From 79a234567c01399c5f1ae1d0b60ac84d12075b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Fri, 18 Mar 2022 01:20:21 +0100 Subject: [PATCH 1/8] nixos/testing: restrict arguments to makeTest Disallow passing arbitrary arguments to makeTest since they are not used; this can help catch mistakes. --- nixos/lib/testing-python.nix | 27 +++++++++++++++------------ pkgs/top-level/all-packages.nix | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/nixos/lib/testing-python.nix b/nixos/lib/testing-python.nix index 0d3c3a89e783..8c4cdb31791a 100644 --- a/nixos/lib/testing-python.nix +++ b/nixos/lib/testing-python.nix @@ -146,26 +146,28 @@ rec { # Make a full-blown test makeTest = - { testScript + { machine ? null + , nodes ? {} + , testScript , enableOCR ? false , name ? "unnamed" # Skip linting (mainly intended for faster dev cycles) , skipLint ? false , passthru ? {} + , meta ? {} , # For meta.position pos ? # position used in error messages and for meta.position - (if t.meta.description or null != null - then builtins.unsafeGetAttrPos "description" t.meta + (if meta.description or null != null + then builtins.unsafeGetAttrPos "description" meta else builtins.unsafeGetAttrPos "testScript" t) - , ... } @ t: let - nodes = qemu_pkg: + mkNodes = qemu_pkg: let testScript' = # Call the test script with the computed nodes. if lib.isFunction testScript - then testScript { nodes = nodes qemu_pkg; } + then testScript { nodes = mkNodes qemu_pkg; } else testScript; build-vms = import ./build-vms.nix { @@ -205,33 +207,34 @@ rec { }; in build-vms.buildVirtualNetwork ( - t.nodes or (if t ? machine then { machine = t.machine; } else { }) + nodes // lib.optionalAttrs (machine != null) { inherit machine; } ); driver = setupDriverForTest { inherit testScript enableOCR skipLint passthru; testName = name; qemu_pkg = pkgs.qemu_test; - nodes = nodes pkgs.qemu_test; + nodes = mkNodes pkgs.qemu_test; }; driverInteractive = setupDriverForTest { inherit testScript enableOCR skipLint passthru; testName = name; qemu_pkg = pkgs.qemu; - nodes = nodes pkgs.qemu; + nodes = mkNodes pkgs.qemu; interactive = true; }; test = let - passMeta = drv: drv // lib.optionalAttrs (t ? meta) { - meta = (drv.meta or { }) // t.meta; + passMeta = drv: drv // lib.optionalAttrs (meta != {}) { + meta = (drv.meta or { }) // meta; }; in passMeta (runTests { inherit driver pos driverInteractive; }); in test // { - inherit test driver driverInteractive nodes; + inherit test driver driverInteractive; + inherit (driver) nodes; }; abortForFunction = functionName: abort ''The ${functionName} function was diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d5d828bf7d1f..e2a40bdee621 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -33613,7 +33613,7 @@ with pkgs; then import test else test; calledTest = if lib.isFunction loadedTest - then callPackage loadedTest {} + then loadedTest { inherit pkgs lib; } else loadedTest; in nixosTesting.makeTest calledTest; From ca8c877f8cd1f9b84e8aa57741aa5cd60a3a2ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Fri, 18 Mar 2022 01:27:04 +0100 Subject: [PATCH 2/8] nixos/tests: fix some evaluation errors Fixes errors caught by "nixos/testing: restrict arguments to makeTest" as well as some unrelated errors and warnings. --- nixos/tests/boot.nix | 1 - nixos/tests/caddy.nix | 6 ++--- nixos/tests/ceph-multi-node.nix | 2 +- nixos/tests/chromium.nix | 38 ++++++++++++++++--------------- nixos/tests/cri-o.nix | 2 +- nixos/tests/gitolite-fcgiwrap.nix | 2 +- nixos/tests/jitsi-meet.nix | 4 ++-- nixos/tests/misc.nix | 6 ++--- nixos/tests/rstudio-server.nix | 6 ----- nixos/tests/step-ca.nix | 4 ++-- nixos/tests/tor.nix | 25 ++++++++------------ nixos/tests/without-nix.nix | 6 ----- 12 files changed, 43 insertions(+), 59 deletions(-) diff --git a/nixos/tests/boot.nix b/nixos/tests/boot.nix index cf5565667131..ec2a9f6527c9 100644 --- a/nixos/tests/boot.nix +++ b/nixos/tests/boot.nix @@ -38,7 +38,6 @@ let } // extraConfig); in makeTest { - inherit iso; name = "boot-" + name; nodes = { }; testScript = diff --git a/nixos/tests/caddy.nix b/nixos/tests/caddy.nix index 0902904b2086..16436ab52800 100644 --- a/nixos/tests/caddy.nix +++ b/nixos/tests/caddy.nix @@ -7,7 +7,7 @@ import ./make-test-python.nix ({ pkgs, ... }: { nodes = { webserver = { pkgs, lib, ... }: { services.caddy.enable = true; - services.caddy.config = '' + services.caddy.extraConfig = '' http://localhost { encode gzip @@ -22,7 +22,7 @@ import ./make-test-python.nix ({ pkgs, ... }: { ''; specialisation.etag.configuration = { - services.caddy.config = lib.mkForce '' + services.caddy.extraConfig = lib.mkForce '' http://localhost { encode gzip @@ -38,7 +38,7 @@ import ./make-test-python.nix ({ pkgs, ... }: { }; specialisation.config-reload.configuration = { - services.caddy.config = '' + services.caddy.extraConfig = '' http://localhost:8080 { } ''; diff --git a/nixos/tests/ceph-multi-node.nix b/nixos/tests/ceph-multi-node.nix index 29e7c279d69a..556546beee76 100644 --- a/nixos/tests/ceph-multi-node.nix +++ b/nixos/tests/ceph-multi-node.nix @@ -48,7 +48,7 @@ let sudo ceph xfsprogs - netcat-openbsd + libressl.nc ]; boot.kernelModules = [ "xfs" ]; diff --git a/nixos/tests/chromium.nix b/nixos/tests/chromium.nix index 8965646bc5dc..3815dca76220 100644 --- a/nixos/tests/chromium.nix +++ b/nixos/tests/chromium.nix @@ -15,26 +15,9 @@ with import ../lib/testing-python.nix { inherit system pkgs; }; with pkgs.lib; -mapAttrs (channel: chromiumPkg: makeTest rec { - name = "chromium-${channel}"; - meta = { - maintainers = with maintainers; [ aszlig primeos ]; - # https://github.com/NixOS/hydra/issues/591#issuecomment-435125621 - inherit (chromiumPkg.meta) timeout; - }; - - enableOCR = true; - +let user = "alice"; - machine.imports = [ ./common/user-account.nix ./common/x11.nix ]; - machine.virtualisation.memorySize = 2047; - machine.test-support.displayManager.auto.user = user; - machine.environment = { - systemPackages = [ chromiumPkg ]; - variables."XAUTHORITY" = "/home/alice/.Xauthority"; - }; - startupHTML = pkgs.writeText "chromium-startup.html" '' @@ -50,6 +33,25 @@ mapAttrs (channel: chromiumPkg: makeTest rec { ''; +in + +mapAttrs (channel: chromiumPkg: makeTest { + name = "chromium-${channel}"; + meta = { + maintainers = with maintainers; [ aszlig primeos ]; + # https://github.com/NixOS/hydra/issues/591#issuecomment-435125621 + inherit (chromiumPkg.meta) timeout; + }; + + enableOCR = true; + + machine.imports = [ ./common/user-account.nix ./common/x11.nix ]; + machine.virtualisation.memorySize = 2047; + machine.test-support.displayManager.auto.user = user; + machine.environment = { + systemPackages = [ chromiumPkg ]; + variables."XAUTHORITY" = "/home/alice/.Xauthority"; + }; testScript = let xdo = name: text: let diff --git a/nixos/tests/cri-o.nix b/nixos/tests/cri-o.nix index 91d46657f241..d3a8713d6a9b 100644 --- a/nixos/tests/cri-o.nix +++ b/nixos/tests/cri-o.nix @@ -1,7 +1,7 @@ # This test runs CRI-O and verifies via critest import ./make-test-python.nix ({ pkgs, ... }: { name = "cri-o"; - maintainers = with pkgs.lib.maintainers; teams.podman.members; + meta.maintainers = with pkgs.lib.maintainers; teams.podman.members; nodes = { crio = { diff --git a/nixos/tests/gitolite-fcgiwrap.nix b/nixos/tests/gitolite-fcgiwrap.nix index 38f8d5c883fd..abf1db37003a 100644 --- a/nixos/tests/gitolite-fcgiwrap.nix +++ b/nixos/tests/gitolite-fcgiwrap.nix @@ -20,7 +20,7 @@ import ./make-test-python.nix ( nodes = { server = - { ... }: + { config, ... }: { networking.firewall.allowedTCPPorts = [ 80 ]; diff --git a/nixos/tests/jitsi-meet.nix b/nixos/tests/jitsi-meet.nix index d95f7c2ea9ea..41d53bc73800 100644 --- a/nixos/tests/jitsi-meet.nix +++ b/nixos/tests/jitsi-meet.nix @@ -21,9 +21,9 @@ import ./make-test-python.nix ({ pkgs, ... }: { forceSSL = true; }; - security.acme.email = "me@example.org"; security.acme.acceptTerms = true; - security.acme.server = "https://example.com"; # self-signed only + security.acme.defaults.email = "me@example.org"; + security.acme.defaults.server = "https://example.com"; # self-signed only }; }; diff --git a/nixos/tests/misc.nix b/nixos/tests/misc.nix index 0587912c9a22..02513c4726c1 100644 --- a/nixos/tests/misc.nix +++ b/nixos/tests/misc.nix @@ -1,13 +1,13 @@ # Miscellaneous small tests that don't warrant their own VM run. -import ./make-test-python.nix ({ pkgs, ...} : rec { +import ./make-test-python.nix ({ pkgs, ...} : let + foo = pkgs.writeText "foo" "Hello World"; +in { name = "misc"; meta = with pkgs.lib.maintainers; { maintainers = [ eelco ]; }; - foo = pkgs.writeText "foo" "Hello World"; - machine = { lib, ... }: with lib; diff --git a/nixos/tests/rstudio-server.nix b/nixos/tests/rstudio-server.nix index c7ac7670fbd4..dd5fe3e5b440 100644 --- a/nixos/tests/rstudio-server.nix +++ b/nixos/tests/rstudio-server.nix @@ -14,12 +14,6 @@ import ./make-test-python.nix ({ pkgs, ... }: }; }; - users.testuser = { - uid = 1000; - group = "testgroup"; - }; - groups.testgroup.gid = 1000; - testScript = '' machine.wait_for_unit("rstudio-server.service") machine.succeed("curl -f -vvv -s http://127.0.0.1:8787") diff --git a/nixos/tests/step-ca.nix b/nixos/tests/step-ca.nix index b22bcb060f2b..f21bd5366266 100644 --- a/nixos/tests/step-ca.nix +++ b/nixos/tests/step-ca.nix @@ -42,8 +42,8 @@ import ./make-test-python.nix ({ pkgs, ... }: caclient = { config, pkgs, ... }: { - security.acme.server = "https://caserver:8443/acme/acme/directory"; - security.acme.email = "root@example.org"; + security.acme.defaults.server = "https://caserver:8443/acme/acme/directory"; + security.acme.defaults.email = "root@example.org"; security.acme.acceptTerms = true; security.pki.certificateFiles = [ "${test-certificates}/root_ca.crt" ]; diff --git a/nixos/tests/tor.nix b/nixos/tests/tor.nix index c061f59226cf..71ec9df4641f 100644 --- a/nixos/tests/tor.nix +++ b/nixos/tests/tor.nix @@ -1,24 +1,19 @@ import ./make-test-python.nix ({ lib, ... }: with lib; -rec { +{ name = "tor"; meta.maintainers = with maintainers; [ joachifm ]; - common = - { ... }: - { boot.kernelParams = [ "audit=0" "apparmor=0" "quiet" ]; - networking.firewall.enable = false; - networking.useDHCP = false; - }; + nodes.client = { pkgs, ... }: { + boot.kernelParams = [ "audit=0" "apparmor=0" "quiet" ]; + networking.firewall.enable = false; + networking.useDHCP = false; - nodes.client = - { pkgs, ... }: - { imports = [ common ]; - environment.systemPackages = with pkgs; [ netcat ]; - services.tor.enable = true; - services.tor.client.enable = true; - services.tor.settings.ControlPort = 9051; - }; + environment.systemPackages = with pkgs; [ netcat ]; + services.tor.enable = true; + services.tor.client.enable = true; + services.tor.settings.ControlPort = 9051; + }; testScript = '' client.wait_for_unit("tor.service") diff --git a/nixos/tests/without-nix.nix b/nixos/tests/without-nix.nix index 2fc00b04144f..93f1d0186047 100644 --- a/nixos/tests/without-nix.nix +++ b/nixos/tests/without-nix.nix @@ -4,12 +4,6 @@ import ./make-test-python.nix ({ lib, ... }: { maintainers = [ ericson2314 ]; }; - nixpkgs.overlays = [ - (self: super: { - nix = throw "don't want to use this"; - }) - ]; - nodes.machine = { ... }: { nix.enable = false; }; From 8f57dc38d93d9a6b8a792e7cd963af676a1de252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Sat, 19 Mar 2022 11:51:39 +0100 Subject: [PATCH 3/8] fixup! nixos/testing: restrict arguments to makeTest --- nixos/lib/testing-python.nix | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/nixos/lib/testing-python.nix b/nixos/lib/testing-python.nix index 8c4cdb31791a..facc7a253a75 100644 --- a/nixos/lib/testing-python.nix +++ b/nixos/lib/testing-python.nix @@ -224,12 +224,7 @@ rec { interactive = true; }; - test = - let - passMeta = drv: drv // lib.optionalAttrs (meta != {}) { - meta = (drv.meta or { }) // meta; - }; - in passMeta (runTests { inherit driver pos driverInteractive; }); + test = lib.addMetaAttrs meta (runTests { inherit driver pos driverInteractive; }); in test // { From eb8b70c020e6693b29634660fa173d7f14f882eb Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 21 Mar 2022 22:28:37 +0100 Subject: [PATCH 4/8] nixos: Make config.nix.enable pass test --- nixos/modules/installer/tools/tools.nix | 2 +- nixos/modules/services/misc/nix-gc.nix | 8 +++++++- nixos/modules/services/misc/nix-optimise.nix | 8 +++++++- nixos/modules/virtualisation/qemu-vm.nix | 2 +- nixos/tests/without-nix.nix | 15 +++++++++++++++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/nixos/modules/installer/tools/tools.nix b/nixos/modules/installer/tools/tools.nix index 71aaf7f253d9..2e088b977710 100644 --- a/nixos/modules/installer/tools/tools.nix +++ b/nixos/modules/installer/tools/tools.nix @@ -117,7 +117,7 @@ in ''; }; - config = lib.mkIf (!config.system.disableInstallerTools) { + config = lib.mkIf (config.nix.enable && !config.system.disableInstallerTools) { system.nixos-generate-config.configuration = mkDefault '' # Edit this configuration file to define what should be installed on diff --git a/nixos/modules/services/misc/nix-gc.nix b/nixos/modules/services/misc/nix-gc.nix index a7a6a3b59644..b4b4b55a6c82 100644 --- a/nixos/modules/services/misc/nix-gc.nix +++ b/nixos/modules/services/misc/nix-gc.nix @@ -81,8 +81,14 @@ in ###### implementation config = { + assertions = [ + { + assertion = cfg.automatic -> config.nix.enable; + message = ''nix.gc.automatic requires nix.enable''; + } + ]; - systemd.services.nix-gc = { + systemd.services.nix-gc = lib.mkIf config.nix.enable { description = "Nix Garbage Collector"; script = "exec ${config.nix.package.out}/bin/nix-collect-garbage ${cfg.options}"; startAt = optional cfg.automatic cfg.dates; diff --git a/nixos/modules/services/misc/nix-optimise.nix b/nixos/modules/services/misc/nix-optimise.nix index e02026d5f76c..acf8177b146a 100644 --- a/nixos/modules/services/misc/nix-optimise.nix +++ b/nixos/modules/services/misc/nix-optimise.nix @@ -37,8 +37,14 @@ in ###### implementation config = { + assertions = [ + { + assertion = cfg.automatic -> config.nix.enable; + message = ''nix.optimise.automatic requires nix.enable''; + } + ]; - systemd.services.nix-optimise = + systemd.services.nix-optimise = lib.mkIf config.nix.enable { description = "Nix Store Optimiser"; # No point this if the nix daemon (and thus the nix store) is outside unitConfig.ConditionPathIsReadWrite = "/nix/var/nix/daemon-socket"; diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix index 514389358947..dacbb64a2dac 100644 --- a/nixos/modules/virtualisation/qemu-vm.nix +++ b/nixos/modules/virtualisation/qemu-vm.nix @@ -796,7 +796,7 @@ in # allow `system.build.toplevel' to be included. (If we had a direct # reference to ${regInfo} here, then we would get a cyclic # dependency.) - boot.postBootCommands = + boot.postBootCommands = lib.mkIf config.nix.enable '' if [[ "$(cat /proc/cmdline)" =~ regInfo=([^ ]*) ]]; then ${config.nix.package.out}/bin/nix-store --load-db < ''${BASH_REMATCH[1]} diff --git a/nixos/tests/without-nix.nix b/nixos/tests/without-nix.nix index 93f1d0186047..b21e9f2844f5 100644 --- a/nixos/tests/without-nix.nix +++ b/nixos/tests/without-nix.nix @@ -6,6 +6,21 @@ import ./make-test-python.nix ({ lib, ... }: { nodes.machine = { ... }: { nix.enable = false; + nixpkgs.overlays = [ + (self: super: { + nix = throw "don't want to use pkgs.nix"; + nixVersions = lib.mapAttrs (k: throw "don't want to use pkgs.nixVersions.${k}") super.nixVersions; + # aliases, some deprecated + nix_2_3 = throw "don't want to use pkgs.nix_2_3"; + nix_2_4 = throw "don't want to use pkgs.nix_2_4"; + nix_2_5 = throw "don't want to use pkgs.nix_2_5"; + nix_2_6 = throw "don't want to use pkgs.nix_2_6"; + nixFlakes = throw "don't want to use pkgs.nixFlakes"; + nixStable = throw "don't want to use pkgs.nixStable"; + nixUnstable = throw "don't want to use pkgs.nixUnstable"; + nixStatic = throw "don't want to use pkgs.nixStatic"; + }) + ]; }; testScript = '' From 6a0b24b27675d03a7f24c124e6c145076104e869 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 21 Mar 2022 22:54:07 +0100 Subject: [PATCH 5/8] lib: applyIfFunction -> applyModuleArgsIfFunction --- lib/default.nix | 2 +- lib/modules.nix | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index 3fead03a4636..1746efc68196 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -112,7 +112,7 @@ let commitIdFromGitRepo cleanSourceWith pathHasContext canCleanSource pathIsRegularFile pathIsGitRepo; inherit (self.modules) evalModules setDefaultModuleLocation - unifyModuleSyntax applyIfFunction mergeModules + unifyModuleSyntax applyModuleArgsIfFunction mergeModules mergeModules' mergeOptionDecls evalOptionValue mergeDefinitions pushDownProperties dischargeProperties filterOverrides sortProperties fixupOptionType mkIf mkAssert mkMerge mkOverride diff --git a/lib/modules.nix b/lib/modules.nix index 4c4d9f994dae..46739746e627 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -268,11 +268,11 @@ rec { # Like unifyModuleSyntax, but also imports paths and calls functions if necessary loadModule = args: fallbackFile: fallbackKey: m: if isFunction m || isAttrs m then - unifyModuleSyntax fallbackFile fallbackKey (applyIfFunction fallbackKey m args) + unifyModuleSyntax fallbackFile fallbackKey (applyModuleArgsIfFunction fallbackKey m args) else if isList m then let defs = [{ file = fallbackFile; value = m; }]; in throw "Module imports can't be nested lists. Perhaps you meant to remove one level of lists? Definitions: ${showDefs defs}" - else unifyModuleSyntax (toString m) (toString m) (applyIfFunction (toString m) (import m) args); + else unifyModuleSyntax (toString m) (toString m) (applyModuleArgsIfFunction (toString m) (import m) args); /* Collects all modules recursively into the form @@ -369,7 +369,7 @@ rec { config = addFreeformType (addMeta (removeAttrs m ["_file" "key" "disabledModules" "require" "imports" "freeformType"])); }; - applyIfFunction = key: f: args@{ config, options, lib, ... }: if isFunction f then + applyModuleArgsIfFunction = key: f: args@{ config, options, lib, ... }: if isFunction f then let # Module arguments are resolved in a strict manner when attribute set # deconstruction is used. As the arguments are now defined with the From 84274cbc95b370bf8e38430453b48b7017671a8a Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 21 Mar 2022 23:06:01 +0100 Subject: [PATCH 6/8] lib: Add toFunction --- lib/default.nix | 3 ++- lib/trivial.nix | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/default.nix b/lib/default.nix index 1746efc68196..2d231bbd2d92 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -68,7 +68,8 @@ let bitNot boolToString mergeAttrs flip mapNullable inNixShell isFloat min max importJSON importTOML warn warnIf throwIfNot checkListOfEnum info showWarnings nixpkgsVersion version - mod compare splitByAndCompare functionArgs setFunctionArgs isFunction + mod compare splitByAndCompare + functionArgs setFunctionArgs isFunction toFunction toHexString toBaseDigits; inherit (self.fixedPoints) fix fix' converge extends composeExtensions composeManyExtensions makeExtensible makeExtensibleWithCustomName; diff --git a/lib/trivial.nix b/lib/trivial.nix index c68bac902e91..52648125059d 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -403,6 +403,25 @@ rec { isFunction = f: builtins.isFunction f || (f ? __functor && isFunction (f.__functor f)); + /* + Turns any non-callable values into constant functions. + Returns callable values as is. + + Example: + + nix-repl> lib.toFunction 1 2 + 1 + + nix-repl> lib.toFunction (x: x + 1) 2 + 3 + */ + toFunction = + # Any value + v: + if isFunction v + then v + else k: v; + /* Convert the given positive integer to a string of its hexadecimal representation. For example: From db6e76f5246fa843c21bded326e1d0bd363f40ce Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 21 Mar 2022 23:09:20 +0100 Subject: [PATCH 7/8] nixosTest: Fix invocation toFunction isn't quite the same as callPackage, but the difference should only be relevant for cross pkgs, which are generally not testable anyway. --- pkgs/top-level/all-packages.nix | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index e2a40bdee621..09fc24d9bbd4 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -33612,9 +33612,7 @@ with pkgs; loadedTest = if builtins.typeOf test == "path" then import test else test; - calledTest = if lib.isFunction loadedTest - then loadedTest { inherit pkgs lib; } - else loadedTest; + calledTest = lib.toFunction loadedTest pkgs; in nixosTesting.makeTest calledTest; From b2d3baa3cf5d8650401d0e4b0d27284e084a1e52 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 21 Mar 2022 23:10:42 +0100 Subject: [PATCH 8/8] tests.nixos-functions.nixosTest-test: Test callPackage-like behavior --- pkgs/test/nixos-functions/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/test/nixos-functions/default.nix b/pkgs/test/nixos-functions/default.nix index 6a4f3164f929..a59160511b91 100644 --- a/pkgs/test/nixos-functions/default.nix +++ b/pkgs/test/nixos-functions/default.nix @@ -26,14 +26,14 @@ in lib.optionalAttrs stdenv.hostPlatform.isLinux ( fileSystems."/".device = "/dev/null"; }).toplevel; - nixosTest-test = pkgs.nixosTest ({ lib, pkgs, ... }: { + nixosTest-test = pkgs.nixosTest ({ lib, pkgs, figlet, ... }: { name = "nixosTest-test"; machine = { pkgs, ... }: { system.nixos = dummyVersioning; - environment.systemPackages = [ pkgs.hello ]; + environment.systemPackages = [ pkgs.hello figlet ]; }; testScript = '' - machine.succeed("hello") + machine.succeed("hello | figlet >/dev/console") ''; });