Unverified Commit d406be44 authored by Maximilian Bosch's avatar Maximilian Bosch
Browse files

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.
parent 28a45037
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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));