diff options
Diffstat (limited to '')
| -rw-r--r-- | flake.nix | 160 | ||||
| -rw-r--r-- | hosts/by-name/server2/host.toml | 2 | ||||
| -rw-r--r-- | hosts/by-name/server3/host.toml | 2 | ||||
| -rw-r--r-- | hosts/default.nix | 44 | ||||
| -rw-r--r-- | hosts/host-names.toml | 2 | ||||
| -rw-r--r-- | modules/default.nix | 8 | ||||
| -rw-r--r-- | modules/vhack/mo/monitoring/components/prometheus.nix | 4 | ||||
| -rw-r--r-- | modules/vhack/ni/nix-sync/module.nix | 1 | ||||
| -rw-r--r-- | pkgs/default.nix | 28 | ||||
| -rw-r--r-- | tests/by-name/at/atuin-sync/test.nix | 244 | ||||
| -rw-r--r-- | tests/by-name/ba/back/test.nix | 4 | ||||
| -rw-r--r-- | tests/by-name/dn/dns/test.nix | 43 | ||||
| -rw-r--r-- | tests/by-name/gi/git-server/test.nix | 4 | ||||
| -rw-r--r-- | tests/by-name/mo/monitoring-federation/test.nix | 4 | ||||
| -rw-r--r-- | tests/by-name/sh/sharkey-cpu/test.nix | 102 | ||||
| -rw-r--r-- | tests/by-name/sn/snm-email-dual-server/test.nix | 10 | ||||
| -rw-r--r-- | tests/by-name/sn/snm-email-single-server/test.nix | 10 | ||||
| -rw-r--r-- | tests/by-name/ta/taskchampion-sync/test.nix | 146 | ||||
| -rw-r--r-- | tests/default.nix | 48 |
19 files changed, 465 insertions, 401 deletions
@@ -1,92 +1,136 @@ { - description = "NixOS server config"; + description = "A NixOS Configuration"; inputs = {}; - outputs = {self, ...} @ attrs: let - sources = import ./unflake.nix; - - inherit (sources) nixpkgs; - inherit (sources) nixpkgs-unstable; - inherit (sources) library; - inherit (sources) treefmt-nix; - inherit (sources) deploy-rs; - # modules - inherit (sources) agenix; - inherit (sources) turtle; - inherit (sources) disko; - inherit (sources) impermanence; - inherit (sources) simple-nixos-mailserver; - inherit (sources) rocie; + outputs = {self, ...}: let + raw_sources = import ./unflake.nix; system = "x86_64-linux"; - nixos-lib = import (nixpkgs + "/nixos/lib") {}; - pkgs = nixpkgs.legacyPackages.${system}; - pkgsUnstable = nixpkgs-unstable.legacyPackages.${system}; + # Filter out the nixpkgs's from the sources, so we always use the `packageSets`. + sources = builtins.removeAttrs raw_sources ["nixpkgs-stable" "nixpkgs-unstable" "library"]; + + packageSets = rec { + stable = raw_sources.nixpkgs-stable.legacyPackages.${system}; + unstable = raw_sources.nixpkgs-unstable.legacyPackages.${system}; - specialArgs = - attrs - // { - inherit - pkgsUnstable - vhackPackages - nixpkgs-unstable - nixos-lib - extraModules - nixLib - turtle - ; + in_tree = import ./pkgs { + unstable_pkgs = unstable; + stable_pkgs = stable; + inherit extra_lib; }; + }; + lib = packageSets.unstable.lib; + extra_lib = raw_sources.library.nixLib; - extraModules = [ - agenix.nixosModules.default - turtle.nixosModules.nixos - disko.nixosModules.default - impermanence.nixosModules.impermanence - simple-nixos-mailserver.nixosModule - rocie.nixosModules.default + extra_modules = [ + sources.agenix.nixosModules.default + sources.turtle.nixosModules.nixos + sources.disko.nixosModules.default + sources.impermanence.nixosModules.impermanence + sources.simple-nixos-mailserver.nixosModule + sources.rocie.nixosModules.default ]; + module_args = { + inherit + sources + # extra package sources + openPRsNixpkgs + packageSets + # extra information + system + ; + }; + special_args = { + inherit + self + # Needs to be a special argument, because it is used for determining the `imports` + # value (via `mkByName`). + extra_lib + ; + }; - deployChecks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib; - tests = pkgs.lib.attrsets.filterAttrs (_: v: !(v ? meta && v.meta.broken)) (import ./tests {inherit pkgs specialArgs nixLib;}); - vhackPackages = import ./pkgs {inherit pkgs nixLib pkgsUnstable;}; + openPRsNixpkgs = {}; - hosts = import ./hosts {inherit self deploy-rs pkgs nixLib nixpkgs specialArgs extraModules;}; + treefmtEval = import ./treefmt.nix { + inherit (sources) treefmt-nix; + pkgs = packageSets.unstable; + }; - inherit (library) nixLib; - treefmtEval = import ./treefmt.nix {inherit treefmt-nix pkgs;}; + hosts = import ./hosts { + inherit + self + extra_lib + module_args + special_args + extra_modules + system + ; + inherit + (raw_sources) + nixpkgs-unstable + nixpkgs-stable + deploy-rs + ; + }; + + deployChecks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) sources.deploy-rs.lib; + tests = lib.attrsets.filterAttrs (_: v: !(v ? meta && v.meta.broken)) (import ./tests + { + inherit sources packageSets extra_modules module_args special_args extra_lib; + }); + # myPkgsFlat = + # builtins.listToAttrs + # # Filter out the `override` and `overrideDerivation` functions + # (builtins.filter + # ({ name, value, }: lib.attrsets.isDerivation value) + # (lib.lists.flatten + # (lib.attrsets.mapAttrsToList + # (name: value: + # if lib.attrsets.isDerivation value then + # [ { inherit name value; } ] + # else + # lib.attrsets.mapAttrsToList + # (name: value: { inherit name value; }) + # value + # ) + # packageSets.in_tree + # ) + # ) + # ); in { checks."${system}" = - nixLib.warnMerge deployChecks."${system}" (nixLib.warnMerge tests { - formatting = treefmtEval.config.build.check self; - } "the flake checks and formatting") + extra_lib.warnMerge + deployChecks."${system}" + (extra_lib.warnMerge + tests + {formatting = treefmtEval.config.build.check self;} + "the flake checks and formatting") "the flake checks and deploy rs checks"; - packages."${system}" = vhackPackages; + legacyPackages."${system}" = packageSets.unstable; + + packages."${system}" = packageSets.in_tree; + formatter."${system}" = treefmtEval.config.build.wrapper; devShells."${system}" = { - default = pkgs.mkShell { + default = packageSets.unstable.mkShell { packages = [ - pkgs.git-bug - - pkgs.deploy-rs + packageSets.unstable.deploy-rs # Used to update the stalwart-mail spamfilter - pkgs.nix-update - - pkgs.cocogitto + packageSets.unstable.nix-update - (agenix.packages."${system}".default.override { - nix = pkgs.lixPackageSets.latest.lix; + (sources.agenix.packages."${system}".default.override { + nix = packageSets.unstable.lixPackageSets.latest.lix; }) ]; }; }; deploy.nodes = hosts.nodes; - inherit (hosts) nixosConfigurations; }; } diff --git a/hosts/by-name/server2/host.toml b/hosts/by-name/server2/host.toml new file mode 100644 index 0000000..ca8423a --- /dev/null +++ b/hosts/by-name/server2/host.toml @@ -0,0 +1,2 @@ +hostname = "server2.vhack.eu" +nixpkgs = "stable" diff --git a/hosts/by-name/server3/host.toml b/hosts/by-name/server3/host.toml new file mode 100644 index 0000000..8a885ae --- /dev/null +++ b/hosts/by-name/server3/host.toml @@ -0,0 +1,2 @@ +hostname = "server3.vhack.eu" +nixpkgs = "stable" diff --git a/hosts/default.nix b/hosts/default.nix index 613db37..4a3d52f 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -1,34 +1,48 @@ { - pkgs, - nixLib, - nixpkgs, - specialArgs, - extraModules, - deploy-rs, self, + extra_lib, + module_args, + extra_modules, + special_args, + nixpkgs-stable, + nixpkgs-unstable, + deploy-rs, + system, }: let - hosts = nixLib.mkByName { + hosts = extra_lib.mkByName { useShards = false; baseDirectory = ./by-name; fileName = "configuration.nix"; }; - mkNixosConfiguration = _: value: + mkNixosConfiguration = name: path: let + host_file = builtins.fromTOML (builtins.readFile (path + "/../host.toml")); + nixpkgs = + if host_file.nixpkgs == "stable" + then nixpkgs-stable + else nixpkgs-unstable; + in nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - inherit specialArgs; + specialArgs = special_args; modules = - extraModules + extra_modules ++ [ + { + _module.args = module_args; + } + path + ../modules - value + # ../modules/common ]; }; - mkDeployHost = name: value: { - hostname = "${name}.vhack.eu"; + mkDeployHost = name: path: let + host_file = builtins.fromTOML (builtins.readFile path + "/host.toml"); + in { + inherit (host_file) hostname; profiles.system = { user = "root"; - path = deploy-rs.lib.x86_64-linux.activate.nixos self.nixosConfigurations."${name}"; + path = deploy-rs.lib."${system}".activate.nixos self.nixosConfigurations."${name}"; }; }; diff --git a/hosts/host-names.toml b/hosts/host-names.toml deleted file mode 100644 index 2cf2833..0000000 --- a/hosts/host-names.toml +++ /dev/null @@ -1,2 +0,0 @@ -server2 = "server2.vhack.eu" -server3 = "server3.vhack.eu" diff --git a/modules/default.nix b/modules/default.nix index bcafc53..ca3c7c8 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,14 +1,12 @@ -{nixLib, ...}: let +{extra_lib, ...}: let vhack = builtins.attrValues ( - nixLib.mkByName { + extra_lib.mkByName { baseDirectory = ./vhack; fileName = "module.nix"; } ); - files = - [] - ++ vhack; + files = vhack; in { imports = files; } diff --git a/modules/vhack/mo/monitoring/components/prometheus.nix b/modules/vhack/mo/monitoring/components/prometheus.nix index ca947d3..2aaf56d 100644 --- a/modules/vhack/mo/monitoring/components/prometheus.nix +++ b/modules/vhack/mo/monitoring/components/prometheus.nix @@ -1,7 +1,7 @@ { lib, config, - nixLib, + extra_lib, ... }: let cfg = config.vhack.monitoring.prometheus; @@ -156,7 +156,7 @@ in { ]; scrapeConfigs = builtins.map (attr: - nixLib.warnMerge { + extra_lib.warnMerge { job_name = attr.name; static_configs = [ { diff --git a/modules/vhack/ni/nix-sync/module.nix b/modules/vhack/ni/nix-sync/module.nix index 9ddd210..02458b7 100644 --- a/modules/vhack/ni/nix-sync/module.nix +++ b/modules/vhack/ni/nix-sync/module.nix @@ -2,7 +2,6 @@ config, lib, modulesPath, - nixLib, ... }: let cfg = config.vhack.nix-sync; diff --git a/pkgs/default.nix b/pkgs/default.nix index 5456ad4..4fdb94f 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,23 +1,21 @@ { - pkgs, - nixLib, - pkgsUnstable, + unstable_pkgs, + stable_pkgs, + extra_lib, }: let - inherit (pkgs) lib; + inherit (unstable_pkgs) lib; - warnMergeMessage = "the ./pkgs/by-name set"; - wMM = warnMergeMessage; - callPackage = - lib.callPackageWith - (nixLib.warnMerge - pkgs - (nixLib.warnMerge vhackPkgs {inherit nixLib pkgsUnstable;} wMM) - wMM); + mergePkgs = pkgs: lib.callPackageWith (extra_lib.warnMerge pkgs in_tree_pkgs "the ./pkgs/by-name set"); + callPackageStable = lib.callPackageWith (mergePkgs stable_pkgs); + callPackageUnstable = lib.callPackageWith (mergePkgs unstable_pkgs); - vhackPkgs = nixLib.mkByName { + in_tree_pkgs = extra_lib.mkByName { baseDirectory = ./by-name; fileName = "package.nix"; - finalizeFunction = name: value: callPackage value {}; + finalizeFunction = name: value: + if value.stable + then callPackageStable value.pkg {} + else callPackageUnstable value.pkg {}; }; in - vhackPkgs + in_tree_pkgs diff --git a/tests/by-name/at/atuin-sync/test.nix b/tests/by-name/at/atuin-sync/test.nix index 3b8f1de..4fe3add 100644 --- a/tests/by-name/at/atuin-sync/test.nix +++ b/tests/by-name/at/atuin-sync/test.nix @@ -1,154 +1,156 @@ { - pkgs, - turtle, + packageSets, + sources, vhack, ... -}: -vhack.runTest { - name = "atuin-sync"; - serverDomains = [ - { - server = "atuin-sync.server"; - } - ]; +}: let + pkgs = packageSets.stable; +in + vhack.runTest { + name = "atuin-sync"; + serverDomains = [ + { + server = "atuin-sync.server"; + } + ]; - nodes = let - atuinSession = "01969ec6b8d07e30a9d2df0911fbfe2a"; - atuin = turtle.packages."${pkgs.stdenv.hostPlatform.system}".default; - in { - server = {config, ...}: { - vhack = { - persist.enable = true; - nginx.enable = true; - atuin-sync = { - enable = true; - fqdn = "atuin-sync.server"; + nodes = let + atuinSession = "01969ec6b8d07e30a9d2df0911fbfe2a"; + atuin = sources.turtle.packages."${pkgs.stdenv.hostPlatform.system}".default; + in { + server = {config, ...}: { + vhack = { + persist.enable = true; + nginx.enable = true; + atuin-sync = { + enable = true; + fqdn = "atuin-sync.server"; + }; }; }; - }; - client1 = {config, ...}: { - environment.sessionVariables.ATUIN_SESSION = atuinSession; + client1 = {config, ...}: { + environment.sessionVariables.ATUIN_SESSION = atuinSession; - environment.systemPackages = [ - atuin - pkgs.sqlite-interactive - ]; - }; - client2 = {config, ...}: { - environment.sessionVariables.ATUIN_SESSION = atuinSession; + environment.systemPackages = [ + atuin + pkgs.sqlite-interactive + ]; + }; + client2 = {config, ...}: { + environment.sessionVariables.ATUIN_SESSION = atuinSession; - environment.systemPackages = [ - atuin - pkgs.sqlite-interactive - ]; + environment.systemPackages = [ + atuin + pkgs.sqlite-interactive + ]; + }; }; - }; - services = [ - {server = "turtle.service";} - ]; + services = [ + {server = "turtle.service";} + ]; - testScript = {nodes, ...}: let - mkSyncConfig = pkgs.writeShellScript "register-atuin-sync-account" '' - mkdir --parents ~/.config/turtle/ + testScript = {nodes, ...}: let + mkSyncConfig = pkgs.writeShellScript "register-atuin-sync-account" '' + mkdir --parents ~/.config/turtle/ - cat << EOF > ~/.config/turtle/config.toml + cat << EOF > ~/.config/turtle/config.toml - [sync] - address = "https://atuin-sync.server" - user_id_path = "${pkgs.writeText "user-id" "019eb88a-6b51-7e52-b12c-7d30bd8e5928"}" - encryption_key_path = "${pkgs.writeText "encryption-key" "3AAgbWsDzL7M00/Mq0LMjsyOCy3MnsypBsyQzKbMywNGzNnMrUBozIINAxdbIiDMhQ=="}" - EOF - ''; + [sync] + address = "https://atuin-sync.server" + user_id_path = "${pkgs.writeText "user-id" "019eb88a-6b51-7e52-b12c-7d30bd8e5928"}" + encryption_key_path = "${pkgs.writeText "encryption-key" "3AAgbWsDzL7M00/Mq0LMjsyOCy3MnsypBsyQzKbMywNGzNnMrUBozIINAxdbIiDMhQ=="}" + EOF + ''; - runCommandAndRecordInTurtle = pkgs.writeShellScript "run-command-and-record-in-atuin" '' - # SPDX-SnippetBegin - # SPDX-SnippetCopyrightText: 2023 mentalisttraceur (https://github.com/mentalisttraceur) - # Source: https://github.com/atuinsh/atuin/issues/1188#issuecomment-1698354107 - run_and_record_in_atuin() - { - local id - local status - local escaped_command="$(printf '%q ' "$@")" - id="$(turtle history start -- "$escaped_command")" - "$@" - status=$? - turtle history end --exit $status "$id" - return $status - } - # SPDX-SnippetEnd + runCommandAndRecordInTurtle = pkgs.writeShellScript "run-command-and-record-in-atuin" '' + # SPDX-SnippetBegin + # SPDX-SnippetCopyrightText: 2023 mentalisttraceur (https://github.com/mentalisttraceur) + # Source: https://github.com/atuinsh/atuin/issues/1188#issuecomment-1698354107 + run_and_record_in_atuin() + { + local id + local status + local escaped_command="$(printf '%q ' "$@")" + id="$(turtle history start -- "$escaped_command")" + "$@" + status=$? + turtle history end --exit $status "$id" + return $status + } + # SPDX-SnippetEnd - run_and_record_in_atuin "$@" - ''; - in - # Python - '' - server.wait_for_open_port(443) + run_and_record_in_atuin "$@" + ''; + in + # Python + '' + server.wait_for_open_port(443) - # Wait for the server to acquire the acme certificate - client1.wait_until_succeeds("curl https://atuin-sync.server") + # Wait for the server to acquire the acme certificate + client1.wait_until_succeeds("curl https://atuin-sync.server") - with subtest("Setup client syncing"): - for client in [client1, client2]: - client.succeed("${mkSyncConfig}") + with subtest("Setup client syncing"): + for client in [client1, client2]: + client.succeed("${mkSyncConfig}") - with subtest("Start turtle daemon"): - for client in [client1, client2]: - client.succeed("systemd-run turtle-daemon start") + with subtest("Start turtle daemon"): + for client in [client1, client2]: + client.succeed("systemd-run turtle-daemon start") - for client in [client1, client2]: - client.wait_until_succeeds("turtle daemon status") + for client in [client1, client2]: + client.wait_until_succeeds("turtle daemon status") - with subtest("Can generate shell history"): - client1.succeed("${runCommandAndRecordInTurtle} echo hi - client 1") - client2.succeed("${runCommandAndRecordInTurtle} echo hi - client 2") + with subtest("Can generate shell history"): + client1.succeed("${runCommandAndRecordInTurtle} echo hi - client 1") + client2.succeed("${runCommandAndRecordInTurtle} echo hi - client 2") - with subtest("Can sync"): - for client in [client1, client2]: - client.succeed("turtle sync perform") - client1.succeed("turtle sync perform") + with subtest("Can sync"): + for client in [client1, client2]: + client.succeed("turtle sync perform") + client1.succeed("turtle sync perform") - with subtest("Have correct tasks"): - hist1 = client1.succeed("turtle history list --cmd-only").strip().split('\n') - hist2 = client2.succeed("turtle history list --cmd-only").strip().split('\n') + with subtest("Have correct tasks"): + hist1 = client1.succeed("turtle history list --cmd-only").strip().split('\n') + hist2 = client2.succeed("turtle history list --cmd-only").strip().split('\n') - hist1.sort() - hist2.sort() + hist1.sort() + hist2.sort() - canonicalHistory = [ - "echo hi - client 1", - "echo hi - client 2" - ] + canonicalHistory = [ + "echo hi - client 1", + "echo hi - client 2" + ] - assert hist1 == hist2, f"The clients don't have the same amount of history items, client1: '{hist1}', client2: '{hist2}'" - assert hist1 == canonicalHistory, f"The history is not correct: '{hist1}' vs. '{canonicalHistory}'" + assert hist1 == hist2, f"The clients don't have the same amount of history items, client1: '{hist1}', client2: '{hist2}'" + assert hist1 == canonicalHistory, f"The history is not correct: '{hist1}' vs. '{canonicalHistory}'" - with subtest("Can sync again"): - client1.succeed("${runCommandAndRecordInTurtle} echo second try - client 1") - client2.succeed("${runCommandAndRecordInTurtle} echo second try - client 2") + with subtest("Can sync again"): + client1.succeed("${runCommandAndRecordInTurtle} echo second try - client 1") + client2.succeed("${runCommandAndRecordInTurtle} echo second try - client 2") - for client in [client1, client2]: - client.succeed("turtle sync perform") - client1.succeed("turtle sync perform") + for client in [client1, client2]: + client.succeed("turtle sync perform") + client1.succeed("turtle sync perform") - hist1 = client1.succeed("turtle history list --cmd-only").strip().split('\n') - hist2 = client2.succeed("turtle history list --cmd-only").strip().split('\n') + hist1 = client1.succeed("turtle history list --cmd-only").strip().split('\n') + hist2 = client2.succeed("turtle history list --cmd-only").strip().split('\n') - hist1.sort() - hist2.sort() + hist1.sort() + hist2.sort() - canonicalHistory = [ - # The old history - "echo hi - client 1", - "echo hi - client 2", + canonicalHistory = [ + # The old history + "echo hi - client 1", + "echo hi - client 2", - # Our newly added history entries - "echo second try - client 1", - "echo second try - client 2" - ] + # Our newly added history entries + "echo second try - client 1", + "echo second try - client 2" + ] - assert hist1 == hist2, f"The clients don't have the same amount of history items, client1: '{hist1}', client2: '{hist2}'" - assert hist1 == canonicalHistory, f"The history is not correct, got: '{hist1}', expected: '{canonicalHistory}'" - ''; -} + assert hist1 == hist2, f"The clients don't have the same amount of history items, client1: '{hist1}', client2: '{hist2}'" + assert hist1 == canonicalHistory, f"The history is not correct, got: '{hist1}', expected: '{canonicalHistory}'" + ''; + } diff --git a/tests/by-name/ba/back/test.nix b/tests/by-name/ba/back/test.nix index 758980e..ed297ec 100644 --- a/tests/by-name/ba/back/test.nix +++ b/tests/by-name/ba/back/test.nix @@ -1,8 +1,10 @@ { - pkgs, + packageSets, vhack, ... }: let + pkgs = packageSets.stable; + domain = "server"; sshKeys = diff --git a/tests/by-name/dn/dns/test.nix b/tests/by-name/dn/dns/test.nix index 01d8833..8bf0799 100644 --- a/tests/by-name/dn/dns/test.nix +++ b/tests/by-name/dn/dns/test.nix @@ -1,14 +1,11 @@ # Inspired by this file: /nixpkgs/nixos/tests/nsd.nix { - nixos-lib, - pkgsUnstable, - nixpkgs-unstable, - vhackPackages, - pkgs, - extraModules, - nixLib, + packageSets, + vhack, ... }: let + pkgs = packageSets.stable; + common = {...}: { networking.firewall.enable = false; networking.dhcpcd.enable = false; @@ -27,30 +24,18 @@ ]; }; in - nixos-lib.runTest { - hostPkgs = pkgs; # the Nixpkgs package set used outside the VMs - + vhack.runTest { name = "dns"; - node = { - specialArgs = {inherit pkgsUnstable vhackPackages nixpkgs-unstable nixLib;}; - - # Use the nixpkgs as constructed by the `nixpkgs.*` options - pkgs = null; - }; - nodes = { server = { config, lib, ... }: { - imports = - extraModules - ++ [ - ../../../../modules - common - ]; + imports = [ + common + ]; vhack = { dns = { @@ -96,17 +81,17 @@ in clientV6 = mkClient "ipv6"; }; + services = [ + {clientV4 = "network.target";} + {clientV6 = "network.target";} + {server = "nsd.service";} + ]; + testScript = {nodes, ...}: /* python */ '' - start_all() - - clientV4.wait_for_unit("network.target") - clientV6.wait_for_unit("network.target") - server.wait_for_unit("nsd.service") - def assert_host(ipVersion, dnsRecordType, dnsQuery, expected): self = clientV4 if ipVersion == 4 else clientV6 out = self.succeed(f"host -{ipVersion} -t {dnsRecordType} {dnsQuery}").rstrip() diff --git a/tests/by-name/gi/git-server/test.nix b/tests/by-name/gi/git-server/test.nix index 09e559c..a0aeb35 100644 --- a/tests/by-name/gi/git-server/test.nix +++ b/tests/by-name/gi/git-server/test.nix @@ -1,8 +1,10 @@ { - pkgs, + packageSets, vhack, ... }: let + pkgs = packageSets.stable; + sshKeys = import ./ssh_keys.nix {inherit pkgs;}; diff --git a/tests/by-name/mo/monitoring-federation/test.nix b/tests/by-name/mo/monitoring-federation/test.nix index 278626f..1cb2de1 100644 --- a/tests/by-name/mo/monitoring-federation/test.nix +++ b/tests/by-name/mo/monitoring-federation/test.nix @@ -1,8 +1,10 @@ { - pkgs, + packageSets, vhack, ... }: let + pkgs = packageSets.stable; + prometheusMain = "prometheus.server2.server.org"; remoteWriteTo = { url = "https://${prometheusMain}"; diff --git a/tests/by-name/sh/sharkey-cpu/test.nix b/tests/by-name/sh/sharkey-cpu/test.nix index f38fd46..89bc7cb 100644 --- a/tests/by-name/sh/sharkey-cpu/test.nix +++ b/tests/by-name/sh/sharkey-cpu/test.nix @@ -1,64 +1,66 @@ { - pkgs, + packageSets, vhack, ... -}: -vhack.runTest { - name = "sharkey-cpu"; - ignore = true; +}: let + pkgs = packageSets.stable; +in + vhack.runTest { + name = "sharkey-cpu"; + ignore = true; - nodes = { - server = {config, ...}: { - vhack = { - persist.enable = true; - nginx.enable = true; - sharkey = { - enable = true; - fqdn = "sharkey.server"; + nodes = { + server = {config, ...}: { + vhack = { + persist.enable = true; + nginx.enable = true; + sharkey = { + enable = true; + fqdn = "sharkey.server"; + }; }; - }; - systemd.services = { - # Avoid an error from this service. - "acme-sharkey.server".enable = false; + systemd.services = { + # Avoid an error from this service. + "acme-sharkey.server".enable = false; - # Test that sharkey's hardening still allows access to the CPUs. - sharkey.serviceConfig.ExecStart = let - nodejs = pkgs.lib.getExe pkgs.nodejs; - script = pkgs.writeTextFile { - name = "script.js"; - text = - # js - '' - import * as os from 'node:os'; + # Test that sharkey's hardening still allows access to the CPUs. + sharkey.serviceConfig.ExecStart = let + nodejs = pkgs.lib.getExe pkgs.nodejs; + script = pkgs.writeTextFile { + name = "script.js"; + text = + # js + '' + import * as os from 'node:os'; - var cpus = os.cpus() + var cpus = os.cpus() - if (cpus.length != 0) { - console.log(cpus[0].model) - } else { - // Fail? - } + if (cpus.length != 0) { + console.log(cpus[0].model) + } else { + // Fail? + } - while (true) { - } - ''; - }; - in - pkgs.lib.mkForce "${nodejs} ${script}"; + while (true) { + } + ''; + }; + in + pkgs.lib.mkForce "${nodejs} ${script}"; + }; }; }; - }; - services = [ - {server = "sharkey.service";} - ]; + services = [ + {server = "sharkey.service";} + ]; - testScript = {...}: - # Python - '' - from time import sleep + testScript = {...}: + # Python + '' + from time import sleep - # Give the service time to run. - sleep(3) - ''; -} + # Give the service time to run. + sleep(3) + ''; + } diff --git a/tests/by-name/sn/snm-email-dual-server/test.nix b/tests/by-name/sn/snm-email-dual-server/test.nix index 6f7bebb..41d8e84 100644 --- a/tests/by-name/sn/snm-email-dual-server/test.nix +++ b/tests/by-name/sn/snm-email-dual-server/test.nix @@ -1,14 +1,18 @@ { lib, vhack, - pkgs, - vhackPackages, + packageSets, ... }: let + pkgs = packageSets.stable; + server1Domain = "mail.server1"; server2Domain = "mail.server2"; - common = import ../../../common/email/functions.nix {inherit pkgs vhackPackages;}; + common = import ../../../common/email/functions.nix { + inherit pkgs; + vhackPackages = packageSets.in_tree; + }; # That's a horrible hack. We should instead wait, until the delivery of the email is # confirmed. diff --git a/tests/by-name/sn/snm-email-single-server/test.nix b/tests/by-name/sn/snm-email-single-server/test.nix index 7b5ec03..260fd92 100644 --- a/tests/by-name/sn/snm-email-single-server/test.nix +++ b/tests/by-name/sn/snm-email-single-server/test.nix @@ -1,12 +1,16 @@ { vhack, - pkgs, - vhackPackages, + packageSets, ... }: let + pkgs = packageSets.stable; + domain = "mail.server.test"; - common = import ../../../common/email/functions.nix {inherit pkgs vhackPackages;}; + common = import ../../../common/email/functions.nix { + inherit pkgs; + vhackPackages = packageSets.in_tree; + }; in vhack.runTest { name = "email"; diff --git a/tests/by-name/ta/taskchampion-sync/test.nix b/tests/by-name/ta/taskchampion-sync/test.nix index 54eef45..a8b42ee 100644 --- a/tests/by-name/ta/taskchampion-sync/test.nix +++ b/tests/by-name/ta/taskchampion-sync/test.nix @@ -1,92 +1,94 @@ { - pkgs, + packageSets, vhack, ... -}: -vhack.runTest { - name = "taskchampion-sync"; +}: let + pkgs = packageSets.stable; +in + vhack.runTest { + name = "taskchampion-sync"; - serverDomains = [ - {server = "taskchampion.server";} - ]; + serverDomains = [ + {server = "taskchampion.server";} + ]; - nodes = let - taskwarriorPackage = pkgs.taskwarrior3.overrideAttrs (final: prev: { - cmakeFlags = (prev.cmakeFlags or []) ++ ["-DENABLE_TLS_NATIVE_ROOTS=true"]; - }); - in { - server = {config, ...}: { - vhack = { - persist.enable = true; - nginx.enable = true; - taskchampion-sync = { - enable = true; - fqdn = "taskchampion.server"; + nodes = let + taskwarriorPackage = pkgs.taskwarrior3.overrideAttrs (final: prev: { + cmakeFlags = (prev.cmakeFlags or []) ++ ["-DENABLE_TLS_NATIVE_ROOTS=true"]; + }); + in { + server = {config, ...}: { + vhack = { + persist.enable = true; + nginx.enable = true; + taskchampion-sync = { + enable = true; + fqdn = "taskchampion.server"; + }; }; }; - }; - task_client1 = {config, ...}: { - environment.systemPackages = [ - taskwarriorPackage - ]; - }; - task_client2 = {config, ...}: { - environment.systemPackages = [ - taskwarriorPackage - ]; + task_client1 = {config, ...}: { + environment.systemPackages = [ + taskwarriorPackage + ]; + }; + task_client2 = {config, ...}: { + environment.systemPackages = [ + taskwarriorPackage + ]; + }; }; - }; - services = [ - {server = "taskchampion-sync-server.service";} - ]; + services = [ + {server = "taskchampion-sync-server.service";} + ]; - ports = [ - {server = 443;} - ]; + ports = [ + {server = 443;} + ]; - testScript = {nodes, ...}: let - # Generated with uuidgen - uuid = "bf01376e-04a4-435a-9263-608567531af3"; - password = "nixos-test"; + testScript = {nodes, ...}: let + # Generated with uuidgen + uuid = "bf01376e-04a4-435a-9263-608567531af3"; + password = "nixos-test"; - mkSyncConfig = path: - pkgs.writeShellScript "setup-config-file" '' - set -xe + mkSyncConfig = path: + pkgs.writeShellScript "setup-config-file" '' + set -xe - mkdir --parents "$(dirname "${path}")" - echo 'sync.server.url=https://taskchampion.server' >> "${path}" - echo 'sync.server.client_id=${uuid}' >> "${path}" - echo 'sync.encryption_secret=${password}' >> "${path}" - ''; - in - # Python - '' - with subtest("Setup task syncing"): - for task in [task_client1, task_client2]: - # See man task-sync(5) - task.succeed("mkdir ~/.task") - task.succeed("${mkSyncConfig "$HOME/.taskrc"}") + mkdir --parents "$(dirname "${path}")" + echo 'sync.server.url=https://taskchampion.server' >> "${path}" + echo 'sync.server.client_id=${uuid}' >> "${path}" + echo 'sync.encryption_secret=${password}' >> "${path}" + ''; + in + # Python + '' + with subtest("Setup task syncing"): + for task in [task_client1, task_client2]: + # See man task-sync(5) + task.succeed("mkdir ~/.task") + task.succeed("${mkSyncConfig "$HOME/.taskrc"}") - with subtest("Can create tasks"): - task_client1.succeed("task add 'First task -- task_client1'") - task_client2.succeed("task add 'First task -- task_client2'") + with subtest("Can create tasks"): + task_client1.succeed("task add 'First task -- task_client1'") + task_client2.succeed("task add 'First task -- task_client2'") - # Wait for the server to acquire the acme certificate - task_client1.wait_until_succeeds("curl https://taskchampion.server") + # Wait for the server to acquire the acme certificate + task_client1.wait_until_succeeds("curl https://taskchampion.server") - with subtest("Can sync tasks"): - for task in [task_client1, task_client2]: - task.succeed("task sync") - task_client1.succeed("task sync") + with subtest("Can sync tasks"): + for task in [task_client1, task_client2]: + task.succeed("task sync") + task_client1.succeed("task sync") - with subtest("Have correct tasks"): - count1 = task_client1.succeed("task count") - count2 = task_client2.succeed("task count") + with subtest("Have correct tasks"): + count1 = task_client1.succeed("task count") + count2 = task_client2.succeed("task count") - assert int(count1) == 2, f"We don't have exactly 2 tasks, but {count1}" - assert count1 == count2, f"The clients don't have the same amount of tasks, client1: {count1}, client2: {count2}" - ''; -} + assert int(count1) == 2, f"We don't have exactly 2 tasks, but {count1}" + assert count1 == count2, f"The clients don't have the same amount of tasks, client1: {count1}, client2: {count2}" + ''; + } diff --git a/tests/default.nix b/tests/default.nix index 88ea7d9..870ecfb 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -1,7 +1,10 @@ { - specialArgs, - nixLib, - pkgs, + packageSets, + extra_modules, + module_args, + special_args, + extra_lib, + sources, }: let splitAttr = attr: let pairs = builtins.attrNames attr; @@ -50,31 +53,28 @@ ports ? [], # If `true`, will ignore this test. ignore ? null, + # Should this test use the stable nixpkgs? + stable ? true, testScript ? {_, ...}: "", }: let # Apparently the default's (e.g. `serivces ? []`), are not applied for the `@args` # syntax. args = {inherit dns ignore name nodes ports serverDomains services testScript;}; + pkgs = + if stable + then packageSets.stable + else packageSets.unstable; in - specialArgs.nixos-lib.runTest { - hostPkgs = pkgs; + pkgs.testers.runNixOSTest { inherit (args) name; meta.broken = pkgs.lib.mkIf (args.ignore != null) true; node = { - specialArgs = { - inherit - (specialArgs) - pkgsUnstable - vhackPackages - nixpkgs-unstable - ; - inherit nixLib; - }; + specialArgs = special_args; # Use the nixpkgs as constructed by the `nixpkgs.*` options - pkgs = null; + pkgs = packageSets.unstable.lib.mkForce null; }; nodes = pkgs.lib.mkMerge [ @@ -87,7 +87,7 @@ }; name_server = {nodes, ...}: { imports = - specialArgs.extraModules + extra_modules ++ [ ./common/acme/client.nix ./common/dns/server.nix @@ -130,7 +130,7 @@ args.nodes (builtins.mapAttrs (_: _: { imports = - specialArgs.extraModules + extra_modules ++ [ ./common/acme/client.nix ./common/dns/client.nix @@ -325,14 +325,18 @@ ); }; - tests = nixLib.mkByName { + tests = extra_lib.mkByName { baseDirectory = ./by-name; fileName = "test.nix"; finalizeFunction = name: value: - import value (nixLib.warnMerge specialArgs { - inherit pkgs vhack; - inherit (pkgs) lib; - } "the test args set"); + # import value (extra_lib.warnMerge special_args { + # inherit pkgs vhack; + # inherit (pkgs) lib; + # } "the test args set"); + import value { + inherit packageSets vhack sources; + inherit (packageSets.unstable) lib; + }; }; in tests |
