Skip to content

Commit e21c05a

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 ebe491e commit e21c05a

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
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: 18 additions & 7 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,19 +24,27 @@ 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+
29+
kernelCmdLine = [ "console=${kernelConsole}" "reboot=t" "panic=-1" ] ++ kernelParams;
2830

2931
bootloaderArgs = [
3032
"--bootloader"
3133
"linux,kernel=${kernelPath},initrd=${initrdPath},cmdline=\"${builtins.concatStringsSep " " kernelCmdLine}\""
3234
];
3335

3436
deviceArgs =
35-
[ "--device" "virtio-rng" ]
36-
++
37-
[ "--device" "virtio-serial,stdio" ]
38-
++
39-
(builtins.concatMap ({ image, ... }: [
37+
[
38+
"--device" "virtio-rng"
39+
]
40+
++ (if graphics.enable then [
41+
"--device" "virtio-gpu"
42+
"--device" "virtio-input,keyboard"
43+
"--device" "virtio-input,pointing"
44+
] else [
45+
"--device" "virtio-serial,stdio"
46+
])
47+
++ (builtins.concatMap ({ image, ... }: [
4048
"--device" "virtio-blk,path=${image}"
4149
]) volumesWithLetters)
4250
++ (builtins.concatMap ({ proto, source, tag, ... }:
@@ -64,6 +72,9 @@ let
6472
++ lib.optionals (logLevel != null) [
6573
"--log-level" logLevel
6674
]
75+
++ lib.optionals graphics.enable [
76+
"--gui"
77+
]
6778
++ bootloaderArgs
6879
++ deviceArgs
6980
++ extraArgs;

0 commit comments

Comments
 (0)