nixos/tests/installer: inline + fix UEFI start command generation

This commit is contained in:
K900 2024-02-26 11:32:32 +03:00
parent 61cb46e6bf
commit 786f391922

View file

@ -83,46 +83,34 @@ let
, postInstallCommands, preBootCommands, postBootCommands, extraConfig
, testSpecialisationConfig, testFlakeSwitch, clevisTest, clevisFallbackTest
}:
let iface = "virtio";
isEfi = bootLoader == "systemd-boot" || (bootLoader == "grub" && grubUseEfi);
bios = if pkgs.stdenv.isAarch64 then "QEMU_EFI.fd" else "OVMF.fd";
let
qemu-common = import ../lib/qemu-common.nix { inherit (pkgs) lib pkgs; };
isEfi = bootLoader == "systemd-boot" || (bootLoader == "grub" && grubUseEfi);
qemu = qemu-common.qemuBinary pkgs.qemu_test;
in if !isEfi && !pkgs.stdenv.hostPlatform.isx86 then ''
machine.succeed("true")
'' else ''
import subprocess
tpm_folder = os.environ['NIX_BUILD_TOP']
def assemble_qemu_flags():
flags = "-cpu max"
${if (system == "x86_64-linux" || system == "i686-linux")
then ''flags += " -m 1024"''
else ''flags += " -m 768 -enable-kvm -machine virt,gic-version=host"''
}
${optionalString clevisTest ''flags += f" -chardev socket,id=chrtpm,path={tpm_folder}/swtpm-sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis,tpmdev=tpm0"''}
${optionalString clevisTest ''flags += " -device virtio-net-pci,netdev=vlan1,mac=52:54:00:12:11:02 -netdev vde,id=vlan1,sock=\"$QEMU_VDE_SOCKET_1\""''}
return flags
qemu_flags = {"qemuFlags": assemble_qemu_flags()}
import os
import subprocess
tpm_folder = os.environ['NIX_BUILD_TOP']
startcommand = "${qemu} -m 2048"
${optionalString clevisTest ''
startcommand += f" -chardev socket,id=chrtpm,path={tpm_folder}/swtpm-sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis,tpmdev=tpm0"
startcommand += " -device virtio-net-pci,netdev=vlan1,mac=52:54:00:12:11:02 -netdev vde,id=vlan1,sock=\"$QEMU_VDE_SOCKET_1\""
''}
${optionalString isEfi ''
startcommand +=" -drive if=pflash,format=raw,unit=0,readonly=on,file=${pkgs.OVMF.firmware} -drive if=pflash,format=raw,unit=1,readonly=on,file=${pkgs.OVMF.variables}"
''}
image_dir = machine.state_dir
disk_image = os.path.join(image_dir, "machine.qcow2")
hd_flags = {
"hdaInterface": "${iface}",
"hda": disk_image,
}
${optionalString isEfi ''
hd_flags.update(
bios="${pkgs.OVMF.fd}/FV/${bios}"
)''
}
default_flags = {**hd_flags, **qemu_flags}
startcommand += f" -drive file={disk_image},if=virtio,werror=report"
def create_machine_named(name):
return create_machine({**default_flags, "name": name})
return create_machine({"startCommand": startcommand, "name": name})
class Tpm:
def __init__(self):
@ -471,7 +459,7 @@ let
# builds stuff in the VM, needs more juice
virtualisation.diskSize = 8 * 1024;
virtualisation.cores = 8;
virtualisation.memorySize = 1536;
virtualisation.memorySize = 2048;
boot.initrd.systemd.enable = systemdStage1;