From f09ab69a7e15a170060e7c459008f31c1d31b058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Mon, 1 Jul 2024 13:33:28 +0200 Subject: [PATCH] nixos/zerotierone: clean up local.conf symlinks unconditionally --- nixos/modules/services/networking/zerotierone.nix | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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}