1 { system ? builtins.currentSystem,
3 pkgs ? import ../.. { inherit system config; }
6 with import ../lib/testing-python.nix { inherit system pkgs; };
11 virtualisation.useBootLoader = true;
12 virtualisation.useEFIBoot = true;
13 boot.loader.systemd-boot.enable = true;
14 boot.loader.efi.canTouchEfiVariables = true;
15 environment.systemPackages = [ pkgs.efibootmgr ];
20 name = "systemd-boot";
21 meta.maintainers = with pkgs.lib.maintainers; [ danielfullmer ];
23 nodes.machine = common;
27 machine.wait_for_unit("multi-user.target")
29 machine.succeed("test -e /boot/loader/entries/nixos-generation-1.conf")
31 # Ensure we actually booted using systemd-boot
32 # Magic number is the vendor UUID used by systemd-boot.
34 "test -e /sys/firmware/efi/efivars/LoaderEntrySelected-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f"
37 # "bootctl install" should have created an EFI entry
38 machine.succeed('efibootmgr | grep "Linux Boot Manager"')
42 # Check that specialisations create corresponding boot entries.
43 specialisation = makeTest {
44 name = "systemd-boot-specialisation";
45 meta.maintainers = with pkgs.lib.maintainers; [ lukegb ];
47 nodes.machine = { pkgs, lib, ... }: {
49 specialisation.something.configuration = {};
54 machine.wait_for_unit("multi-user.target")
57 "test -e /boot/loader/entries/nixos-generation-1-specialisation-something.conf"
60 "grep -q 'title NixOS (something)' /boot/loader/entries/nixos-generation-1-specialisation-something.conf"
65 # Boot without having created an EFI entry--instead using default "/EFI/BOOT/BOOTX64.EFI"
67 name = "systemd-boot-fallback";
68 meta.maintainers = with pkgs.lib.maintainers; [ danielfullmer ];
70 nodes.machine = { pkgs, lib, ... }: {
72 boot.loader.efi.canTouchEfiVariables = mkForce false;
77 machine.wait_for_unit("multi-user.target")
79 machine.succeed("test -e /boot/loader/entries/nixos-generation-1.conf")
81 # Ensure we actually booted using systemd-boot
82 # Magic number is the vendor UUID used by systemd-boot.
84 "test -e /sys/firmware/efi/efivars/LoaderEntrySelected-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f"
87 # "bootctl install" should _not_ have created an EFI entry
88 machine.fail('efibootmgr | grep "Linux Boot Manager"')
93 name = "systemd-boot-update";
94 meta.maintainers = with pkgs.lib.maintainers; [ danielfullmer ];
96 nodes.machine = common;
99 machine.succeed("mount -o remount,rw /boot")
101 # Replace version inside sd-boot with something older. See magic[] string in systemd src/boot/efi/boot.c
104 find /boot -iname '*.efi' -print0 | \
105 xargs -0 -I '{}' sed -i 's/#### LoaderInfo: systemd-boot .* ####/#### LoaderInfo: systemd-boot 000.0-1-notnixos ####/' '{}'
109 output = machine.succeed("/run/current-system/bin/switch-to-configuration boot")
110 assert "updating systemd-boot from (000.0-1-notnixos) to " in output
114 memtest86 = makeTest {
115 name = "systemd-boot-memtest86";
116 meta.maintainers = with pkgs.lib.maintainers; [ Enzime ];
118 nodes.machine = { pkgs, lib, ... }: {
119 imports = [ common ];
120 boot.loader.systemd-boot.memtest86.enable = true;
121 nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
127 machine.succeed("test -e /boot/loader/entries/memtest86.conf")
128 machine.succeed("test -e /boot/efi/memtest86/BOOTX64.efi")
132 netbootxyz = makeTest {
133 name = "systemd-boot-netbootxyz";
134 meta.maintainers = with pkgs.lib.maintainers; [ Enzime ];
136 nodes.machine = { pkgs, lib, ... }: {
137 imports = [ common ];
138 boot.loader.systemd-boot.netbootxyz.enable = true;
142 machine.succeed("test -e /boot/loader/entries/o_netbootxyz.conf")
143 machine.succeed("test -e /boot/efi/netbootxyz/netboot.xyz.efi")
147 entryFilename = makeTest {
148 name = "systemd-boot-entry-filename";
149 meta.maintainers = with pkgs.lib.maintainers; [ Enzime ];
151 nodes.machine = { pkgs, lib, ... }: {
152 imports = [ common ];
153 boot.loader.systemd-boot.memtest86.enable = true;
154 boot.loader.systemd-boot.memtest86.entryFilename = "apple.conf";
155 nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
161 machine.fail("test -e /boot/loader/entries/memtest86.conf")
162 machine.succeed("test -e /boot/loader/entries/apple.conf")
163 machine.succeed("test -e /boot/efi/memtest86/BOOTX64.efi")
167 extraEntries = makeTest {
168 name = "systemd-boot-extra-entries";
169 meta.maintainers = with pkgs.lib.maintainers; [ Enzime ];
171 nodes.machine = { pkgs, lib, ... }: {
172 imports = [ common ];
173 boot.loader.systemd-boot.extraEntries = {
181 machine.succeed("test -e /boot/loader/entries/banana.conf")
182 machine.succeed("test -e /boot/efi/nixos/.extra-files/loader/entries/banana.conf")
186 extraFiles = makeTest {
187 name = "systemd-boot-extra-files";
188 meta.maintainers = with pkgs.lib.maintainers; [ Enzime ];
190 nodes.machine = { pkgs, lib, ... }: {
191 imports = [ common ];
192 boot.loader.systemd-boot.extraFiles = {
193 "efi/fruits/tomato.efi" = pkgs.netbootxyz-efi;
198 machine.succeed("test -e /boot/efi/fruits/tomato.efi")
199 machine.succeed("test -e /boot/efi/nixos/.extra-files/efi/fruits/tomato.efi")
203 switch-test = makeTest {
204 name = "systemd-boot-switch-test";
205 meta.maintainers = with pkgs.lib.maintainers; [ Enzime ];
210 machine = { pkgs, ... }: {
211 imports = [ common ];
212 boot.loader.systemd-boot.extraFiles = {
213 "efi/fruits/tomato.efi" = pkgs.netbootxyz-efi;
217 with_netbootxyz = { pkgs, ... }: {
218 imports = [ common ];
219 boot.loader.systemd-boot.netbootxyz.enable = true;
223 testScript = { nodes, ... }: let
224 originalSystem = nodes.machine.config.system.build.toplevel;
225 baseSystem = nodes.common.config.system.build.toplevel;
226 finalSystem = nodes.with_netbootxyz.config.system.build.toplevel;
228 machine.succeed("test -e /boot/efi/fruits/tomato.efi")
229 machine.succeed("test -e /boot/efi/nixos/.extra-files/efi/fruits/tomato.efi")
231 with subtest("remove files when no longer needed"):
232 machine.succeed("${baseSystem}/bin/switch-to-configuration boot")
233 machine.fail("test -e /boot/efi/fruits/tomato.efi")
234 machine.fail("test -d /boot/efi/fruits")
235 machine.succeed("test -d /boot/efi/nixos/.extra-files")
236 machine.fail("test -e /boot/efi/nixos/.extra-files/efi/fruits/tomato.efi")
237 machine.fail("test -d /boot/efi/nixos/.extra-files/efi/fruits")
239 with subtest("files are added back when needed again"):
240 machine.succeed("${originalSystem}/bin/switch-to-configuration boot")
241 machine.succeed("test -e /boot/efi/fruits/tomato.efi")
242 machine.succeed("test -e /boot/efi/nixos/.extra-files/efi/fruits/tomato.efi")
244 with subtest("simultaneously removing and adding files works"):
245 machine.succeed("${finalSystem}/bin/switch-to-configuration boot")
246 machine.fail("test -e /boot/efi/fruits/tomato.efi")
247 machine.fail("test -e /boot/efi/nixos/.extra-files/efi/fruits/tomato.efi")
248 machine.succeed("test -e /boot/loader/entries/o_netbootxyz.conf")
249 machine.succeed("test -e /boot/efi/netbootxyz/netboot.xyz.efi")
250 machine.succeed("test -e /boot/efi/nixos/.extra-files/loader/entries/o_netbootxyz.conf")
251 machine.succeed("test -e /boot/efi/nixos/.extra-files/efi/netbootxyz/netboot.xyz.efi")