at 24.11-pre 3.3 kB view raw
1import ./make-test-python.nix ({ pkgs, ... }: { 2 name = "nixos-rebuild-specialisations"; 3 4 nodes = { 5 machine = { lib, pkgs, ... }: { 6 imports = [ 7 ../modules/profiles/installation-device.nix 8 ../modules/profiles/base.nix 9 ]; 10 11 nix.settings = { 12 substituters = lib.mkForce [ ]; 13 hashed-mirrors = null; 14 connect-timeout = 1; 15 }; 16 17 system.includeBuildDependencies = true; 18 19 system.extraDependencies = [ 20 # Not part of the initial build apparently? 21 pkgs.grub2 22 ]; 23 24 virtualisation = { 25 cores = 2; 26 memorySize = 4096; 27 }; 28 }; 29 }; 30 31 testScript = 32 let 33 configFile = pkgs.writeText "configuration.nix" '' 34 { lib, pkgs, ... }: { 35 imports = [ 36 ./hardware-configuration.nix 37 <nixpkgs/nixos/modules/testing/test-instrumentation.nix> 38 ]; 39 40 boot.loader.grub = { 41 enable = true; 42 device = "/dev/vda"; 43 forceInstall = true; 44 }; 45 46 documentation.enable = false; 47 48 environment.systemPackages = [ 49 (pkgs.writeShellScriptBin "parent" "") 50 ]; 51 52 specialisation.foo = { 53 inheritParentConfig = true; 54 55 configuration = { ... }: { 56 environment.systemPackages = [ 57 (pkgs.writeShellScriptBin "foo" "") 58 ]; 59 }; 60 }; 61 62 specialisation.bar = { 63 inheritParentConfig = true; 64 65 configuration = { ... }: { 66 environment.systemPackages = [ 67 (pkgs.writeShellScriptBin "bar" "") 68 ]; 69 }; 70 }; 71 } 72 ''; 73 74 in 75 '' 76 machine.start() 77 machine.succeed("udevadm settle") 78 machine.wait_for_unit("multi-user.target") 79 80 machine.succeed("nixos-generate-config") 81 machine.copy_from_host( 82 "${configFile}", 83 "/etc/nixos/configuration.nix", 84 ) 85 86 with subtest("Switch to the base system"): 87 machine.succeed("nixos-rebuild switch") 88 machine.succeed("parent") 89 machine.fail("foo") 90 machine.fail("bar") 91 92 with subtest("Switch from base system into a specialization"): 93 machine.succeed("nixos-rebuild switch --specialisation foo") 94 machine.succeed("parent") 95 machine.succeed("foo") 96 machine.fail("bar") 97 98 with subtest("Switch from specialization into another specialization"): 99 machine.succeed("nixos-rebuild switch -c bar") 100 machine.succeed("parent") 101 machine.fail("foo") 102 machine.succeed("bar") 103 104 with subtest("Switch from specialization into the base system"): 105 machine.succeed("nixos-rebuild switch") 106 machine.succeed("parent") 107 machine.fail("foo") 108 machine.fail("bar") 109 110 with subtest("Switch into specialization using `nixos-rebuild test`"): 111 machine.succeed("nixos-rebuild test --specialisation foo") 112 machine.succeed("parent") 113 machine.succeed("foo") 114 machine.fail("bar") 115 116 with subtest("Make sure nonsense command combinations are forbidden"): 117 machine.fail("nixos-rebuild boot --specialisation foo") 118 machine.fail("nixos-rebuild boot -c foo") 119 ''; 120})