Skip to content

Commit

Permalink
qemu: add option microvm.qemu.machineOpts
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Mar 29, 2024
1 parent 6533956 commit 1b7c70b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
47 changes: 28 additions & 19 deletions lib/runners/qemu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ let

accel =
if microvmConfig.cpu == null
then "accel=kvm:tcg"
else "accel=tcg";
then "kvm:tcg"
else "tcg";

# PCI required by vfio-pci for PCI passthrough
pciInDevices = lib.any ({ bus, ... }: bus == "pci") devices;
Expand All @@ -75,23 +75,32 @@ let
shares != [] ||
pciInDevices;

machineConfig = builtins.concatStringsSep "," {
x86_64-linux = [
machine
accel
"mem-merge=on"
"acpi=on"
] ++ lib.optionals (machine == "microvm") [
"pit=off"
"pic=off"
"pcie=${if requirePci then "on" else "off"}"
"usb=${if requireUsb then "on" else "off"}"
];
aarch64-linux = [
"virt"
"gic-version=max,${accel}"
];
}.${system};
machineOpts =
if microvmConfig.qemu.machineOpts != null
then microvmConfig.qemu.machineOpts
else {
x86_64-linux = {
inherit accel;
mem-merge = "on";
acpi = "on";
} // lib.optionalAttrs (machine == "microvm") {
pit = "off";
pic = "off";
pcie = if requirePci then "on" else "off";
usb = if requireUsb then "on" else "off";
};
aarch64-linux = {
inherit accel;
gic-version = "max";
};
}.${system};

machineConfig = builtins.concatStringsSep "," (
[ machine ] ++
map (name:
"${name}=${machineOpts.${name}}"
) (builtins.attrNames machineOpts)
);

devType =
if requirePci
Expand Down
6 changes: 6 additions & 0 deletions nixos-modules/microvm/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ in
'';
};

qemu.machineOpts = mkOption {
type = with types; nullOr (attrsOf str);
default = null;
description = "Overwrite the default machine model options.";
};

qemu.extraArgs = mkOption {
type = with types; listOf str;
default = [];
Expand Down

0 comments on commit 1b7c70b

Please sign in to comment.