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: https://www.youtube.com/watch?v=LA8KF9Fs2sk

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

1 Like

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.

2 Likes

While QEMU will probably support mounting directories with a macOS host starting with 7.0 (due out in a few months – see qemu: add 9p virtfs support on Darwin by mroi · Pull Request #122420 · NixOS/nixpkgs · GitHub for the extended process to get to that point), qemu: backport 9p-darwin to v6.2.0 by willcohen · Pull Request #162243 · NixOS/nixpkgs · GitHub is a PR that backports that functionality back to 6.2.

Stumbling accross this post, this makes me want to mention https://spectrum-os.org, which makes number improvements over the (graphical) integration between a host and VMs. Even if it’s pretty alpha for now.

1 Like

For those who can’t wait for Spectrum to get end-user-usable, I’ve seen at NixCon 2023 that @jpo jpouellet (Jean-Philippe Ouellet) · GitHub had an impressive Qubes+Nix setup that essentially does what @supermarin describes. Spectrum is essentially a continuation of that idea.

1 Like