From 9b98cdfe38c85c9905294f1ba42bc7d4f2668ddc Mon Sep 17 00:00:00 2001 From: Alexander Heldt Date: Sat, 31 Aug 2024 12:45:52 +0200 Subject: [PATCH] backwards: Add `enable` option to `syncthing` module --- hosts/backwards/modules/default.nix | 1 + hosts/backwards/modules/syncthing/default.nix | 133 ++++++++++-------- 2 files changed, 73 insertions(+), 61 deletions(-) diff --git a/hosts/backwards/modules/default.nix b/hosts/backwards/modules/default.nix index 3cf51b3..c592aaa 100644 --- a/hosts/backwards/modules/default.nix +++ b/hosts/backwards/modules/default.nix @@ -12,6 +12,7 @@ in ssh.enable = true; git.enable = true; + syncthing.enable = true; }; }; } diff --git a/hosts/backwards/modules/syncthing/default.nix b/hosts/backwards/modules/syncthing/default.nix index 88433b9..637bcbc 100644 --- a/hosts/backwards/modules/syncthing/default.nix +++ b/hosts/backwards/modules/syncthing/default.nix @@ -1,88 +1,99 @@ -{ config, ... }: +{ lib, config, ... }: +let + enabled = config.mod.syncthing.enable; +in { - services.syncthing = { - enable = true; - openDefaultPorts = true; + options = { + mod.syncthing = { + enable = lib.mkEnableOption "Enable syncthing module"; + }; + }; - cert = config.age.secrets.syncthing-cert.path; - key = config.age.secrets.syncthing-key.path; + config = lib.mkIf enabled { + services.syncthing = { + enable = true; + openDefaultPorts = true; - user = "alex"; - group = "users"; + cert = config.age.secrets.syncthing-cert.path; + key = config.age.secrets.syncthing-key.path; - dataDir = "/home/alex/sync"; + user = "alex"; + group = "users"; - guiAddress = "0.0.0.0:8384"; + dataDir = "/home/alex/sync"; - settings = { - devices = { - phone.id = config.lib.syncthing.phone; - pinwheel.id = config.lib.syncthing.pinwheel; - }; + guiAddress = "0.0.0.0:8384"; - folders = { - org = { - path = "/home/alex/sync/org"; - devices = [ "phone" "pinwheel" ]; - versioning = { - type = "staggered"; - params = { - maxage = "2592000"; # 30 days - }; - }; + settings = { + devices = { + phone.id = config.lib.syncthing.phone; + pinwheel.id = config.lib.syncthing.pinwheel; }; - personal = { - path = "/home/alex/sync/personal"; - devices = [ "pinwheel" ]; - versioning = { - type = "staggered"; - params = { - maxAge = "2592000"; # 30 days + folders = { + org = { + path = "/home/alex/sync/org"; + devices = [ "phone" "pinwheel" ]; + versioning = { + type = "staggered"; + params = { + maxage = "2592000"; # 30 days + }; }; }; - }; - work = { - path = "/home/alex/sync/work"; - devices = [ "pinwheel" ]; - versioning = { - type = "staggered"; - params = { - maxAge = "2592000"; # 30 days + personal = { + path = "/home/alex/sync/personal"; + devices = [ "pinwheel" ]; + versioning = { + type = "staggered"; + params = { + maxAge = "2592000"; # 30 days + }; }; }; - }; - books = { - path = "/home/alex/sync/books"; - devices = [ "pinwheel" ]; - versioning = { - type = "staggered"; - params = { - maxAge = "2592000"; # 30 days + work = { + path = "/home/alex/sync/work"; + devices = [ "pinwheel" ]; + versioning = { + type = "staggered"; + params = { + maxAge = "2592000"; # 30 days + }; }; }; - }; - "phone-gps" = { - path = "/home/alex/sync/phone-gps"; - devices = [ "phone" ]; - versioning = { - type = "staggered"; - params = { - maxage = "2592000"; # 30 days + books = { + path = "/home/alex/sync/books"; + devices = [ "pinwheel" ]; + versioning = { + type = "staggered"; + params = { + maxAge = "2592000"; # 30 days + }; + }; + }; + + "phone-gps" = { + path = "/home/alex/sync/phone-gps"; + devices = [ "phone" ]; + versioning = { + type = "staggered"; + params = { + maxage = "2592000"; # 30 days + }; }; }; }; }; }; - }; - age = { - secrets = { - "syncthing-cert".file = ../../../../secrets/backwards/syncthing-cert.age; - "syncthing-key".file = ../../../../secrets/backwards/syncthing-key.age; + age = { + secrets = { + "syncthing-cert".file = ../../../../secrets/backwards/syncthing-cert.age; + "syncthing-key".file = ../../../../secrets/backwards/syncthing-key.age; + }; }; }; }