From 18c734d7f2ca4e86730808b8b4900363cb705ed3 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Sat, 3 Jun 2023 19:43:20 -0700 Subject: [PATCH 1/3] nixosTest: adds support for lib.extend When lib overrides were used, before this commit, they would not be made available in the configuration evaluation of nixosTest's nodes. Sample code: ``` nix let pkgs = import ./. { overlays = [ (new: old: { lib = old.lib.extend (self: super: { sorry_dave = builtins.trace "There are no pod bay doors" "sorry dave"; }); }) ]; }; in pkgs.testers.nixosTest { name = "demo lib overlay"; nodes = { machine = { lib, ... }: { environment.etc."got-lib-overlay".text = lib.sorry_dave; }; }; testScript = { nodes }: '' start_all() machine.succeed('grep dave /etc/got-lib-overlay') ''; } ``` --- nixos/lib/testing/nodes.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nixos/lib/testing/nodes.nix b/nixos/lib/testing/nodes.nix index 6e439fd814db..f58759b4cdba 100644 --- a/nixos/lib/testing/nodes.nix +++ b/nixos/lib/testing/nodes.nix @@ -16,6 +16,7 @@ let baseOS = import ../eval-config.nix { + inherit lib; system = null; # use modularly defined system inherit (config.node) specialArgs; modules = [ config.defaults ]; From 562f879cd173525076b79fc9b04de77004ad37c8 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Wed, 14 Jun 2023 23:12:44 -0700 Subject: [PATCH 2/3] runNixOSTest: adds support for lib.extend When lib overrides were used, before this commit, they would not be made available in the configuration evaluation of nixosTest's nodes. Sample code: ``` nix let pkgs = import ./. { overlays = [ (new: old: { lib = old.lib.extend (self: super: { sorry_dave = builtins.trace "There are no pod bay doors" "sorry dave"; }); }) ]; }; in pkgs.testers.runNixOSTest { name = "demo lib overlay"; nodes = { machine = { lib, ... }: { environment.etc."got-lib-overlay".text = lib.sorry_dave; }; }; testScript = { nodes }: '' start_all() machine.succeed('grep dave /etc/got-lib-overlay') ''; } ``` --- pkgs/build-support/testers/default.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/testers/default.nix b/pkgs/build-support/testers/default.nix index 190ce72d0e63..d380dc6f30e1 100644 --- a/pkgs/build-support/testers/default.nix +++ b/pkgs/build-support/testers/default.nix @@ -97,7 +97,9 @@ # See doc/builders/testers.chapter.md or # https://nixos.org/manual/nixpkgs/unstable/#tester-runNixOSTest runNixOSTest = - let nixos = import ../../../nixos/lib {}; + let nixos = import ../../../nixos/lib { + inherit lib; + }; in testModule: nixos.runTest { _file = "pkgs.runNixOSTest implementation"; From 933851135002dcc5564ac51263b5e24a5bb14ecc Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Sat, 3 Jun 2023 20:10:20 -0700 Subject: [PATCH 3/3] nixosTest: provide a test for lib.extend in nixosTests & runNixOSTest --- nixos/tests/all-tests.nix | 1 + nixos/tests/nixos-test-driver/lib-extend.nix | 31 ++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 nixos/tests/nixos-test-driver/lib-extend.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 1b90b3e13807..02bef2039075 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -87,6 +87,7 @@ in { # Testing the test driver nixos-test-driver = { extra-python-packages = handleTest ./nixos-test-driver/extra-python-packages.nix {}; + lib-extend = handleTestOn [ "x86_64-linux" "aarch64-linux" ] ./nixos-test-driver/lib-extend.nix {}; node-name = runTest ./nixos-test-driver/node-name.nix; }; diff --git a/nixos/tests/nixos-test-driver/lib-extend.nix b/nixos/tests/nixos-test-driver/lib-extend.nix new file mode 100644 index 000000000000..4fb7cf494aed --- /dev/null +++ b/nixos/tests/nixos-test-driver/lib-extend.nix @@ -0,0 +1,31 @@ +{ pkgs, ... }: + +let + patchedPkgs = pkgs.extend (new: old: { + lib = old.lib.extend (self: super: { + sorry_dave = "sorry dave"; + }); + }); + + testBody = { + name = "demo lib overlay"; + + nodes = { + machine = { lib, ... }: { + environment.etc."got-lib-overlay".text = lib.sorry_dave; + }; + }; + + # We don't need to run an actual test. Instead we build the `machine` configuration + # and call it a day, because that already proves that `lib` is wired up correctly. + # See the attrset returned at the bottom of this file. + testScript = ""; + }; + + inherit (patchedPkgs.testers) nixosTest runNixOSTest; + evaluationNixosTest = nixosTest testBody; + evaluationRunNixOSTest = runNixOSTest testBody; +in { + nixosTest = evaluationNixosTest.driver.nodes.machine.system.build.toplevel; + runNixOSTest = evaluationRunNixOSTest.driver.nodes.machine.system.build.toplevel; +}