diff --git a/clanModules/static-hosts/default.nix b/clanModules/static-hosts/default.nix index 70766b1a6..343f38126 100644 --- a/clanModules/static-hosts/default.nix +++ b/clanModules/static-hosts/default.nix @@ -19,10 +19,20 @@ clanDir = config.clanCore.clanDir; machineDir = clanDir + "/machines/"; zerotierIpMachinePath = machines: machineDir + machines + "/facts/zerotier-ip"; - machines = builtins.readDir machineDir; + machinesFileSet = builtins.readDir machineDir; + machines = lib.mapAttrsToList (name: _: name) machinesFileSet; + networkIpsUnchecked = builtins.map ( + machine: + let + fullPath = zerotierIpMachinePath machine; + in + if builtins.pathExists fullPath then machine else null + ) machines; + networkIps = lib.filter (machine: machine != null) networkIpsUnchecked; + machinesWithIp = lib.filterAttrs (name: _: (lib.elem name networkIps)) machinesFileSet; filteredMachines = lib.filterAttrs ( name: _: !(lib.elem name config.clan.static-hosts.excludeHosts) - ) machines; + ) machinesWithIp; in lib.filterAttrs (_: value: value != null) ( lib.mapAttrs' ( @@ -38,7 +48,7 @@ [ "${machine}.${config.clan.static-hosts.topLevelDomain}" ] ) else - null + { } ) filteredMachines ); }