Closed Luflosi closed 6 months ago
Maybe we can do it on VNC connection via TCP 5900 instead, like how CUPS does it. So the VM will only boot when TCP connections come in, or SSH on TCP 2222 https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/services/printing/cupsd.nix#L155-L163
That would be awesome but I don't think it's currently possible.
Socket activation works by making systemd listen on some socket and when it detects an incoming connection, systemd starts the corresponding service and passes the opened file descriptor to it. But QEMU does not seem to support using socket activation for VNC or hostfwd. I found -add-fd fd=fd,set=set[,opaque=opaque]
which seemed promising but in the end I didn't manage to get anything working as I don't know how to pass something like /dev/fdset/2
to the vnc option. See https://github.com/Luflosi/NixThePlanet/commit/163709071f2fe3c0b073dfb38eb0aaaf67143341 for my latest attempt.
On my laptop I want to just start the VM when I need it to conserve battery.