nixos/qemu-vm: add enableSharedMemory option

This option configures a memfd backend for the VM's memory with the size
of `virtualisation.memorySize` and uses that as default memory backend.

This is required for e.g. vhost-device-vsock.

The motivation for making this an option is that I decided to enable
this by default for all NixOS tests to avoid changing essential QEMU
options based on whether or not debugging is enabled. However, there
should be an easy way to turn it off which is what this option provides.
This commit is contained in:
Maximilian Bosch
2026-04-15 15:45:33 +01:00
parent 28a450372a
commit d406be44b9
+6
View File
@@ -716,6 +716,8 @@ in
};
virtualisation.qemu = {
enableSharedMemory = mkEnableOption "shared memory";
package = mkOption {
type = types.package;
default =
@@ -1338,6 +1340,10 @@ in
"-device usb-kbd"
"-device usb-tablet"
])
(mkIf cfg.qemu.enableSharedMemory [
"-object memory-backend-memfd,id=mem0,size=${toString config.virtualisation.memorySize}M,share=on"
"-machine memory-backend=mem0"
])
(
let
alphaNumericChars = lowerChars ++ upperChars ++ (map toString (range 0 9));