From 217d834eb9cdb6607880eda85b49524c35363061 Mon Sep 17 00:00:00 2001 From: George Shammas Date: Mon, 25 May 2026 21:33:18 -0400 Subject: [PATCH] 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. --- .../virtualisation/nixos-containers.nix | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/nixos/modules/virtualisation/nixos-containers.nix b/nixos/modules/virtualisation/nixos-containers.nix index 84bb0b6c4856..dd9177a5bd21 100644 --- a/nixos/modules/virtualisation/nixos-containers.nix +++ b/nixos/modules/virtualisation/nixos-containers.nix @@ -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 =