From d50b43423455ac06f3e237dbc0a0c98bcb4b5dcf Mon Sep 17 00:00:00 2001 From: Arian van Putten Date: Sun, 26 May 2019 00:15:10 +0200 Subject: [PATCH 1/3] nixos: Make 'nesting.clone' work in NixOS tests Because nesting.clone calls 'eval-config.nix' manually, without the 'extraArgs' argument that provides the 'nodes' argument to nixos modules in nixos tests, evaluating of 'nesting.clone' definitions would fail with the following error while evaluating the module argument `nodes' in "" while evaluating the attribute '_module.args.nodes' at undefined position: attribute 'nodes' missing, at Date: Sun, 26 May 2019 00:35:29 +0200 Subject: [PATCH 2/3] nixos: Add test that demonstrates how to use nesting.clone This is actually very useful. Allows you to test switch-to-configuration nesting.children is still currently still broken as it will throw away 'too much' of the config, including the modules that make nixos tests work in the first place. But that's something for another time. --- nixos/tests/all-tests.nix | 1 + nixos/tests/nesting.nix | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 nixos/tests/nesting.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 9bce49c9e30..10a381c2c8f 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -161,6 +161,7 @@ in nat.standalone = handleTest ./nat.nix { withFirewall = false; }; ndppd = handleTest ./ndppd.nix {}; neo4j = handleTest ./neo4j.nix {}; + nesting = handleTest ./nesting.nix {}; netdata = handleTest ./netdata.nix {}; networking.networkd = handleTest ./networking.nix { networkd = true; }; networking.scripted = handleTest ./networking.nix { networkd = false; }; diff --git a/nixos/tests/nesting.nix b/nixos/tests/nesting.nix new file mode 100644 index 00000000000..3be64d7a9b5 --- /dev/null +++ b/nixos/tests/nesting.nix @@ -0,0 +1,22 @@ +import ./make-test.nix { + name = "nesting"; + machine = { pkgs, ... }: { + environment.systemPackages = [ pkgs.cowsay ]; + nesting.clone = [ + ({ pkgs, ... }: { + environment.systemPackages = [ pkgs.hello ]; + }) + ]; + }; + testScript = '' + $machine->waitForUnit("default.target"); + $machine->succeed("cowsay hey"); + $machine->fail("hello"); + + # Nested clones do inherit from parent + $machine->succeed("/run/current-system/fine-tune/child-1/bin/switch-to-configuration test"); + $machine->succeed("cowsay hey"); + $machine->succeed("hello"); + + ''; +} From cbc45b5981f26c80e7d78e9525373b1388b7e516 Mon Sep 17 00:00:00 2001 From: Arian van Putten Date: Sun, 26 May 2019 00:52:52 +0200 Subject: [PATCH 3/3] nixos: Make nesting.children work in NixOS tests We differentiate between modules and baseModules in the VM builder for NixOS tests. This way, nesting.children, eventhough it doesn't inherit from parent, still has enough config to actually complete the test. Otherwise, the qemu modules would not be loaded, for example, and a nesting.children statement would not evaluate. --- nixos/lib/build-vms.nix | 6 +++--- nixos/tests/nesting.nix | 46 +++++++++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/nixos/lib/build-vms.nix b/nixos/lib/build-vms.nix index ba8e13b431a..6c92aa1ffa2 100644 --- a/nixos/lib/build-vms.nix +++ b/nixos/lib/build-vms.nix @@ -32,14 +32,14 @@ rec { import ./eval-config.nix { inherit system; - modules = configurations ++ + modules = configurations ++ extraConfigurations; + baseModules = (import ../modules/module-list.nix) ++ [ ../modules/virtualisation/qemu-vm.nix ../modules/testing/test-instrumentation.nix # !!! should only get added for automated test runs { key = "no-manual"; documentation.nixos.enable = false; } { key = "qemu"; system.build.qemu = qemu; } { key = "nodes"; _module.args.nodes = nodes; } - ] ++ optional minimal ../modules/testing/minimal-kernel.nix - ++ extraConfigurations; + ] ++ optional minimal ../modules/testing/minimal-kernel.nix; }; diff --git a/nixos/tests/nesting.nix b/nixos/tests/nesting.nix index 3be64d7a9b5..1306d6f8e0c 100644 --- a/nixos/tests/nesting.nix +++ b/nixos/tests/nesting.nix @@ -1,22 +1,42 @@ import ./make-test.nix { name = "nesting"; - machine = { pkgs, ... }: { - environment.systemPackages = [ pkgs.cowsay ]; - nesting.clone = [ - ({ pkgs, ... }: { - environment.systemPackages = [ pkgs.hello ]; - }) - ]; + nodes = { + clone = { pkgs, ... }: { + environment.systemPackages = [ pkgs.cowsay ]; + nesting.clone = [ + ({ pkgs, ... }: { + environment.systemPackages = [ pkgs.hello ]; + }) + ]; + }; + children = { pkgs, ... }: { + environment.systemPackages = [ pkgs.cowsay ]; + nesting.children = [ + ({ pkgs, ... }: { + environment.systemPackages = [ pkgs.hello ]; + }) + ]; + }; }; testScript = '' - $machine->waitForUnit("default.target"); - $machine->succeed("cowsay hey"); - $machine->fail("hello"); + $clone->waitForUnit("default.target"); + $clone->succeed("cowsay hey"); + $clone->fail("hello"); # Nested clones do inherit from parent - $machine->succeed("/run/current-system/fine-tune/child-1/bin/switch-to-configuration test"); - $machine->succeed("cowsay hey"); - $machine->succeed("hello"); + $clone->succeed("/run/current-system/fine-tune/child-1/bin/switch-to-configuration test"); + $clone->succeed("cowsay hey"); + $clone->succeed("hello"); + + + $children->waitForUnit("default.target"); + $children->succeed("cowsay hey"); + $children->fail("hello"); + + # Nested children do not inherit from parent + $children->succeed("/run/current-system/fine-tune/child-1/bin/switch-to-configuration test"); + $children->fail("cowsay hey"); + $children->succeed("hello"); ''; }