diff --git a/nixos/modules/services/networking/zerotierone.nix b/nixos/modules/services/networking/zerotierone.nix index 2485327ed44e..8b52ad7dd51e 100644 --- a/nixos/modules/services/networking/zerotierone.nix +++ b/nixos/modules/services/networking/zerotierone.nix @@ -60,14 +60,16 @@ in mkdir -p /var/lib/zerotier-one/networks.d chmod 700 /var/lib/zerotier-one chown -R root:root /var/lib/zerotier-one + + # cleans up old symlinks also if we unset localConf + if [[ -L "${localConfFilePath}" && "$(readlink "${localConfFilePath}")" =~ ^${builtins.storeDir}.* ]]; then + rm ${localConfFilePath} + fi '' + (concatMapStrings (netId: '' touch "/var/lib/zerotier-one/networks.d/${netId}.conf" - '') cfg.joinNetworks) + optionalString (cfg.localConf != {}) '' - if [ -L "${localConfFilePath}" ] - then - rm ${localConfFilePath} - elif [ -f "${localConfFilePath}" ] - then + '') cfg.joinNetworks) + lib.optionalString (cfg.localConf != {}) '' + # in case the user has applied manual changes to the local.conf, we backup the file + if [ -f "${localConfFilePath}" ]; then mv ${localConfFilePath} ${localConfFilePath}.bak fi ln -s ${localConfFile} ${localConfFilePath}