From 954f1fe605ad4181847502da72b00a82911dd3b2 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Wed, 5 Jun 2024 19:07:06 +0200 Subject: [PATCH] zerotier-static-peers: filter out non existing Ip --- clanModules/zerotier-static-peers/default.nix | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/clanModules/zerotier-static-peers/default.nix b/clanModules/zerotier-static-peers/default.nix index a396bbb0..c0f197b7 100644 --- a/clanModules/zerotier-static-peers/default.nix +++ b/clanModules/zerotier-static-peers/default.nix @@ -35,21 +35,26 @@ in config.systemd.services.zerotier-static-peers-autoaccept = let - machines = builtins.readDir machineDir; zerotierIpMachinePath = machines: machineDir + machines + "/facts/zerotier-ip"; + 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.zerotier-static-peers.excludeHosts) - ) machines; + ) machinesWithIp; hosts = lib.mapAttrsToList (host: _: host) ( lib.mapAttrs' ( machine: _: let fullPath = zerotierIpMachinePath machine; in - if builtins.pathExists fullPath then - lib.nameValuePair (builtins.readFile fullPath) [ machine ] - else - null + lib.nameValuePair (builtins.readFile fullPath) [ machine ] ) filteredMachines ); in