Merge pull request 'static-hosts: filter out non existing Ip's' (#1574) from kenji/clan-core:static-hosts-fix into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/1574
This commit is contained in:
@@ -19,10 +19,20 @@
|
|||||||
clanDir = config.clanCore.clanDir;
|
clanDir = config.clanCore.clanDir;
|
||||||
machineDir = clanDir + "/machines/";
|
machineDir = clanDir + "/machines/";
|
||||||
zerotierIpMachinePath = machines: machineDir + machines + "/facts/zerotier-ip";
|
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 (
|
filteredMachines = lib.filterAttrs (
|
||||||
name: _: !(lib.elem name config.clan.static-hosts.excludeHosts)
|
name: _: !(lib.elem name config.clan.static-hosts.excludeHosts)
|
||||||
) machines;
|
) machinesWithIp;
|
||||||
in
|
in
|
||||||
lib.filterAttrs (_: value: value != null) (
|
lib.filterAttrs (_: value: value != null) (
|
||||||
lib.mapAttrs' (
|
lib.mapAttrs' (
|
||||||
@@ -38,7 +48,7 @@
|
|||||||
[ "${machine}.${config.clan.static-hosts.topLevelDomain}" ]
|
[ "${machine}.${config.clan.static-hosts.topLevelDomain}" ]
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
null
|
{ }
|
||||||
) filteredMachines
|
) filteredMachines
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user