Skip to content

Commit 67b66af

Browse files
committed
feat: Add graphics support for vfkit hypervisor
Enables vfkit to use the --gui flag and virtio-gpu devices when microvm.graphics.enable is set to true, matching the behavior of other hypervisors like qemu and cloud-hypervisor. Changes: - Add virtio-gpu, virtio-input keyboard and pointing devices when graphics.enable is true - Add --gui flag to vfkit command line when graphics are enabled - Replace virtio-serial with GUI devices in graphics mode - Update README to document graphics support on macOS with vfkit
1 parent 16acd1f commit 67b66af

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,15 @@ nix run microvm#vm
100100
Check `networkctl status virbr0` for the DHCP leases of the nested
101101
MicroVMs. They listen for ssh with an empty root password.
102102

103-
### Experimental: run graphical applications in cloud-hypervisor with Wayland forwarding
103+
### Experimental: run graphical applications with graphics support
104104

105+
On Linux with cloud-hypervisor and Wayland forwarding:
105106
```shell
106107
nix run microvm#graphics neverball
107108
```
108109

110+
On macOS with vfkit, enable graphics with `microvm.graphics.enable = true`.
111+
109112
## Commercial support
110113

111114
Accelerate your operations and secure your infrastructure with support from a

lib/runners/vfkit.nix

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let
1515
inherit (microvmConfig)
1616
hostName vcpu mem user interfaces volumes shares socket
1717
storeOnDisk kernel initrdPath storeDisk kernelParams
18-
balloon devices credentialFiles vsock;
18+
balloon devices credentialFiles vsock graphics;
1919

2020
inherit (microvmConfig.vfkit) extraArgs logLevel;
2121

@@ -24,7 +24,8 @@ let
2424
# vfkit requires uncompressed kernel
2525
kernelPath = "${kernel.out}/${pkgs.stdenv.hostPlatform.linux-kernel.target}";
2626

27-
kernelCmdLine = "console=hvc0 reboot=t panic=-1 ${toString kernelParams}";
27+
kernelConsole = if graphics.enable then "tty0" else "hvc0";
28+
kernelCmdLine = "console=${kernelConsole} reboot=t panic=-1 ${toString kernelParams}";
2829

2930
bootloaderArgs = [
3031
"--bootloader"
@@ -34,7 +35,13 @@ let
3435
deviceArgs =
3536
[ "--device" "virtio-rng" ]
3637
++
37-
[ "--device" "virtio-serial,stdio" ]
38+
(if graphics.enable then [
39+
"--device" "virtio-gpu"
40+
"--device" "virtio-input,keyboard"
41+
"--device" "virtio-input,pointing"
42+
] else [
43+
"--device" "virtio-serial,stdio"
44+
])
3845
++
3946
(builtins.concatMap ({ image, ... }: [
4047
"--device" "virtio-blk,path=${image}"
@@ -72,6 +79,9 @@ let
7279
++ lib.optionals (logLevel != null) [
7380
"--log-level" logLevel
7481
]
82+
++ lib.optionals graphics.enable [
83+
"--gui"
84+
]
7585
++ bootloaderArgs
7686
++ deviceArgs
7787
++ extraArgs;

0 commit comments

Comments
 (0)