@@ -55,7 +55,7 @@ let
5555 inherit (cfg)
5656 version extraConfig extraPerEntryConfig extraEntries
5757 extraEntriesBeforeNixOS extraPrepareConfig configurationLimit copyKernels
58− default fsIdentifier efiSupport gfxmodeEfi gfxmodeBios;
58+ default fsIdentifier efiSupport efiInstallAsRemovable gfxmodeEfi gfxmodeBios;
5959 path = (makeBinPath ([
6060 pkgs.coreutils pkgs.gnused pkgs.gnugrep pkgs.findutils pkgs.diffutils pkgs.btrfs-progs
6161 pkgs.utillinux ] ++ (if cfg.efiSupport && (cfg.version == 2) then [pkgs.efibootmgr ] else [])
@@ -357,6 +357,44 @@ in
357357 '';
358358 };
359359
360+ efiInstallAsRemovable = mkOption {
361+ default = false;
362+ example = true;
363+ type = types.bool;
364+ description = ''
365+ Whether to invoke <literal>grub-install</literal> with
366+ <literal>--removable</literal>.
367+
368+ Unless turn this on, GRUB will install itself somewhere (exactly
369+ where depends on other config variables) in
370+ <literal>boot.loader.efi.efiSysMountPoint</literal>. If you've set
371+ <literal>boot.loader.efi.canTouchEfiVariables</literal> *AND* you
372+ are currently booted in UEFI mode, then GRUB will use
373+ <literal>efibootmgr</literal> to modify the boot order in the NVRAM's
374+ EFI variables of your computer to include this location. If you are
375+ *not* booted in UEFI mode at the time grub is being installed, the
376+ NVRAM will not be modified, and your system will not find GRUB at
377+ boot time. GRUB will still succeed (althgouh you'll see a warning
378+ printed "<literal>efibootmgr: EFI variables are not supported on
379+ this system.</literal>").
380+
381+ If you do turn this feature on, then GRUB will install itself
382+ in a specific special location within <literal>efiSysMountPoint</literal>
383+ (namely <literal>EFI/boot/boot$arch.efi</literal>) which is the firmwares
384+ are hardcoded to try first, regardless of NVRAM EFI variables.
385+
386+ To summarize, turn this on if:
387+ <itemizedlist>
388+ <listitem>You are installing NixOS and want it to boot in UEFI mode,
389+ but you are currently booted in legacy mode</listitem>
390+ <listitem>You want to make a drive that will boot regardless of
391+ the NVRAM state of the computer (like a USB "removable" drive)</listitem>
392+ <listitem>You simply dislike the idea of depending on some NVRAM
393+ state to make your drive bootable</listitem>
394+ </itemizedlist>
395+ '';
396+ };
397+
360398 enableCryptodisk = mkOption {
361399 default = false;
362400 type = types.bool;
@@ -484,6 +522,14 @@ in
484522 assertion = !cfg.trustedBoot.enable || cfg.trustedBoot.systemHasTPM == "YES_TPM_is_activated";
485523 message = "Trusted GRUB can break the system! Confirm that the system has an activated TPM by setting 'systemHasTPM'.";
486524 }
525+ {
526+ assertion = cfg.efiInstallAsRemovable -> cfg.efiSupport;
527+ message = "If you wish to to use boot.loader.grub.efiInstallAsRemovable, then turn on boot.loader.grub.efiSupport";
528+ }
529+ {
530+ assertion = cfg.efiInstallAsRemovable -> !config.boot.loader.efi.canTouchEfiVariables;
531+ message = "If you wish to to use boot.loader.grub.efiInstallAsRemovable, then turn off boot.loader.efi.canTouchEfiVariables";
532+ }
487533 ] ++ flip concatMap cfg.mirroredBoots (args: [
488534 {
489535 assertion = args.devices != [ ];