Skip to content

Commit

Permalink
qemu: drop q35 in favor of microvm as it now supports pci+usb+acpi
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Dec 18, 2023
1 parent 4189f0d commit b59a269
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
1 change: 1 addition & 0 deletions examples/qemu-vnc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ nixpkgs.lib.nixosSystem {
({ config, lib, pkgs, ... }: {
microvm = {
hypervisor = "qemu";
graphics.enable = true;
interfaces = lib.optional (tapInterface != null) {
type = "tap";
id = tapInterface;
Expand Down
37 changes: 25 additions & 12 deletions lib/runners/qemu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let
});

overrideQemu = x: lib.pipe x (
lib.optional (lib.any ({ bus, ... }: bus == "usb") microvmConfig.devices) enableLibusb
lib.optional requireUsb enableLibusb
++ lib.optional microvmConfig.optimize.enable minimizeQemuClosureSize
);

Expand All @@ -45,6 +45,10 @@ let

volumes = withDriveLetters microvmConfig;

requireUsb =
graphics.enable ||
lib.any ({ bus, ... }: bus == "usb") microvmConfig.devices;

arch = builtins.head (builtins.split "-" system);

cpuArgs = [
Expand All @@ -65,19 +69,30 @@ let
# PCI required by vfio-pci for PCI passthrough
pciInDevices = lib.any ({ bus, ... }: bus == "pci") devices;

requirePci = shares != [] || pciInDevices;
requirePci =
graphics.enable ||
shares != [] ||
pciInDevices;

machine = {
x86_64-linux =
if requirePci
then "q35,${accel},mem-merge=on,sata=off"
else "microvm,${accel},pit=off,pic=off,rtc=off,mem-merge=on";
x86_64-linux = builtins.concatStringsSep "," [
"microvm"
accel
"mem-merge=on"
"pit=off"
"pic=off"
"mem-merge=on"
"acpi=on"
"pcie=${if requirePci then "on" else "off"}"
"usb=${if requireUsb then "on" else "off"}"
];
aarch64-linux = "virt,gic-version=max,${accel}";
}.${system};

devType = if requirePci
then "pci"
else "device";
devType =
if requirePci
then "pci"
else "device";

kernelPath = "${kernel.out}/${pkgs.stdenv.hostPlatform.linux-kernel.target}";

Expand Down Expand Up @@ -227,9 +242,7 @@ in {
]) interfaces
)
++
lib.optionals (lib.any ({ bus, ... }:
bus == "usb"
) devices) [
lib.optionals requireUsb [
"-usb"
"-device" "usb-ehci"
]
Expand Down

0 comments on commit b59a269

Please sign in to comment.