qemu-vm: treat EFI vars as state, similarly to diskImage
This commit is contained in:
parent
ee43e2f1ea
commit
0b4e216775
@ -105,7 +105,7 @@ let
|
|||||||
else if pkgs.stdenv.isAarch64 then "${pkgs.OVMF.fd}/FV/AAVMF"
|
else if pkgs.stdenv.isAarch64 then "${pkgs.OVMF.fd}/FV/AAVMF"
|
||||||
else throw "No EFI firmware available for platform";
|
else throw "No EFI firmware available for platform";
|
||||||
efiFirmware = "${efiPrefix}_CODE.fd";
|
efiFirmware = "${efiPrefix}_CODE.fd";
|
||||||
efiVars = "${efiPrefix}_VARS.fd";
|
efiVarsDefault = "${efiPrefix}_VARS.fd";
|
||||||
|
|
||||||
# Shell script to start the VM.
|
# Shell script to start the VM.
|
||||||
startVM =
|
startVM =
|
||||||
@ -132,10 +132,14 @@ let
|
|||||||
# A writable boot disk can be booted from automatically.
|
# 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
|
${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 ''
|
${if cfg.useEFIBoot then ''
|
||||||
# VM needs writable EFI vars
|
# VM needs writable EFI vars
|
||||||
cp ${bootDisk}/EFI_VARS.fd $TMPDIR || exit 1
|
if ! test -e "$NIX_EFI_VARS"; then
|
||||||
chmod 0644 $TMPDIR/EFI_VARS.fd || exit 1
|
cp ${bootDisk}/efi-vars.fd "$NIX_EFI_VARS" || exit 1
|
||||||
|
chmod 0644 "$NIX_EFI_VARS" || exit 1
|
||||||
|
fi
|
||||||
'' else ''
|
'' else ''
|
||||||
''}
|
''}
|
||||||
'' else ''
|
'' else ''
|
||||||
@ -182,8 +186,8 @@ let
|
|||||||
diskImage=$out/disk.img
|
diskImage=$out/disk.img
|
||||||
${qemu}/bin/qemu-img create -f qcow2 $diskImage "60M"
|
${qemu}/bin/qemu-img create -f qcow2 $diskImage "60M"
|
||||||
${if cfg.useEFIBoot then ''
|
${if cfg.useEFIBoot then ''
|
||||||
efiVars=$out/EFI_VARS.fd
|
efiVars=$out/efi-vars.fd
|
||||||
cp ${efiVars} $efiVars
|
cp ${efiVarsDefault} $efiVars
|
||||||
chmod 0644 $efiVars
|
chmod 0644 $efiVars
|
||||||
'' else ''
|
'' 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 =
|
virtualisation.bios =
|
||||||
mkOption {
|
mkOption {
|
||||||
default = null;
|
default = null;
|
||||||
@ -570,7 +584,7 @@ in
|
|||||||
])
|
])
|
||||||
(mkIf cfg.useEFIBoot [
|
(mkIf cfg.useEFIBoot [
|
||||||
"-drive if=pflash,format=raw,unit=0,readonly,file=${efiFirmware}"
|
"-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) [
|
(mkIf (cfg.bios != null) [
|
||||||
"-bios ${cfg.bios}/bios.bin"
|
"-bios ${cfg.bios}/bios.bin"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user