···450450451451 # Include second initrd with secrets
452452 if (-e -x "$path/append-initrd-secrets") {
453453- my $initrdName = basename($initrd);
454454- my $initrdSecretsPath = "$bootPath/kernels/$initrdName-secrets";
453453+ # Name the initrd secrets after the system from which they're derived.
454454+ my $systemName = basename(Cwd::abs_path("$path"));
455455+ my $initrdSecretsPath = "$bootPath/kernels/$systemName-secrets";
455456456457 mkpath(dirname($initrdSecretsPath), 0, 0755);
457458 my $oldUmask = umask;
···470471 if (-e $initrdSecretsPathTemp && ! -z _) {
471472 rename $initrdSecretsPathTemp, $initrdSecretsPath or die "failed to move initrd secrets into place: $!\n";
472473 $copied{$initrdSecretsPath} = 1;
473473- $initrd .= " " . ($grubBoot->path eq "/" ? "" : $grubBoot->path) . "/kernels/$initrdName-secrets";
474474+ $initrd .= " " . ($grubBoot->path eq "/" ? "" : $grubBoot->path) . "/kernels/$systemName-secrets";
474475 } else {
475476 unlink $initrdSecretsPathTemp;
476477 rmdir dirname($initrdSecretsPathTemp);
+18-3
nixos/modules/virtualisation/qemu-vm.nix
···152152153153 ${lib.optionalString cfg.useBootLoader
154154 ''
155155- # Create a writable copy/snapshot of the boot disk.
156156- # A writable boot disk can be booted from automatically.
157157- ${qemu}/bin/qemu-img create -f qcow2 -F qcow2 -b ${bootDisk}/disk.img "$TMPDIR/disk.img"
155155+ if ${if !cfg.persistBootDevice then "true" else "! test -e $TMPDIR/disk.img"}; then
156156+ # Create a writable copy/snapshot of the boot disk.
157157+ # A writable boot disk can be booted from automatically.
158158+ ${qemu}/bin/qemu-img create -f qcow2 -F qcow2 -b ${bootDisk}/disk.img "$TMPDIR/disk.img"
159159+ fi
158160159161 NIX_EFI_VARS=$(readlink -f "''${NIX_EFI_VARS:-${cfg.efiVars}}")
160162···368370 lib.mdDoc ''
369371 The disk to be used for the root filesystem.
370372 '';
373373+ };
374374+375375+ virtualisation.persistBootDevice =
376376+ mkOption {
377377+ type = types.bool;
378378+ default = false;
379379+ description =
380380+ lib.mdDoc ''
381381+ If useBootLoader is specified, whether to recreate the boot device
382382+ on each instantiaton or allow it to persist.
383383+ '';
371384 };
372385373386 virtualisation.emptyDiskImages =
···853866 # * The disks are attached in `virtualisation.qemu.drives`.
854867 # Their order makes them appear as devices `a`, `b`, etc.
855868 # * `fileSystems."/boot"` is adjusted to be on device `b`.
869869+ # * The disk.img is recreated each time the VM is booted unless
870870+ # virtualisation.persistBootDevice is set.
856871857872 # If `useBootLoader`, GRUB goes to the second disk, see
858873 # note [Disk layout with `useBootLoader`].