Skip to content

Commit 1b7c70b

Browse files
committed
qemu: add option microvm.qemu.machineOpts
1 parent 6533956 commit 1b7c70b

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

lib/runners/qemu.nix

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ let
6464

6565
accel =
6666
if microvmConfig.cpu == null
67-
then "accel=kvm:tcg"
68-
else "accel=tcg";
67+
then "kvm:tcg"
68+
else "tcg";
6969

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

78-
machineConfig = builtins.concatStringsSep "," {
79-
x86_64-linux = [
80-
machine
81-
accel
82-
"mem-merge=on"
83-
"acpi=on"
84-
] ++ lib.optionals (machine == "microvm") [
85-
"pit=off"
86-
"pic=off"
87-
"pcie=${if requirePci then "on" else "off"}"
88-
"usb=${if requireUsb then "on" else "off"}"
89-
];
90-
aarch64-linux = [
91-
"virt"
92-
"gic-version=max,${accel}"
93-
];
94-
}.${system};
78+
machineOpts =
79+
if microvmConfig.qemu.machineOpts != null
80+
then microvmConfig.qemu.machineOpts
81+
else {
82+
x86_64-linux = {
83+
inherit accel;
84+
mem-merge = "on";
85+
acpi = "on";
86+
} // lib.optionalAttrs (machine == "microvm") {
87+
pit = "off";
88+
pic = "off";
89+
pcie = if requirePci then "on" else "off";
90+
usb = if requireUsb then "on" else "off";
91+
};
92+
aarch64-linux = {
93+
inherit accel;
94+
gic-version = "max";
95+
};
96+
}.${system};
97+
98+
machineConfig = builtins.concatStringsSep "," (
99+
[ machine ] ++
100+
map (name:
101+
"${name}=${machineOpts.${name}}"
102+
) (builtins.attrNames machineOpts)
103+
);
95104

96105
devType =
97106
if requirePci

nixos-modules/microvm/options.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,12 @@ in
406406
'';
407407
};
408408

409+
qemu.machineOpts = mkOption {
410+
type = with types; nullOr (attrsOf str);
411+
default = null;
412+
description = "Overwrite the default machine model options.";
413+
};
414+
409415
qemu.extraArgs = mkOption {
410416
type = with types; listOf str;
411417
default = [];

0 commit comments

Comments
 (0)