Configure network for libvirtd with systemd

This commit is contained in:
Erwin Boskma 2022-09-21 22:52:10 +02:00
parent 346d4d8b18
commit 3d3653efeb
Signed by: erwin
GPG key ID: 270B20D17394F7E5

View file

@ -9,23 +9,60 @@ in
config = mkIf (cfg.enable) {
virtualisation.libvirtd = {
enable = true;
allowedBridges = [ "br0" ];
};
networking = {
interfaces = {
br0 = {
useDHCP = true;
macAddress = "04:d9:f5:f9:c2:c6";
systemd.network = {
netdevs = {
"40-br0" = {
enable = true;
netdevConfig = {
Kind = "bridge";
Name = "br0";
};
extraConfig = ''
[Bridge]
STP=yes
'';
};
};
bridges = {
"br0" = {
interfaces = [ "enp4s0" ];
# rstp = true;
networks = {
"40-br0" = {
enable = true;
matchConfig = {
Name = "br0";
};
linkConfig = {
MACAddress = "04:d9:f5:f9:c2:c6";
};
networkConfig = {
DHCP = "yes";
IPv6PrivacyExtensions = "kernel";
};
};
"40-enp4s0" = {
enable = true;
bridge = [ "br0" ];
matchConfig = {
Name = "enp4s0";
};
networkConfig = {
DHCP = mkForce "no";
IPv6PrivacyExtensions = "kernel";
};
};
};
};
systemd.services.docker = {
serviceConfig = {
ExecStartPre = "${pkgs.iptables}/bin/iptables -I DOCKER-USER -i br0 -o br0 -j ACCEPT";
};
};
users.users.${config.eboskma.var.mainUser}.extraGroups = [ "libvirtd" ];
environment.systemPackages = with pkgs; [ virt-manager ];
};
}