diff --git a/modules/system/boot/loader/efi-boot-stub/efi-boot-stub-builder.sh b/modules/system/boot/loader/efi-boot-stub/efi-boot-stub-builder.sh index 3c55363a44d3..2f550c98428b 100644 --- a/modules/system/boot/loader/efi-boot-stub/efi-boot-stub-builder.sh +++ b/modules/system/boot/loader/efi-boot-stub/efi-boot-stub-builder.sh @@ -122,3 +122,10 @@ for fn in "@efiSysMountPoint@/efi/nixos/"*; do rm -vf -- "$fn" fi done + +# Run any extra commands users may need +if test -n "@runEfibootmgr@"; then + set +e + @postEfiBootMgrCommands@ + set -e +fi diff --git a/modules/system/boot/loader/efi-boot-stub/efi-boot-stub.nix b/modules/system/boot/loader/efi-boot-stub/efi-boot-stub.nix index 2b35aadc623d..618c8d7737af 100644 --- a/modules/system/boot/loader/efi-boot-stub/efi-boot-stub.nix +++ b/modules/system/boot/loader/efi-boot-stub/efi-boot-stub.nix @@ -8,7 +8,7 @@ let isExecutable = true; inherit (pkgs) bash; path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep pkgs.glibc] ++ (pkgs.stdenv.lib.optionals config.boot.loader.efiBootStub.runEfibootmgr [pkgs.efibootmgr pkgs.module_init_tools]); - inherit (config.boot.loader.efiBootStub) efiSysMountPoint runEfibootmgr installStartupNsh efiDisk efiPartition; + inherit (config.boot.loader.efiBootStub) efiSysMountPoint runEfibootmgr installStartupNsh efiDisk efiPartition postEfiBootMgrCommands; efiShell = if config.boot.loader.efiBootStub.installShell then if pkgs.stdenv.isi686 then @@ -103,6 +103,17 @@ in ''; }; + postEfiBootMgrCommands = mkOption { + default = ""; + type = types.string; + description = '' + Shell commands to be executed immediately after efibootmgr has setup the system EFI. + Some systems do not follow the EFI specifications properly and insert extra entries. + Others will brick (fix by removing battery) on boot when it finds more than X entries. + This hook allows for running a few extra efibootmgr commands to combat these issues. + ''; + }; + }; }; };