How to run VMs on NixOS?

I am running a headless NixOS server and would like to know what’s the easiest/“best” way to run VMs on such a system. So far I’ve found close to nothing, and the guides I find seem to focus on non-headless NixOS installations, as trying to run VMs on my box yield DISPLAY is not set errors and similar.

  • Thanks!
1 Like

For VMs that are running NixOS themselves, I’m a fan of MicroVMs which I run on my home-server.

1 Like

Incus and LXD are both in nixpkgs, and while they originally focused on running containers, they have reasonably mature VM support now too. There’s a web front-end at least for Incus (probably LXD too) which allows you to do most things, access consoles, etc. Some of the most sophisticated qemu functionality might not be there, but all the basics are.

Otherwise, libvirt is also in nixpkgs, and you can connect to that remotely from another box using virsh or virt-manager. There’s also NixVirt if you want to fully declaratively define libvirt VMs using nix format rather than than libvirt’s native XML.

I’ve finally migrated my main homelab server (a fairly low-spec nuc) to NixOS and at the moment I’m doing a mix of incus and libvirt (I’ll probably fully migrate to the latter eventually due to a few missing features in incus.)

2 Likes

Oh, I should have mentioned Proxmox-NixOS as well! I haven’t found an excuse to try it yet but it looks very promising - presumably it would be of particular benefit for anyone with previous proxmox experience.

1 Like

@polygon Thanks! I guess I can make the images as small as I want, without the extra bloat, so I’m definitely going to try this out :smiley:

@srd424 Thanks for the input - I didn’t know but, apparently, libvirt has a Wiki entry. I’m giving it a go as we speak!

1 Like