Skip to content

Commit 3784aa6

Browse files
Set qemu gui backend to cocoa on darwin (#418)
* Set qemu gui backend to cocoa on darwin * Add defaultText for microvm.graphics.backend option Co-authored-by: Sandro <[email protected]> --------- Co-authored-by: Sandro <[email protected]>
1 parent 42628f7 commit 3784aa6

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

lib/runners/qemu.nix

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,23 @@ lib.warnIf (mem == 2048) ''
218218
"-drive" "id=store,format=raw,read-only=on,file=${storeDisk},if=none,aio=${aioEngine}"
219219
"-device" "virtio-blk-${devType},drive=store${lib.optionalString (devType == "pci") ",disable-legacy=on"}"
220220
] ++
221-
(if graphics.enable
222-
then [
223-
"-display" "gtk,gl=on"
224-
"-device" "virtio-vga-gl"
225-
"-device" "qemu-xhci"
226-
"-device" "usb-tablet"
227-
"-device" "usb-kbd"
228-
]
229-
else [
230-
"-nographic"
231-
]) ++
221+
(if graphics.enable then (
222+
let
223+
displayArgs = {
224+
cocoa = [
225+
"-display" "cocoa" "-device" "virtio-gpu"
226+
];
227+
gtk = [
228+
"-display" "gtk,gl=on" "-device" "virtio-vga-gl"
229+
];
230+
}.${graphics.backend};
231+
in
232+
displayArgs ++ [
233+
"-device" "qemu-xhci"
234+
"-device" "usb-tablet"
235+
"-device" "usb-kbd"
236+
]
237+
) else [ "-nographic" ]) ++
232238
lib.optionals canSandbox [
233239
"-sandbox" "on"
234240
] ++

nixos-modules/microvm/options.nix

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -475,21 +475,31 @@ in
475475
'';
476476
};
477477

478-
graphics.enable = mkOption {
479-
type = types.bool;
480-
default = false;
481-
description = ''
482-
Enable GUI support.
483-
484-
MicroVMs with graphics are intended for the interactive
485-
use-case. They cannot be started through systemd jobs.
486-
487-
Support in Hypervisors:
488-
- `qemu` starts a Gtk window with the framebuffer of the virtio-gpu
489-
'';
490-
};
491-
492-
graphics.socket = mkOption {
478+
graphics.enable = mkOption {
479+
type = types.bool;
480+
default = false;
481+
description = ''
482+
Enable GUI support.
483+
484+
MicroVMs with graphics are intended for the interactive
485+
use-case. They cannot be started through systemd jobs.
486+
487+
The display backend is chosen by `microvm.graphics.backend`.
488+
'';
489+
};
490+
491+
graphics.backend = mkOption {
492+
type = types.enum [ "gtk" "cocoa" ];
493+
default = if pkgs.stdenv.hostPlatform.isDarwin then "cocoa" else "gtk";
494+
defaultText = lib.literalExpression ``if pkgs.stdenv.hostPlatform.isDarwin then "cocoa" else "gtk"``;
495+
description = ''
496+
QEMU display backend to use when `graphics.enable` is true.
497+
498+
Defaults to `cocoa` on Darwin hosts and `gtk` otherwise.
499+
'';
500+
};
501+
502+
graphics.socket = mkOption {
493503
type = types.str;
494504
default = "${hostName}-gpu.sock";
495505
description = ''

0 commit comments

Comments
 (0)