diff options
author | Ryan Lahfa <masterancpp@gmail.com> | 2023-01-15 18:52:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-15 18:52:09 +0100 |
commit | e2ac17f781dda8eef54f166996bfcd315ddb591f (patch) | |
tree | 0f2f6d1206567f06de091daea2720647b200ebe1 /nixos/tests | |
parent | 4ae2ca2ef8a1239d382bf2e7439290ce09086339 (diff) | |
parent | 2c55eba8f4604d1eef22f7bfd7df01312fe07272 (diff) |
Merge pull request #207466 from Patryk27/fix/174065
nixos: add --specialisation to nixos-rebuild
Diffstat (limited to 'nixos/tests')
-rw-r--r-- | nixos/tests/all-tests.nix | 2 | ||||
-rw-r--r-- | nixos/tests/nixos-rebuild-specialisations.nix | 131 | ||||
-rw-r--r-- | nixos/tests/specialisation.nix | 43 |
3 files changed, 132 insertions, 44 deletions
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index e6c786744d9db..0dde27b8623a4 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -436,7 +436,6 @@ in { netdata = handleTest ./netdata.nix {}; networking.networkd = handleTest ./networking.nix { networkd = true; }; networking.scripted = handleTest ./networking.nix { networkd = false; }; - specialisation = handleTest ./specialisation.nix {}; netbox = handleTest ./web-apps/netbox.nix {}; # TODO: put in networking.nix after the test becomes more complete networkingProxy = handleTest ./networking-proxy.nix {}; @@ -464,6 +463,7 @@ in { nix-serve-ssh = handleTest ./nix-serve-ssh.nix {}; nixops = handleTest ./nixops/default.nix {}; nixos-generate-config = handleTest ./nixos-generate-config.nix {}; + nixos-rebuild-specialisations = handleTest ./nixos-rebuild-specialisations.nix {}; nixpkgs = pkgs.callPackage ../modules/misc/nixpkgs/test.nix { inherit evalMinimalConfig; }; node-red = handleTest ./node-red.nix {}; nomad = handleTest ./nomad.nix {}; diff --git a/nixos/tests/nixos-rebuild-specialisations.nix b/nixos/tests/nixos-rebuild-specialisations.nix new file mode 100644 index 0000000000000..c61f81b8ca656 --- /dev/null +++ b/nixos/tests/nixos-rebuild-specialisations.nix @@ -0,0 +1,131 @@ +import ./make-test-python.nix ({ pkgs, ... }: { + name = "nixos-rebuild-specialisations"; + + nodes = { + machine = { lib, pkgs, ... }: { + imports = [ + ../modules/profiles/installation-device.nix + ../modules/profiles/base.nix + ]; + + nix.settings = { + substituters = lib.mkForce [ ]; + hashed-mirrors = null; + connect-timeout = 1; + }; + + system.extraDependencies = with pkgs; [ + curl + desktop-file-utils + docbook5 + docbook_xsl_ns + grub2 + kmod.dev + libarchive + libarchive.dev + libxml2.bin + libxslt.bin + python3Minimal + shared-mime-info + stdenv + sudo + xorg.lndir + ]; + + virtualisation = { + cores = 2; + memorySize = 2048; + }; + }; + }; + + testScript = + let + configFile = pkgs.writeText "configuration.nix" '' + { lib, pkgs, ... }: { + imports = [ + ./hardware-configuration.nix + <nixpkgs/nixos/modules/testing/test-instrumentation.nix> + ]; + + boot.loader.grub = { + enable = true; + device = "/dev/vda"; + forceInstall = true; + }; + + documentation.enable = false; + + environment.systemPackages = [ + (pkgs.writeShellScriptBin "parent" "") + ]; + + specialisation.foo = { + inheritParentConfig = true; + + configuration = { ... }: { + environment.systemPackages = [ + (pkgs.writeShellScriptBin "foo" "") + ]; + }; + }; + + specialisation.bar = { + inheritParentConfig = true; + + configuration = { ... }: { + environment.systemPackages = [ + (pkgs.writeShellScriptBin "bar" "") + ]; + }; + }; + } + ''; + + in + '' + machine.start() + machine.succeed("udevadm settle") + machine.wait_for_unit("multi-user.target") + + machine.succeed("nixos-generate-config") + machine.copy_from_host( + "${configFile}", + "/etc/nixos/configuration.nix", + ) + + with subtest("Switch to the base system"): + machine.succeed("nixos-rebuild switch") + machine.succeed("parent") + machine.fail("foo") + machine.fail("bar") + + with subtest("Switch from base system into a specialization"): + machine.succeed("nixos-rebuild switch --specialisation foo") + machine.succeed("parent") + machine.succeed("foo") + machine.fail("bar") + + with subtest("Switch from specialization into another specialization"): + machine.succeed("nixos-rebuild switch -c bar") + machine.succeed("parent") + machine.fail("foo") + machine.succeed("bar") + + with subtest("Switch from specialization into the base system"): + machine.succeed("nixos-rebuild switch") + machine.succeed("parent") + machine.fail("foo") + machine.fail("bar") + + with subtest("Switch into specialization using `nixos-rebuild test`"): + machine.succeed("nixos-rebuild test --specialisation foo") + machine.succeed("parent") + machine.succeed("foo") + machine.fail("bar") + + with subtest("Make sure nonsense command combinations are forbidden"): + machine.fail("nixos-rebuild boot --specialisation foo") + machine.fail("nixos-rebuild boot -c foo") + ''; +}) diff --git a/nixos/tests/specialisation.nix b/nixos/tests/specialisation.nix deleted file mode 100644 index b8d4b8279f4da..0000000000000 --- a/nixos/tests/specialisation.nix +++ /dev/null @@ -1,43 +0,0 @@ -import ./make-test-python.nix { - name = "specialisation"; - nodes = { - inheritconf = { pkgs, ... }: { - environment.systemPackages = [ pkgs.cowsay ]; - specialisation.inheritconf.configuration = { pkgs, ... }: { - environment.systemPackages = [ pkgs.hello ]; - }; - }; - noinheritconf = { pkgs, ... }: { - environment.systemPackages = [ pkgs.cowsay ]; - specialisation.noinheritconf = { - inheritParentConfig = false; - configuration = { pkgs, ... }: { - environment.systemPackages = [ pkgs.hello ]; - }; - }; - }; - }; - testScript = '' - inheritconf.wait_for_unit("default.target") - inheritconf.succeed("cowsay hey") - inheritconf.fail("hello") - - with subtest("Nested clones do inherit from parent"): - inheritconf.succeed( - "/run/current-system/specialisation/inheritconf/bin/switch-to-configuration test" - ) - inheritconf.succeed("cowsay hey") - inheritconf.succeed("hello") - - noinheritconf.wait_for_unit("default.target") - noinheritconf.succeed("cowsay hey") - noinheritconf.fail("hello") - - with subtest("Nested children do not inherit from parent"): - noinheritconf.succeed( - "/run/current-system/specialisation/noinheritconf/bin/switch-to-configuration test" - ) - noinheritconf.fail("cowsay hey") - noinheritconf.succeed("hello") - ''; -} |