at 21.11-pre 2.8 kB view raw
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 # Boot without having created an EFI entry--instead using default "/EFI/BOOT/BOOTX64.EFI" 43 fallback = makeTest { 44 name = "systemd-boot-fallback"; 45 meta.maintainers = with pkgs.lib.maintainers; [ danielfullmer ]; 46 47 machine = { pkgs, lib, ... }: { 48 imports = [ common ]; 49 boot.loader.efi.canTouchEfiVariables = mkForce false; 50 }; 51 52 testScript = '' 53 machine.start() 54 machine.wait_for_unit("multi-user.target") 55 56 machine.succeed("test -e /boot/loader/entries/nixos-generation-1.conf") 57 58 # Ensure we actually booted using systemd-boot 59 # Magic number is the vendor UUID used by systemd-boot. 60 machine.succeed( 61 "test -e /sys/firmware/efi/efivars/LoaderEntrySelected-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f" 62 ) 63 64 # "bootctl install" should _not_ have created an EFI entry 65 machine.fail('efibootmgr | grep "Linux Boot Manager"') 66 ''; 67 }; 68 69 update = makeTest { 70 name = "systemd-boot-update"; 71 meta.maintainers = with pkgs.lib.maintainers; [ danielfullmer ]; 72 73 machine = common; 74 75 testScript = '' 76 machine.succeed("mount -o remount,rw /boot") 77 78 # Replace version inside sd-boot with something older. See magic[] string in systemd src/boot/efi/boot.c 79 machine.succeed( 80 """ 81 find /boot -iname '*.efi' -print0 | \ 82 xargs -0 -I '{}' sed -i 's/#### LoaderInfo: systemd-boot .* ####/#### LoaderInfo: systemd-boot 001 ####/' '{}' 83 """ 84 ) 85 86 output = machine.succeed("/run/current-system/bin/switch-to-configuration boot") 87 assert "updating systemd-boot from 001 to " in output 88 ''; 89 }; 90}