These things are not bad, I really enjoy them but now I wanted to create a non-NixOS virtual machine and wanted to avoid systemd-nspawn, was thinking about QEMU (KVM) but it’s not a strict requirement.
Isnt’t there a NixOS module that let you declare QEMU virtual machines as the containers module (i.e. systemd unit files) and gives you a convenient CLI to imperatively interact with them?
I looked for it in nixpkgs without luck. Probably if I can’t find a better solution I’ll end up writing a systemd unit that executes my virtual machine but a well refined more general module that behaves like containers in nixpkgs would be great in my opinion.
Just to clarify, you want a VM with e.g. Debian in it, but build it from a Nix derivation and manage it via systemd on NixOS?
Wait, build what with a derivation? If you mean building the vm image then no (how?). I mean a NixOS module that, given something like:
generic-containers = {
foo = {
memory = "2G";
cpu = 2;
disks = {
bar = "/var/lib/foo/bar.qcow2";
};
cdrom = "debian-live.iso"; # you will be able to delete this line after you installed it
# ...
};
};
Creates a systemd service that “composes” the needed args for qemu. So, if there is a derivation involved, it’s the derivation used to build the unit file, but you wouldn’t explicitly write it.
It would be also interesting having a simple CLI util to stop/restart/list these containers, like nixos-container.
I’ve heard ideas of something like a libvirt module that would effectively be this, akin to the terraform module out there for libvirt.
That being said, without restricting what types of VMs are supported (like to Linux or Unix) post-provisioning VM interactions are difficult as console support for operating systems varies wildly. As I understand it, QubesOS has to do a decent amount to its templates to get the cross-vm capabilities on top of the Xen hypervisor. It’s definitely possible, but I’m not too sure it’d be worth the effort …
Maybe something more aligned would be “micro-vms” ? I’ve heard of some efforts like SpectrumOS out there in that vein