summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Uhl <github@mail.felix-uhl.de>2024-09-25 00:06:59 +0200
committerFelix Uhl <github@mail.felix-uhl.de>2024-10-11 10:53:42 +0200
commitf2e5b04c4e53e7a24a0b432cca50c355f867a505 (patch)
treeee8565473aa9c9c0498758f3a248c37ec21376ad
parentnixos/systemd-boot: autoformat (diff)
downloadnixpkgs-f2e5b04c4e53e7a24a0b432cca50c355f867a505.tar.gz
nixos/systemd-boot: add edk2-uefi-shell boot option
We already have a edk2-uefi-shell package in nixpkgs, but adding it to systemd-boot was somewhat tedious. Now it's a single line of nix.
-rw-r--r--nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix37
-rw-r--r--nixos/tests/systemd-boot.nix15
2 files changed, 52 insertions, 0 deletions
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 ];