nixos/containers: fix default gateway with privateNetwork (v2)

The fix in #523016 fixes an issue with the default gateway, however it
does so by unconditionally defining `networking.interfaces.eth0`. This
makes so if you had other methods of defining the addresses for eth0,
those now get blanked out.

Instead, move the logic around so we only define
networking.interfaces.eth0 if we really have to.
This commit is contained in:
George Shammas
2026-05-25 22:17:45 -04:00
parent 64c08a7ca0
commit 217d834eb9
@@ -607,14 +607,16 @@ in
boot.isNspawnContainer = true;
networking.hostName = mkDefault name;
networking.useDHCP = false;
networking.interfaces = lib.mkIf config.privateNetwork {
eth0.ipv4.addresses = lib.optional (config.localAddress != null) (
ipv4FromString config.localAddress
);
eth0.ipv6.addresses = lib.optional (config.localAddress6 != null) (
lib.network.ipv6.fromString config.localAddress6
);
};
networking.interfaces = lib.mkIf config.privateNetwork (
lib.mkMerge [
(lib.mkIf (config.localAddress != null) {
eth0.ipv4.addresses = [ (ipv4FromString config.localAddress) ];
})
(lib.mkIf (config.localAddress6 != null) {
eth0.ipv6.addresses = [ (lib.network.ipv6.fromString config.localAddress6) ];
})
]
);
assertions = [
{
assertion =