2 name = "nixos-rebuild-specialisations";
4 # TODO: remove overlay from nixos/modules/profiles/installation-device.nix
5 # make it a _small package instead, then remove pkgsReadOnly = false;.
6 node.pkgsReadOnly = false;
9 machine = { lib, pkgs, ... }: {
11 ../modules/profiles/installation-device.nix
12 ../modules/profiles/base.nix
16 substituters = lib.mkForce [ ];
17 hashed-mirrors = null;
21 system.includeBuildDependencies = true;
23 system.extraDependencies = [
24 # Not part of the initial build apparently?
28 system.switch.enable = true;
39 configFile = hostPkgs.writeText "configuration.nix" ''
42 ./hardware-configuration.nix
43 <nixpkgs/nixos/modules/testing/test-instrumentation.nix>
52 documentation.enable = false;
54 environment.systemPackages = [
55 (pkgs.writeShellScriptBin "parent" "")
58 specialisation.foo = {
59 inheritParentConfig = true;
61 configuration = { ... }: {
62 environment.systemPackages = [
63 (pkgs.writeShellScriptBin "foo" "")
68 specialisation.bar = {
69 inheritParentConfig = true;
71 configuration = { ... }: {
72 environment.systemPackages = [
73 (pkgs.writeShellScriptBin "bar" "")
83 machine.succeed("udevadm settle")
84 machine.wait_for_unit("multi-user.target")
86 machine.succeed("nixos-generate-config")
87 machine.copy_from_host(
89 "/etc/nixos/configuration.nix",
92 with subtest("Switch to the base system"):
93 machine.succeed("nixos-rebuild switch")
94 machine.succeed("parent")
98 with subtest("Switch from base system into a specialization"):
99 machine.succeed("nixos-rebuild switch --specialisation foo")
100 machine.succeed("parent")
101 machine.succeed("foo")
104 with subtest("Switch from specialization into another specialization"):
105 machine.succeed("nixos-rebuild switch -c bar")
106 machine.succeed("parent")
108 machine.succeed("bar")
110 with subtest("Switch from specialization into the base system"):
111 machine.succeed("nixos-rebuild switch")
112 machine.succeed("parent")
116 with subtest("Switch into specialization using `nixos-rebuild test`"):
117 machine.succeed("nixos-rebuild test --specialisation foo")
118 machine.succeed("parent")
119 machine.succeed("foo")
122 with subtest("Make sure nonsense command combinations are forbidden"):
123 machine.fail("nixos-rebuild boot --specialisation foo")
124 machine.fail("nixos-rebuild boot -c foo")