summary refs log tree commit diff
path: root/nixos/modules/virtualisation/qemu-vm.nix
diff options
context:
space:
mode:
authorDaniel Fullmer <danielrf12@gmail.com>2020-06-14 10:20:21 -0400
committerDaniel Fullmer <danielrf12@gmail.com>2020-07-06 12:09:37 -0700
commit0b4e2167752110ddc03f6ca91872c7e612931f3d (patch)
tree2e14c8ad2d124a16c2e9e7c6f80a79d1c839a159 /nixos/modules/virtualisation/qemu-vm.nix
parentee43e2f1eacfaf9bfc179b4f0f9445fee480928c (diff)
downloadnixpkgs-0b4e2167752110ddc03f6ca91872c7e612931f3d.tar
nixpkgs-0b4e2167752110ddc03f6ca91872c7e612931f3d.tar.gz
nixpkgs-0b4e2167752110ddc03f6ca91872c7e612931f3d.tar.bz2
nixpkgs-0b4e2167752110ddc03f6ca91872c7e612931f3d.tar.lz
nixpkgs-0b4e2167752110ddc03f6ca91872c7e612931f3d.tar.xz
nixpkgs-0b4e2167752110ddc03f6ca91872c7e612931f3d.tar.zst
nixpkgs-0b4e2167752110ddc03f6ca91872c7e612931f3d.zip
qemu-vm: treat EFI vars as state, similarly to diskImage
Diffstat (limited to 'nixos/modules/virtualisation/qemu-vm.nix')
-rw-r--r--nixos/modules/virtualisation/qemu-vm.nix26
1 files changed, 20 insertions, 6 deletions
diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix
index 757952f2029..a927766eabb 100644
--- a/nixos/modules/virtualisation/qemu-vm.nix
+++ b/nixos/modules/virtualisation/qemu-vm.nix
@@ -105,7 +105,7 @@ let
     else if pkgs.stdenv.isAarch64 then "${pkgs.OVMF.fd}/FV/AAVMF"
     else throw "No EFI firmware available for platform";
   efiFirmware = "${efiPrefix}_CODE.fd";
-  efiVars = "${efiPrefix}_VARS.fd";
+  efiVarsDefault = "${efiPrefix}_VARS.fd";
 
   # Shell script to start the VM.
   startVM =
@@ -132,10 +132,14 @@ let
         # A writable boot disk can be booted from automatically.
         ${qemu}/bin/qemu-img create -f qcow2 -b ${bootDisk}/disk.img $TMPDIR/disk.img || exit 1
 
+        NIX_EFI_VARS=$(readlink -f ''${NIX_EFI_VARS:-${cfg.efiVars}})
+
         ${if cfg.useEFIBoot then ''
           # VM needs writable EFI vars
-          cp ${bootDisk}/EFI_VARS.fd $TMPDIR || exit 1
-          chmod 0644 $TMPDIR/EFI_VARS.fd || exit 1
+          if ! test -e "$NIX_EFI_VARS"; then
+            cp ${bootDisk}/efi-vars.fd "$NIX_EFI_VARS" || exit 1
+            chmod 0644 "$NIX_EFI_VARS" || exit 1
+          fi
         '' else ''
         ''}
       '' else ''
@@ -182,8 +186,8 @@ let
               diskImage=$out/disk.img
               ${qemu}/bin/qemu-img create -f qcow2 $diskImage "60M"
               ${if cfg.useEFIBoot then ''
-                efiVars=$out/EFI_VARS.fd
-                cp ${efiVars} $efiVars
+                efiVars=$out/efi-vars.fd
+                cp ${efiVarsDefault} $efiVars
                 chmod 0644 $efiVars
               '' else ''
               ''}
@@ -480,6 +484,16 @@ in
           '';
       };
 
+    virtualisation.efiVars =
+      mkOption {
+        default = "./${vmName}-efi-vars.fd";
+        description =
+          ''
+            Path to nvram image containing UEFI variables.  The will be created
+            on startup if it does not exist.
+          '';
+      };
+
     virtualisation.bios =
       mkOption {
         default = null;
@@ -570,7 +584,7 @@ in
       ])
       (mkIf cfg.useEFIBoot [
         "-drive if=pflash,format=raw,unit=0,readonly,file=${efiFirmware}"
-        "-drive if=pflash,format=raw,unit=1,file=$TMPDIR/EFI_VARS.fd"
+        "-drive if=pflash,format=raw,unit=1,file=$NIX_EFI_VARS"
       ])
       (mkIf (cfg.bios != null) [
         "-bios ${cfg.bios}/bios.bin"