Systemd-vmspawn unable to start a VM

Hi!
Since I use NixOS, I started loving systemd a lot and using it extensively. :capital_abcd:

So I wanted to give a try to the new systemd-vmspawn utility, to imperatively run a VM on a NixOS 24.11 desktop.

I first imported a debian :shell: image:

sudo importctl pull-raw -m --verify=no https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-nocloud-amd64.raw debian-12

Then I tried to start a VM:

sudo systemd-vmspawn -i /var/lib/machines/debian-12.raw

But got the following error: :x:

Failed to find OVMF config: No such file or directory

I found nothing online :spider_web: about using systemd-vmspawn on NixOS.

I think ideally there should be a NixOS option like virtualisation.systemd-vmspawn.enable to configure what’s necessary for systemd-vmspawn to work out of the box. :pray:

I’d be happy to open a PR for that, but I don’t know what’s wrong! I don’t know much about the low-level side of virtual machines. :gear:

Brain log: :brain:

  • The error seems to occur here in systemd-nspawn. :eyes:
  • I saw that this option exists: virtualisation.efi.OVMF to change the OVMF package, but no option to actually import this package or something.
  • I suspect that some firmware or virtualisation backend like QEMU is missing.
  • There is no optional QEMU dependency in the systemd package.
  • sudo systemd-vmspawn --firmware=list shows nothing, which should indicate that it doesn’t find any EFI firmware.
  • No difference when running the same command in a nix-shell -p qemu shell.
  • No difference when activating virtualisation.libvirtd enabled (it’s dumb but I had to try)

Side note:
systemd-firstboot is not available in NixOS and I have no idea why. Surely because no one tried to start systemd-vmspawn so no one needed it.

That’s because it’s relatively new and we haven’t written any code to implement it yet.

That is for something completely unrelated; the nixos-rebuild build-vm style VMs.

What does that have to do with systemd-vmspawn? But yes, we haven’t fully fleshed out the firstboot functionality in systemd yet either.

1 Like

Of course, I completely understand!

I guess it can be used to preconfigure the local machine, in which case it’s surely not very useful on NixOS.

But its use is documented when starting VMs for the first time.
So it’s somewhat related to the whole machinectl / importctl / systemd-nspawn / systemd-vmspawn ecosystem :slight_smile:
Its use on the host, targeting guests, make it useful to have when using NixOS as a systemd hypervisor or container manager, in my opinion.
Anyway debian images have a nocloud variant which have a passwordless root user, so the workaround of not having systemd-firstboot was easy in my usecase.