Hello fellow nix users .
I have just setup virt-manager in nixos, and everytime i reboot and open virt-manger and try to run any virtual machine i get this error:
Error starting domain: Requested operation is not valid: network 'default' is not active
I managed to solve this error by running: sudo virsh net-start default however this will work until you reboot the machine you will have to run it again, following this article, it explains that you have to run sudo virsh net-autostart --network default if you want to auto start that daemon automatically on startup.
The only reason i have not applied the second solution is because i am on nixos, and i am making the assumption that there will be a nixos config that does the same thing + if there is (that would be good since it will be declared in the config).
To me sounds like according to my understanding of the article one needed to set virtualisation.libvirtd.allowedBridges to what is deemed ādefaultā (āvirbr0ā in the article again).
Some links around here discussing the bridge interface workings:
The systemd service automatically starts the libvirt default network on boot:
after = ["libvirtd.service"] ensures it only runs after libvirtd is ready
wantedBy = ["multi-user.target"] makes it start automatically at boot
Type = "oneshot" with RemainAfterExit = true means it runs once and systemd considers it active
ExecStart runs virsh net-start default when the service starts
ExecStop runs virsh net-destroy default on shutdown/stop for clean teardown
This is the NixOS equivalent of running sudo virsh net-autostart default on other distributions. The network will now automatically be available whenever you start virt-manager, eliminating the ānetwork ādefaultā is not activeā error.
just out of curiosity, since we declare the extraGroups elsewhereunder users in our config, currently i am forced to give that option in users line instead of declaring the libvirtd extragroups near the libvirt vonfig line. How to do this?
I want a method where it should work well like commenting the above whole virt-manager thing will revert my extragroups back to normal instead of going to users line and removing the libvirtd.
edit:
is this the neat way? users.groups.libvirtd.members = ["alice"];
Yes. As far as I understand, that is the neat way. Thanks for pointing it out, though. Iāll update the code in my post.(Edit: Ah⦠I canāt edit the post anymore)
Also, you can make the other approach (users.users.<myuser>.extraGroups = [ "libvirtd" ];) work by using nix modules. Tutorial here.
Hey, this almost worked. But I got a minor bug here, where I open virt-manager it stays on "Connecting to KVM/QEMU " something. And only when I close and reopen the app it works fine showing my guest OSs.
Iām okay with this now, but would love to have a solution
Which channel are you using? Iām on nixpkgs-unstable and it looks like the connection setting is already included as part of the virt-manager, so I donāt need to redefine it in my config.
Hereās my full virt-manager module, if youāre curious:
@avisek what does this lib.gvariant do?
I couldnāt find a function in that exact name in noogle.dev all ends with some other name. So what does this do? Can I just use {} without wrapping it with the gvariant like you did?
gvariant is a set, thats why you can use it with with.
Though why it is in the snippet, I canāt say, as the given snippet doesnāt use any bindings at all in the scope introduced by the with.
Nether of the 2 do⦠(except for lib.gvariant which isnāt overwritten by any of the with either anyway, if the lib got introduced into scope idiomatically).
Before I start explaining, I need to do a small correction to my above code snippet: There should only be one āwith lib.gvariant;ā (Thanks to @NobbZ for pointing it out)
Itās like with pkgs; for environment.systemPackages:
# with `with pkgs;`
environment.systemPackages = with pkgs; [
git
neovim
]
# without `with pkgs;`
environment.systemPackages = [
pkgs.git
pkgs.neovim
]
lib.gvariant provides type conversion functions for GVariant, the serialization format used by GSettings/dconf. It ensures values are properly typed for the configuration system.
lib.gvariant.mkInt32 converts nix integer to dconf-specific 32-bit signed integer.
Can you omit gvariant conversions? No, not reliably. Plain Nix values may not serialize correctly to GVariant. For example:
# This might not work correctly
resize-guest = 1; # Could be interpreted as different integer type
# This ensures correct GVariant typing
resize-guest = lib.gvariant.mkInt32 1;
However, some simple types like strings and booleans often work without explicit conversion, but integers frequently need mkInt32 to avoid type mismatches that can cause dconf to reject the settings.
Best practice: Keep using lib.gvariant functions to ensure your dconf settings are applied correctly.