From 8615a25cbece3dcfab393637f7c25b2f3239afb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Tue, 10 Mar 2026 16:10:26 +0100 Subject: [PATCH] nixos/test-driver: make /etc/hosts VLAN-aware with primary IP fallback Resolves an issue where nodes on shared secondary VLANs could not reach each other if their primary IPs were on isolated networks. --- nixos/lib/testing/network.nix | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/nixos/lib/testing/network.nix b/nixos/lib/testing/network.nix index fff7ffbc260f..570b854d8e28 100644 --- a/nixos/lib/testing/network.nix +++ b/nixos/lib/testing/network.nix @@ -64,11 +64,9 @@ let optionalString (ipInterfaces != [ ]) (head (head ipInterfaces).value.ipv6.addresses).address; - # Generate /etc/hosts by only including IP addresses from VLANs that - # both the local machine and the remote machine share. This prevents - # machines from trying to connect via unreachable interfaces (e.g., - # a Management VLAN) and ensures name resolution matches the - # actual network topology of the test. + # Generate /etc/hosts including every remote's primary IP addresses + # (whichever VLAN they may belong to) as well as all IP addresses from + # VLANs that both the local machine and the remote machine share. networking.extraHosts = let localVlans = config.virtualisation.vlans; @@ -91,13 +89,24 @@ let [ ] ) remoteInterfaces ); + + # We also want to test router protocols that enable connections + # between nodes even if they don't share a VLAN, so we include + # the primary IPs of all machines in the hosts file. + primaryIPs = [ + remoteConfig.networking.primaryIPAddress + remoteConfig.networking.primaryIPv6Address + ]; + + allReachableIps = lib.lists.uniqueStrings (sharedIps ++ primaryIPs); + hostnames = optionalString ( remoteConfig.networking.domain != null ) "${remoteConfig.networking.hostName}.${remoteConfig.networking.domain} " + "${remoteConfig.networking.hostName}\n"; in - builtins.concatStringsSep "" (map (ip: "${ip} ${hostnames}") sharedIps) + builtins.concatStringsSep "" (map (ip: "${ip} ${hostnames}") allReachableIps) ) testModuleArgs.config.allMachines; }; in