Miniguest: lightweight and declarative guest operating systems profiles

In hopes of improving my experience with setting up NixOS virtual machines, I found myself designing and implementing a system to declaratively build guest configurations that I could then plug into my libvirt hypervisor. I settled on using direct kernel boot to load the kernel and tweaked initrd, and an additional /boot filesystem to supply the second stage of NixOS, as well as a nix store passthrough. This turned out to work quite well for me even in a very rough draft, and builds upon the features of Nix in a very straightforward way. Despite that, I could not find any similar projects. As is tradition, I decided to share the software in the hope that it would be useful.

Think of it as a mix between nixos-container and nixos-rebuild build-vm

Some quick highlights:

  • Low footprint The guest’s program is stored in the host’s nix store. This allows structural sharing and hard-linking to kick in, so each guest will take up little additional space.

  • Automation No manual steps need to be performed in a VM to install it.

  • Quick deployment We don’t need to copy closures into each VM, the store is shared so it’s already there.

  • Rollbacks of course we have those.

  • Orthogonality The concept doesn’t imply a choice of hypervisor, filesystem layout, or host OS, it can work with a variety of configurations.

  • Harvard architecture The presence of mutable data is explicitly declared and encapsulated separately from the program. Stateless VMs can also be created by omitting writable storage.

EDIT: I realized that fileSystems.<name>.autoFormat is already in 21.05.

9 Likes