NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.71k stars 13.85k forks source link

libvirt: the default virtual network cannot be removed #73418

Closed alexbakker closed 2 years ago

alexbakker commented 4 years ago

Describe the bug The default virtual network for libvirt cannot be persistently removed or disabled.

To Reproduce Steps to reproduce the behavior:

  1. Enable libvirtd with virtualisation.libvirt.enable = true;.
  2. Verify that the default network exists with: virsh net-list.
  3. Remove the 'default' network with virsh net-destroy default && virsh net-undefine default.
  4. Verify that the default network has been removed with: virsh net-list.
  5. Restart libvirtd: systemctl restart libvirtd.
  6. Notice that the default network has reappeared.

Expected behavior I expected the 'default' network to still be gone after a restart of libvirtd.

Metadata

 - system: `"x86_64-linux"`
 - host os: `Linux 5.3.10, NixOS, 19.09.1223.cb2cdab7136 (Loris)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3`
 - channels(root): `"nixos-19.09.1223.cb2cdab7136, home-manager-19.09"`
 - channels(alex): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute: libvirt
# a list of nixos modules affected by the problem
module: libvirtd
stale[bot] commented 4 years ago

Thank you for your contributions. This has been automatically marked as stale because it has had no activity for 180 days. If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity. Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse. 3. Ask on the #nixos channel on irc.freenode.net.
alexbakker commented 4 years ago

This is still an issue.

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

euank commented 3 years ago

Unstale; I'll try to find the time to poke at this since I've been doing a little work on the libvirt package.

Xpl0itR commented 3 years ago

Still an issue. Made a workaround for the meantime:

systemd.services.destroy-libvirtd-default-network = {
  path     = [ pkgs.libvirt ];
  requires = [ "libvirtd.service" ];
  after    = [ "libvirtd.service" ];
  wantedBy = [ "multi-user.target" ];
  script   = ''
if [[ $(virsh net-list --name) == *"default"* ]]; then
  virsh net-destroy default && virsh net-undefine default
else
  echo "libvirt default network has already been destroyed"
fi
  '';
};
dasJ commented 3 years ago

Caused by this: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/libvirtd.nix#L194

Also, much nicer workaround:

{
  systemd.services.libvirtd-config.script = lib.mkAfter ''
    rm /var/lib/libvirt/qemu/networks/autostart/default.xml
  '';
}
stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

dasJ commented 2 years ago

still annoying to me

amarshall commented 2 years ago

Please see PR. Welcome to comments as to whether it’s the best option or not. https://github.com/NixOS/nixpkgs/pull/186358

fpletz commented 2 years ago

Fixed by @amarshall in #186358. Thanks!

rickykresslein commented 1 year ago

I've stumbled upon this when trying to figure out how to set a default network. Now that it is not set automatically, how can I set it?

amarshall commented 1 year ago

@rickykresslein Put whatever you want to be the default network in /var/lib/libvirt/qemu/networks/autostart/default.xml. If you want to copy the default “default network” from the libvirt pkg, it’s in ${pkgs.libvirt}/var/lib/libvirt/qemu/networks/autostart/default.xml.