From d1cbda1c36ae8b77a1814dbf90346ac400ebf219 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 17 Jan 2020 16:42:35 -0500 Subject: [PATCH] Refactor syncthing config And fix issue where folder types were set to null. --- modules/services/syncthing.nix | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/services/syncthing.nix b/modules/services/syncthing.nix index bbc62d06..dd1c5183 100644 --- a/modules/services/syncthing.nix +++ b/modules/services/syncthing.nix @@ -17,38 +17,42 @@ midori.id = "BOFH5JP-A3MPTJA-EGIZVWV-URHUTSJ-2ZXCAA2-XMZPPSR-GLMOQFL-ZX7DGQP"; }; folders = - let ifEnabledDevice = devices: lib.elem config.networking.hostName devices; + let deviceEnabled = devices: lib.elem config.networking.hostName devices; + deviceType = devices: + if (deviceEnabled devices) + then "sendreceive" + else "receiveonly"; in { archive = rec { devices = [ "kuro" "ao" "midori" ]; path = "/home/${config.my.username}/archive"; watch = false; rescanInterval = 3600 * 6; - type = lib.mkIf (! ifEnabledDevice ["kuro"]) "recieveonly"; - enable = ifEnabledDevice devices; + type = deviceType ["kuro"]; + enable = deviceEnabled devices; }; share = rec { devices = [ "kuro" "shiro" "ao" "aka" "midori" ]; path = "/home/${config.my.username}/share"; watch = true; rescanInterval = 3600 * 6; - enable = ifEnabledDevice devices; + enable = deviceEnabled devices; }; projects = rec { devices = [ "kuro" "shiro" "ao" "midori" ]; path = "/home/${config.my.username}/projects"; watch = false; rescanInterval = 3600 * 2; - type = lib.mkIf (ifEnabledDevice ["ao"]) "recieveonly"; - enable = ifEnabledDevice devices; + type = deviceType ["ao"]; + enable = deviceEnabled devices; }; secrets = rec { devices = [ "kuro" "shiro" "ao" "aka" ]; path = "/home/${config.my.username}/.secrets"; watch = true; rescanInterval = 3600; - type = lib.mkIf (! ifEnabledDevice ["kuro" "shiro"]) "recieveonly"; - enable = ifEnabledDevice devices; + type = deviceType ["kuro" "shiro"]; + enable = deviceEnabled devices; }; }; };