Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions lib/runners/qemu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,23 @@ lib.warnIf (mem == 2048) ''
"-drive" "id=store,format=raw,read-only=on,file=${storeDisk},if=none,aio=${aioEngine}"
"-device" "virtio-blk-${devType},drive=store${lib.optionalString (devType == "pci") ",disable-legacy=on"}"
] ++
(if graphics.enable
then [
"-display" "gtk,gl=on"
"-device" "virtio-vga-gl"
"-device" "qemu-xhci"
"-device" "usb-tablet"
"-device" "usb-kbd"
]
else [
"-nographic"
]) ++
(if graphics.enable then (
let
displayArgs = {
cocoa = [
"-display" "cocoa" "-device" "virtio-gpu"
];
gtk = [
"-display" "gtk,gl=on" "-device" "virtio-vga-gl"
];
}.${graphics.backend};
in
displayArgs ++ [
"-device" "qemu-xhci"
"-device" "usb-tablet"
"-device" "usb-kbd"
]
) else [ "-nographic" ]) ++
lib.optionals canSandbox [
"-sandbox" "on"
] ++
Expand Down
40 changes: 25 additions & 15 deletions nixos-modules/microvm/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -475,21 +475,31 @@ in
'';
};

graphics.enable = mkOption {
type = types.bool;
default = false;
description = ''
Enable GUI support.

MicroVMs with graphics are intended for the interactive
use-case. They cannot be started through systemd jobs.

Support in Hypervisors:
- `qemu` starts a Gtk window with the framebuffer of the virtio-gpu
'';
};

graphics.socket = mkOption {
graphics.enable = mkOption {
type = types.bool;
default = false;
description = ''
Enable GUI support.

MicroVMs with graphics are intended for the interactive
use-case. They cannot be started through systemd jobs.

The display backend is chosen by `microvm.graphics.backend`.
'';
};

graphics.backend = mkOption {
type = types.enum [ "gtk" "cocoa" ];
default = if pkgs.stdenv.hostPlatform.isDarwin then "cocoa" else "gtk";
defaultText = lib.literalExpression ``if pkgs.stdenv.hostPlatform.isDarwin then "cocoa" else "gtk"``;
description = ''
QEMU display backend to use when `graphics.enable` is true.

Defaults to `cocoa` on Darwin hosts and `gtk` otherwise.
'';
};

graphics.socket = mkOption {
type = types.str;
default = "${hostName}-gpu.sock";
description = ''
Expand Down
Loading