mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-12 12:45:27 +03:00
ovmf: expose EFI prefixes and refactor qemu-vm with it
This commit is contained in:
parent
ce907408b8
commit
c91d0713ac
3 changed files with 49 additions and 13 deletions
|
@ -98,12 +98,6 @@ let
|
|||
addDeviceNames =
|
||||
imap1 (idx: drive: drive // { device = driveDeviceName idx; });
|
||||
|
||||
efiPrefix =
|
||||
if pkgs.stdenv.hostPlatform.isx86 then "${pkgs.OVMF.fd}/FV/OVMF"
|
||||
else if pkgs.stdenv.isAarch64 then "${pkgs.OVMF.fd}/FV/AAVMF"
|
||||
else throw "No EFI firmware available for platform";
|
||||
efiFirmware = "${efiPrefix}_CODE.fd";
|
||||
efiVarsDefault = "${efiPrefix}_VARS.fd";
|
||||
|
||||
# Shell script to start the VM.
|
||||
startVM =
|
||||
|
@ -218,14 +212,14 @@ let
|
|||
${qemu}/bin/qemu-img create -f qcow2 $diskImage "60M"
|
||||
${if cfg.useEFIBoot then ''
|
||||
efiVars=$out/efi-vars.fd
|
||||
cp ${efiVarsDefault} $efiVars
|
||||
cp ${cfg.efi.variables} $efiVars
|
||||
chmod 0644 $efiVars
|
||||
'' else ""}
|
||||
'';
|
||||
buildInputs = [ pkgs.util-linux ];
|
||||
QEMU_OPTS = "-nographic -serial stdio -monitor none"
|
||||
+ lib.optionalString cfg.useEFIBoot (
|
||||
" -drive if=pflash,format=raw,unit=0,readonly=on,file=${efiFirmware}"
|
||||
" -drive if=pflash,format=raw,unit=0,readonly=on,file=${cfg.efi.firmware}"
|
||||
+ " -drive if=pflash,format=raw,unit=1,file=$efiVars");
|
||||
}
|
||||
''
|
||||
|
@ -705,8 +699,31 @@ in
|
|||
manager.
|
||||
useEFIBoot is ignored if useBootLoader == false.
|
||||
'';
|
||||
};
|
||||
|
||||
virtualisation.efi = {
|
||||
firmware = mkOption {
|
||||
type = types.path;
|
||||
default = pkgs.OVMF.firmware;
|
||||
defaultText = "pkgs.OVMF.firmware";
|
||||
description =
|
||||
lib.mdDoc ''
|
||||
Firmware binary for EFI implementation, defaults to OVMF.
|
||||
'';
|
||||
};
|
||||
|
||||
variables = mkOption {
|
||||
type = types.path;
|
||||
default = pkgs.OVMF.variables;
|
||||
defaultText = "pkgs.OVMF.variables";
|
||||
description =
|
||||
lib.mdDoc ''
|
||||
Platform-specific flash binary for EFI variables, implementation-dependent to the EFI firmware.
|
||||
Defaults to OVMF.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
virtualisation.useDefaultFilesystems =
|
||||
mkOption {
|
||||
type = types.bool;
|
||||
|
@ -928,7 +945,7 @@ in
|
|||
''-append "$(cat ${config.system.build.toplevel}/kernel-params) init=${config.system.build.toplevel}/init regInfo=${regInfo}/registration ${consoles} $QEMU_KERNEL_PARAMS"''
|
||||
])
|
||||
(mkIf cfg.useEFIBoot [
|
||||
"-drive if=pflash,format=raw,unit=0,readonly=on,file=${efiFirmware}"
|
||||
"-drive if=pflash,format=raw,unit=0,readonly=on,file=${cfg.efi.firmware}"
|
||||
"-drive if=pflash,format=raw,unit=1,file=$NIX_EFI_VARS"
|
||||
])
|
||||
(mkIf (cfg.bios != null) [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue