Performant graphical VM via qemu

I started tinkering with the idea of replacing the macOS terminal with nixOS in a VM, similar to what Mitchell Hashimoto does: Dev Tool Time with Mitchell Hashimoto - YouTube

Also started playing with the reverse idea: run nixOS+sway on the Lenovo X1 as the main desktop, and run all the graphical stuff (email, calendar, contacts, etc) in a graphical linux VM.

In both scenarios, I’m running into shared folders + graphical (performance bad, resolution) problems.
I love the idea of having the whole linux config in the flake.nix and building the vm with nixos-rebuild.
Where the fun stops is actually using the VM.

  1. Is there an undocumented, known set of config options that runs a near-native GUI linux guest under nixos?
  2. Is there the same for macOS? I’m not sure if the same virtualisation drivers are useful under aarm64 and x86_64 / Intel
  3. Is there a mount point that has to be defined in configuration.nix in order for qemu guest to share the whole home dir with the host? I do have services.qemuGuest and services.spice-vdagentd enabled, but don’t see the shared folder anywhere.

I’m aware this can be achieved with VMWare Fusion and Parallels, not sure about Virtualbox, but would like to stay with qemu and nixos-rebuild workflow if possible.

TIA

In my experience, for reasonable graphics performance in a VM, you need to do gpu-passthrough. It might work better with a newer hardware (especially with gpu virtualization built-in in newer intel gpus).

As for 3), I think you can configure it with virtualisation.sharedDirectories (github) option. IIRC, you need to do manual mount later inside the VM (test with mount -t 9p trans=virtio,rw my-share /mnt/point and it should be possible to configure fileSystems."/home" configuration to mount my-share later).

Personally, I’m using NixOS containers for a similar use-case. I’ve described this approach (and my experience with several other) here. You might want to take a look, but I’m not sure if it will fit your workflow.

While QEMU will probably support mounting directories with a macOS host starting with 7.0 (due out in a few months – see https://github.com/NixOS/nixpkgs/pull/122420 for the extended process to get to that point), https://github.com/NixOS/nixpkgs/pull/162243 is a PR that backports that functionality back to 6.2.

Hosted by Flying Circus.