1{ system ? builtins.currentSystem,
2 config ? {},
3 pkgs ? import ../.. { inherit system config; }
4}:
5
6with import ../lib/testing-python.nix { inherit system pkgs; };
7with pkgs.lib;
8
9let
10 common = {
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 ];
16 };
17in
18{
19 basic = makeTest {
20 name = "systemd-boot";
21 meta.maintainers = with pkgs.lib.maintainers; [ danielfullmer ];
22
23 machine = common;
24
25 testScript = ''
26 machine.start()
27 machine.wait_for_unit("multi-user.target")
28
29 machine.succeed("test -e /boot/loader/entries/nixos-generation-1.conf")
30
31 # Ensure we actually booted using systemd-boot
32 # Magic number is the vendor UUID used by systemd-boot.
33 machine.succeed(
34 "test -e /sys/firmware/efi/efivars/LoaderEntrySelected-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f"
35 )
36
37 # "bootctl install" should have created an EFI entry
38 machine.succeed('efibootmgr | grep "Linux Boot Manager"')
39 '';
40 };
41
42 # Check that specialisations create corresponding boot entries.
43 specialisation = makeTest {
44 name = "systemd-boot-specialisation";
45 meta.maintainers = with pkgs.lib.maintainers; [ lukegb ];
46
47 machine = { pkgs, lib, ... }: {
48 imports = [ common ];
49 specialisation.something.configuration = {};
50 };
51
52 testScript = ''
53 machine.start()
54 machine.wait_for_unit("multi-user.target")
55
56 machine.succeed(
57 "test -e /boot/loader/entries/nixos-generation-1-specialisation-something.conf"
58 )
59 machine.succeed(
60 "grep -q 'title NixOS (something)' /boot/loader/entries/nixos-generation-1-specialisation-something.conf"
61 )
62 '';
63 };
64
65 # Boot without having created an EFI entry--instead using default "/EFI/BOOT/BOOTX64.EFI"
66 fallback = makeTest {
67 name = "systemd-boot-fallback";
68 meta.maintainers = with pkgs.lib.maintainers; [ danielfullmer ];
69
70 machine = { pkgs, lib, ... }: {
71 imports = [ common ];
72 boot.loader.efi.canTouchEfiVariables = mkForce false;
73 };
74
75 testScript = ''
76 machine.start()
77 machine.wait_for_unit("multi-user.target")
78
79 machine.succeed("test -e /boot/loader/entries/nixos-generation-1.conf")
80
81 # Ensure we actually booted using systemd-boot
82 # Magic number is the vendor UUID used by systemd-boot.
83 machine.succeed(
84 "test -e /sys/firmware/efi/efivars/LoaderEntrySelected-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f"
85 )
86
87 # "bootctl install" should _not_ have created an EFI entry
88 machine.fail('efibootmgr | grep "Linux Boot Manager"')
89 '';
90 };
91
92 update = makeTest {
93 name = "systemd-boot-update";
94 meta.maintainers = with pkgs.lib.maintainers; [ danielfullmer ];
95
96 machine = common;
97
98 testScript = ''
99 machine.succeed("mount -o remount,rw /boot")
100
101 # Replace version inside sd-boot with something older. See magic[] string in systemd src/boot/efi/boot.c
102 machine.succeed(
103 """
104 find /boot -iname '*.efi' -print0 | \
105 xargs -0 -I '{}' sed -i 's/#### LoaderInfo: systemd-boot .* ####/#### LoaderInfo: systemd-boot 000.0-1-notnixos ####/' '{}'
106 """
107 )
108
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
111 '';
112 };
113}