From 297d53dac887766a85dced8a9e3e684903cd3130 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Fri, 7 Jun 2024 13:56:48 +0200 Subject: [PATCH] syncthing: automatically add zt network ip to devices --- clanModules/syncthing-static-peers/default.nix | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/clanModules/syncthing-static-peers/default.nix b/clanModules/syncthing-static-peers/default.nix index df350500..9df8a9d6 100644 --- a/clanModules/syncthing-static-peers/default.nix +++ b/clanModules/syncthing-static-peers/default.nix @@ -18,11 +18,28 @@ let if builtins.pathExists fullPath then machine else null ) machines; syncthingPublicKeyMachines = lib.filter (machine: machine != null) syncthingPublicKeysUnchecked; + 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; + networkIpMachines = lib.filter (machine: machine != null) networkIpsUnchecked; devices = builtins.map (machine: { name = machine; value = { name = machine; id = (lib.removeSuffix "\n" (builtins.readFile (syncthingPublicKeyPath machine))); + addresses = + [ "dynamic" ] + ++ ( + if (lib.elem machine networkIpMachines) then + [ "tcp://[${(lib.removeSuffix "\n" (builtins.readFile (zerotierIpMachinePath machine)))}]:22000" ] + else + [ ] + ); }; }) syncthingPublicKeyMachines; in