diff --git a/disko-install b/disko-install index c703167..b2521b6 100755 --- a/disko-install +++ b/disko-install @@ -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") diff --git a/docs/disko-install.md b/docs/disko-install.md index c997cea..aee22be 100644 --- a/docs/disko-install.md +++ b/docs/disko-install.md @@ -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. diff --git a/install-cli.nix b/install-cli.nix index dec7394..93c0067 100644 --- a/install-cli.nix +++ b/install-cli.nix @@ -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; })]; };