Libvirtd on Ubuntu with Nix

Hey everyone! I’m new to Nix, and I’m trying to wrap my mind around the right way to tackle this problem. I’m running Ubuntu 18.04 with Nix and home-manager. I installed virt-manager by adding it to my home-manager config, which was great. But now I’m getting an error message when I run virt-manager:

The libvirtd service does not appear to be installed. Install and run the libvirtd service to manage virtualization on this host.
Could not detect a default hypervisor. Make sure the appropriate qemu/kvm virtualization packages are installed to manage virtualization on this host.

Fair enough, I need libvirtd. However, I haven’t been able to find libvirtd in the nix package search. And if such a package does exist in the nix package system, why isn’t it set as a requirement of virt-manager?

I’d like to solve this via my home-manager config. Barring that, I’d like to use Nix independent of home-manager. If all else fails, I can apt-get and use the system default package stuff.

This wiki article is where I’d start if I was not using Nix at all. I’m not really sure how to do this with Nix however. Any and all advice is appreciated!

libvirtd is a system daemon, not something you can run as your user. It is packaged in nixpkgs but configuring and running it is outside the scope of home-manager and Nix. To install it you should follow instructions specific for ubuntu, like the one you mentioned or this.

If you are interested in the full declarative experience you may try NixOS: you would write services.libvirtd.enable = true; in your system configuration and be done with it.

Yeah, unfortunately I can’t switch to NixOS yet. I successfully installed the libvirt package, but I was not able to enable the service:

skainswo@skainswo-X58A-UD3R:~$ sudo systemctl enable libvirtd
[sudo] password for skainswo: 
Failed to enable unit: Unit file libvirtd.service does not exist.
skainswo@skainswo-X58A-UD3R:~$ sudo systemctl enable libvirt
Failed to enable unit: Unit file libvirt.service does not exist.

Do these packages have documentation anywhere? How do I find out how to set them up?

When you run systemctl on Ubuntu you are using systemctl from Ubuntu, not Nix. Unfortunately systemctl from Ubuntu isn’t aware of any software installed via Nix.

In its current form Nix isn’t able to run systemd services on non NixOS distros without jumping through some serious hoops. Not the answer you were looking for I’m sure :frowning:

1 Like

Ah, I see… Not the answer I was hoping for but that’s very helpful to know nonetheless!

As far as i understand, all the necessary service files are actually installed by nix, but just not registered by ubuntu. You should be able to add the nix systemd path to your ubuntu systemd, like mentioned in the first answer here: How does Nix manage SystemD modules on a non-NixOS? - Unix & Linux Stack Exchange.
I’ve never tried this myself but I assume it can work.

1 Like

Oh, that’s very interesting! I’ll give it a shot.

Some other approaches:

Disnix, been experimenting with this. It can be hooked into Ubuntu fairly easily.

1 Like