diff --git a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix index cbaddf25f925..f791bc9d7691 100644 --- a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix +++ b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix @@ -29,6 +29,8 @@ let $out ''; + edk2ShellEspPath = "efi/edk2-uefi-shell/shell.efi"; + systemdBootBuilder = pkgs.substituteAll rec { name = "systemd-boot"; @@ -72,6 +74,8 @@ let netbootxyz = optionalString cfg.netbootxyz.enable pkgs.netbootxyz-efi; + edk2-uefi-shell = optionalString cfg.edk2-uefi-shell.enable pkgs.edk2-uefi-shell; + checkMountpoints = pkgs.writeShellScript "check-mountpoints" '' fail() { echo "$1 = '$2' is not a mounted partition. Is the path configured correctly?" >&2 @@ -343,6 +347,29 @@ in }; }; + edk2-uefi-shell = { + enable = mkOption { + type = types.bool; + default = false; + description = '' + Make the EDK2 UEFI Shell available from the systemd-boot menu. + It can be used to manually boot other operating systems or for debugging. + ''; + }; + + sortKey = mkOption { + type = types.str; + default = "o_edk2-uefi-shell"; + description = '' + `systemd-boot` orders the menu entries by their sort keys, + so if you want something to appear after all the NixOS entries, + it should start with {file}`o` or onwards. + + See also {option}`boot.loader.systemd-boot.sortKey`.. + ''; + }; + }; + extraEntries = mkOption { type = types.attrsOf types.lines; default = { }; @@ -476,6 +503,9 @@ in (mkIf cfg.netbootxyz.enable { "efi/netbootxyz/netboot.xyz.efi" = "${pkgs.netbootxyz-efi}"; }) + (mkIf cfg.edk2-uefi-shell.enable { + ${edk2ShellEspPath} = "${pkgs.edk2-uefi-shell}/shell.efi"; + }) ]; boot.loader.systemd-boot.extraEntries = mkMerge [ @@ -493,6 +523,13 @@ in sort-key ${cfg.netbootxyz.sortKey} ''; }) + (mkIf cfg.edk2-uefi-shell.enable { + "edk2-uefi-shell.conf" = '' + title EDK2 UEFI Shell + efi /${edk2ShellEspPath} + sort-key ${cfg.edk2-uefi-shell.sortKey} + ''; + }) ]; boot.bootspec.extensions."org.nixos.systemd-boot" = { diff --git a/nixos/tests/systemd-boot.nix b/nixos/tests/systemd-boot.nix index 6b710180b368..d5cd6ae0117f 100644 --- a/nixos/tests/systemd-boot.nix +++ b/nixos/tests/systemd-boot.nix @@ -339,6 +339,21 @@ in ''; }; + edk2-uefi-shell = makeTest { + name = "systemd-boot-edk2-uefi-shell"; + meta.maintainers = with pkgs.lib.maintainers; [ iFreilicht ]; + + nodes.machine = { ... }: { + imports = [ common ]; + boot.loader.systemd-boot.edk2-uefi-shell.enable = true; + }; + + testScript = '' + machine.succeed("test -e /boot/loader/entries/edk2-uefi-shell.conf") + machine.succeed("test -e /boot/efi/edk2-uefi-shell/shell.efi") + ''; + }; + memtestSortKey = makeTest { name = "systemd-boot-memtest-sortkey"; meta.maintainers = with pkgs.lib.maintainers; [ julienmalka ];