# Libvirtd on Ubuntu with Nix

**URL:** https://discourse.nixosstag.fcio.net/t/libvirtd-on-ubuntu-with-nix/7259
**Category:** Guides
**Created:** [May 18, 2020, 6:56am UTC](https://discourse.nixosstag.fcio.net/t/libvirtd-on-ubuntu-with-nix/7259 "2020-05-18T06:56:39Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![samuela](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/samuela/32/2486_2.png) [@samuela](https://discourse.nixosstag.fcio.net/u/samuela)
#### Post date: [May 18, 2020, 6:56am UTC](https://discourse.nixosstag.fcio.net/t/libvirtd-on-ubuntu-with-nix/7259/1 "2020-05-18T06:56:39Z")

</div>

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](https://help.ubuntu.com/community/KVM/Installation) 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!

---

<div class="post-metadata">

### Author: ![rnhmjoj](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/rnhmjoj/32/1792_2.png) [@rnhmjoj](https://discourse.nixosstag.fcio.net/u/rnhmjoj)
#### Post date: [May 18, 2020, 5:21pm UTC](https://discourse.nixosstag.fcio.net/t/libvirtd-on-ubuntu-with-nix/7259/2 "2020-05-18T17:21:35Z")

</div>

`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](https://ubuntu.com/server/docs/virtualization-libvirt).

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.

---

<div class="post-metadata">

### Author: ![samuela](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/samuela/32/2486_2.png) [@samuela](https://discourse.nixosstag.fcio.net/u/samuela)
#### Post date: [May 18, 2020, 8:10pm UTC](https://discourse.nixosstag.fcio.net/t/libvirtd-on-ubuntu-with-nix/7259/3 "2020-05-18T20:10:59Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

### Author: ![aanderse](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/aanderse/32/1420_2.png) [@aanderse](https://discourse.nixosstag.fcio.net/u/aanderse)
#### Post date: [May 18, 2020, 8:53pm UTC](https://discourse.nixosstag.fcio.net/t/libvirtd-on-ubuntu-with-nix/7259/4 "2020-05-18T20:53:19Z")

</div>

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 ☹

---

<div class="post-metadata">

### Author: ![samuela](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/samuela/32/2486_2.png) [@samuela](https://discourse.nixosstag.fcio.net/u/samuela)
#### Post date: [May 18, 2020, 9:04pm UTC](https://discourse.nixosstag.fcio.net/t/libvirtd-on-ubuntu-with-nix/7259/5 "2020-05-18T21:04:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![DavHau](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/davhau/32/2324_2.png) [@DavHau](https://discourse.nixosstag.fcio.net/u/DavHau)
#### Post date: [May 19, 2020, 6:35am UTC](https://discourse.nixosstag.fcio.net/t/libvirtd-on-ubuntu-with-nix/7259/6 "2020-05-19T06:35:37Z")

</div>

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](https://unix.stackexchange.com/questions/349199/how-does-nix-manage-systemd-modules-on-a-non-nixos).  
I’ve never tried this myself but I assume it can work.

---

<div class="post-metadata">

### Author: ![samuela](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/samuela/32/2486_2.png) [@samuela](https://discourse.nixosstag.fcio.net/u/samuela)
#### Post date: [May 19, 2020, 6:45pm UTC](https://discourse.nixosstag.fcio.net/t/libvirtd-on-ubuntu-with-nix/7259/7 "2020-05-19T18:45:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![tomberek](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/tomberek/32/283_2.png) [@tomberek](https://discourse.nixosstag.fcio.net/u/tomberek)
#### Post date: [May 22, 2020, 5:53pm UTC](https://discourse.nixosstag.fcio.net/t/libvirtd-on-ubuntu-with-nix/7259/8 "2020-05-22T17:53:11Z")

</div>

Some other approaches:

> [@Systemd backend or "using NixOps to manage Ubuntu"](https://discourse.nixosstag.fcio.net/t/systemd-backend-or-using-nixops-to-manage-ubuntu/1546/4):
>
> I was able to reduce the hackery to the following. It only needs a modified ./switch-to-configuration with these sections commented out: @@ -35,8 +35,8 @@ @@ -51,17 +51,17 @@ @@ -309,47 +309,47 @@ @@ -371,7 +371,7 @@ @@ -401,10 +401,10 @@ @@ -413,17 +413,17 @@ Remaining modifications are to forcibly clear out some elements of system.activationScripts. The following can be used by NixOps after some minimal prep on the Ubuntu machine Install Nix .bashrc add to PATH /nix/var/nix/profiles/defau…

> [@NixOS-like experience on Ubuntu in AWS](https://discourse.nixosstag.fcio.net/t/nixos-like-experience-on-ubuntu-in-aws/2422):
>
> I’ve had fun recently with making server Ubuntu behave more like NixOS. I’ll share some parts, which work for me, and I hope people can suggest improvements (drop Ubuntu? haha, nice try). So, my story is based around Nix, overlays, home-manager and declarative containers. Let’s start with required installations I’ll post installation instructions as Salt state config, but you can adapt to whatever you like. Nix # TODO: set secure\_path in /etc/sudoers to Nix-enabled value # In the meanwhile `…

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