Skip to content

Commit

Permalink
nixos/systemd-boot: add edk2-uefi-shell boot option
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iFreilicht committed Oct 11, 2024
1 parent 5482065 commit f2e5b04
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
37 changes: 37 additions & 0 deletions nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ let
$out
'';

edk2ShellEspPath = "efi/edk2-uefi-shell/shell.efi";

systemdBootBuilder = pkgs.substituteAll rec {
name = "systemd-boot";

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = { };
Expand Down Expand Up @@ -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 [
Expand All @@ -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" = {
Expand Down
15 changes: 15 additions & 0 deletions nixos/tests/systemd-boot.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down

0 comments on commit f2e5b04

Please sign in to comment.