add efi var install option

This commit is contained in:
Jörg Thalheim 2024-03-05 08:23:33 +01:00 committed by mergify[bot]
parent f61c7d28d5
commit 3704ee3926
3 changed files with 24 additions and 2 deletions

View File

@ -10,6 +10,9 @@ Usage: $0 [OPTIONS]
--show-trace Show the stack trace on error.
-h, --help Show this help message.
--reference-lock-file FILE Use the specified lock file as a reference for the Nix store.
--write-efi-boot-entries Write EFI boot entries to the NVRAM of the system for the installed system.
Specify this option if you plan to boot from this disk on the current machine,
but not if you plan to move the disk to another machine.
EOF
}
@ -34,6 +37,7 @@ nix_args=(
)
dry_run=
diskoAttr=diskoScript
writeEfiBootEntries=false
declare -A diskMappings
parseArgs() {
@ -61,6 +65,9 @@ parseArgs() {
--show-trace)
nix_args+=("$1")
;;
--write-efi-boot-entries)
writeEfiBootEntries=true
;;
--mode)
if [[ $# -lt 2 ]]; then
echo "Option $1 requires an argument" >&2
@ -150,6 +157,7 @@ main() {
--argstr flake "$flake" \
--argstr flakeAttr "$flakeAttr" \
--argstr rootMountPoint "$mountPoint" \
--arg writeEfiBootEntries "$writeEfiBootEntries" \
--arg diskMappings "$(serialiaseArrayToNix diskMappings)" \
-A installToplevel \
-A "$diskoAttr")

View File

@ -111,3 +111,17 @@ or attaching it to a qemu-vm:
```
$ sudo qemu-kvm -enable-kvm -hda /dev/sda
```
### Persisting boot entries to EFI vars flash
Disko-install is designed for NixOS installations on portable storage or disks that may be transferred between computers.
As such, it does not modify the host's NVRAM by default.
To ensure your NixOS installation boots seamlessly on new hardware or to prioritize it in your current machine's boot order,
use the --write-efi-boot-entries option:
```console
$ sudo nix run 'github:nix-community/disko#disko-install' -- --write-efi-boot-entries --flake '/tmp/config/etc/nixos#mymachine' --disk main /dev/sda
```
This command installs NixOS with Disko-install and sets the newly installed system as the default boot option,
without affecting the flexibility to boot from other devices if needed.

View File

@ -1,7 +1,7 @@
{ flake
, flakeAttr
, diskMappings
, canTouchEfiVariables ? false
, writeEfiBootEntries ? false
, rootMountPoint ? "/mnt"
}:
let
@ -32,7 +32,7 @@ let
};
installSystem = originalSystem.extendModules {
modules = [({ lib, ... }: {
boot.loader.efi.canTouchEfiVariables = lib.mkVMOverride canTouchEfiVariables;
boot.loader.efi.canTouchEfiVariables = lib.mkVMOverride writeEfiBootEntries;
boot.loader.grub.devices = lib.mkVMOverride diskoSystem.config.boot.loader.grub.devices;
})];
};