at 23.11-pre 3.5 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.extraDependencies = with pkgs; [ 18 curl 19 desktop-file-utils 20 docbook5 21 docbook_xsl_ns 22 grub2 23 kmod.dev 24 libarchive 25 libarchive.dev 26 libxml2.bin 27 libxslt.bin 28 python3Minimal 29 shared-mime-info 30 stdenv 31 sudo 32 xorg.lndir 33 ]; 34 35 virtualisation = { 36 cores = 2; 37 memorySize = 2048; 38 }; 39 }; 40 }; 41 42 testScript = 43 let 44 configFile = pkgs.writeText "configuration.nix" '' 45 { lib, pkgs, ... }: { 46 imports = [ 47 ./hardware-configuration.nix 48 <nixpkgs/nixos/modules/testing/test-instrumentation.nix> 49 ]; 50 51 boot.loader.grub = { 52 enable = true; 53 device = "/dev/vda"; 54 forceInstall = true; 55 }; 56 57 documentation.enable = false; 58 59 environment.systemPackages = [ 60 (pkgs.writeShellScriptBin "parent" "") 61 ]; 62 63 specialisation.foo = { 64 inheritParentConfig = true; 65 66 configuration = { ... }: { 67 environment.systemPackages = [ 68 (pkgs.writeShellScriptBin "foo" "") 69 ]; 70 }; 71 }; 72 73 specialisation.bar = { 74 inheritParentConfig = true; 75 76 configuration = { ... }: { 77 environment.systemPackages = [ 78 (pkgs.writeShellScriptBin "bar" "") 79 ]; 80 }; 81 }; 82 } 83 ''; 84 85 in 86 '' 87 machine.start() 88 machine.succeed("udevadm settle") 89 machine.wait_for_unit("multi-user.target") 90 91 machine.succeed("nixos-generate-config") 92 machine.copy_from_host( 93 "${configFile}", 94 "/etc/nixos/configuration.nix", 95 ) 96 97 with subtest("Switch to the base system"): 98 machine.succeed("nixos-rebuild switch") 99 machine.succeed("parent") 100 machine.fail("foo") 101 machine.fail("bar") 102 103 with subtest("Switch from base system into a specialization"): 104 machine.succeed("nixos-rebuild switch --specialisation foo") 105 machine.succeed("parent") 106 machine.succeed("foo") 107 machine.fail("bar") 108 109 with subtest("Switch from specialization into another specialization"): 110 machine.succeed("nixos-rebuild switch -c bar") 111 machine.succeed("parent") 112 machine.fail("foo") 113 machine.succeed("bar") 114 115 with subtest("Switch from specialization into the base system"): 116 machine.succeed("nixos-rebuild switch") 117 machine.succeed("parent") 118 machine.fail("foo") 119 machine.fail("bar") 120 121 with subtest("Switch into specialization using `nixos-rebuild test`"): 122 machine.succeed("nixos-rebuild test --specialisation foo") 123 machine.succeed("parent") 124 machine.succeed("foo") 125 machine.fail("bar") 126 127 with subtest("Make sure nonsense command combinations are forbidden"): 128 machine.fail("nixos-rebuild boot --specialisation foo") 129 machine.fail("nixos-rebuild boot -c foo") 130 ''; 131})