Release NixOS 23.11
[NixPkgs.git] / nixos / tests / bootspec.nix
blob9295500422a9283ad9af5bba61f31580b95b5d01
1 { system ? builtins.currentSystem,
2   config ? {},
3   pkgs ? import ../.. { inherit system config; }
4 }:
6 with import ../lib/testing-python.nix { inherit system pkgs; };
7 with pkgs.lib;
9 let
10   baseline = {
11     virtualisation.useBootLoader = true;
12   };
13   grub = {
14     boot.loader.grub.enable = true;
15   };
16   systemd-boot = {
17     boot.loader.systemd-boot.enable = true;
18   };
19   uefi = {
20     virtualisation.useEFIBoot = true;
21     boot.loader.efi.canTouchEfiVariables = true;
22     boot.loader.grub.efiSupport = true;
23     environment.systemPackages = [ pkgs.efibootmgr ];
24   };
25   standard = {
26     boot.bootspec.enable = true;
28     imports = [
29       baseline
30       systemd-boot
31       uefi
32     ];
33   };
36   basic = makeTest {
37     name = "systemd-boot-with-bootspec";
38     meta.maintainers = with pkgs.lib.maintainers; [ raitobezarius ];
40     nodes.machine = standard;
42     testScript = ''
43       machine.start()
44       machine.wait_for_unit("multi-user.target")
46       machine.succeed("test -e /run/current-system/boot.json")
47     '';
48   };
50   grub = makeTest {
51     name = "grub-with-bootspec";
52     meta.maintainers = with pkgs.lib.maintainers; [ raitobezarius ];
54     nodes.machine = {
55       boot.bootspec.enable = true;
57       imports = [
58         baseline
59         grub
60         uefi
61       ];
62     };
64     testScript = ''
65       machine.start()
66       machine.wait_for_unit("multi-user.target")
68       machine.succeed("test -e /run/current-system/boot.json")
69     '';
70   };
72   legacy-boot = makeTest {
73     name = "legacy-boot-with-bootspec";
74     meta.maintainers = with pkgs.lib.maintainers; [ raitobezarius ];
76     nodes.machine = {
77       boot.bootspec.enable = true;
79       imports = [
80         baseline
81         grub
82       ];
83     };
85     testScript = ''
86       machine.start()
87       machine.wait_for_unit("multi-user.target")
89       machine.succeed("test -e /run/current-system/boot.json")
90     '';
91   };
93   # Check that initrd create corresponding entries in bootspec.
94   initrd = makeTest {
95     name = "bootspec-with-initrd";
96     meta.maintainers = with pkgs.lib.maintainers; [ raitobezarius ];
98     nodes.machine = {
99       imports = [ standard ];
100       environment.systemPackages = [ pkgs.jq ];
101       # It's probably the case, but we want to make it explicit here.
102       boot.initrd.enable = true;
103     };
105     testScript = ''
106       import json
108       machine.start()
109       machine.wait_for_unit("multi-user.target")
111       machine.succeed("test -e /run/current-system/boot.json")
113       bootspec = json.loads(machine.succeed("jq -r '.\"org.nixos.bootspec.v1\"' /run/current-system/boot.json"))
115       assert all(key in bootspec for key in ('initrd', 'initrdSecrets')), "Bootspec should contain initrd or initrdSecrets field when initrd is enabled"
116     '';
117   };
119   # Check that specialisations create corresponding entries in bootspec.
120   specialisation = makeTest {
121     name = "bootspec-with-specialisation";
122     meta.maintainers = with pkgs.lib.maintainers; [ raitobezarius ];
124     nodes.machine = {
125       imports = [ standard ];
126       environment.systemPackages = [ pkgs.jq ];
127       specialisation.something.configuration = {};
128     };
130     testScript = ''
131       import json
133       machine.start()
134       machine.wait_for_unit("multi-user.target")
136       machine.succeed("test -e /run/current-system/boot.json")
137       machine.succeed("test -e /run/current-system/specialisation/something/boot.json")
139       sp_in_parent = json.loads(machine.succeed("jq -r '.\"org.nixos.specialisation.v1\".something' /run/current-system/boot.json"))
140       sp_in_fs = json.loads(machine.succeed("cat /run/current-system/specialisation/something/boot.json"))
142       assert sp_in_parent['org.nixos.bootspec.v1'] == sp_in_fs['org.nixos.bootspec.v1'], "Bootspecs of the same specialisation are different!"
143     '';
144   };
146   # Check that extensions are propagated.
147   extensions = makeTest {
148     name = "bootspec-with-extensions";
149     meta.maintainers = with pkgs.lib.maintainers; [ raitobezarius ];
151     nodes.machine = { config, ... }: {
152       imports = [ standard ];
153       environment.systemPackages = [ pkgs.jq ];
154       boot.bootspec.extensions = {
155         "org.nix-tests.product" = {
156           osRelease = config.environment.etc."os-release".source;
157         };
158       };
159     };
161     testScript = ''
162       machine.start()
163       machine.wait_for_unit("multi-user.target")
165       current_os_release = machine.succeed("cat /etc/os-release")
166       bootspec_os_release = machine.succeed("cat $(jq -r '.\"org.nix-tests.product\".osRelease' /run/current-system/boot.json)")
168       assert current_os_release == bootspec_os_release, "Filename referenced by extension has unexpected contents"
169     '';
170   };