From eefa14bd57f8211ad847e9c4c71437086127a0ce Mon Sep 17 00:00:00 2001 From: cnst Date: Sat, 6 Sep 2025 13:49:24 +0200 Subject: [PATCH] feat(syncthing): adding syncthing host to sobotka --- hosts/sobotka/server.nix | 5 ++ modules/default.nix | 1 + modules/home/services/syncthing/default.nix | 4 +- modules/server/default.nix | 16 ++++- modules/server/syncthing/default.nix | 68 +++++++++++++++++++++ 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 modules/server/syncthing/default.nix diff --git a/hosts/sobotka/server.nix b/hosts/sobotka/server.nix index cbf1eeae..50705262 100644 --- a/hosts/sobotka/server.nix +++ b/hosts/sobotka/server.nix @@ -9,6 +9,11 @@ uid = 994; gid = 993; + mounts = { + fast = "/mnt/user"; + config = "/persist/opt/services"; + }; + unbound = { enable = true; }; diff --git a/modules/default.nix b/modules/default.nix index 21737120..a01ffd01 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -129,6 +129,7 @@ ./server/lidarr ./server/radarr ./server/sonarr + ./server/syncthing ./server/jellyseerr ./server/jellyfin ./server/podman diff --git a/modules/home/services/syncthing/default.nix b/modules/home/services/syncthing/default.nix index dd5b7fa0..318646f2 100644 --- a/modules/home/services/syncthing/default.nix +++ b/modules/home/services/syncthing/default.nix @@ -9,7 +9,9 @@ let in { options = { - home.services.syncthing.enable = mkEnableOption "Enables syncthing"; + home.services.syncthing = { + enable = mkEnableOption "Enables syncthing"; + }; }; config = mkIf cfg.enable { services.syncthing = { diff --git a/modules/server/default.nix b/modules/server/default.nix index 41fdcbf4..52d5e338 100644 --- a/modules/server/default.nix +++ b/modules/server/default.nix @@ -11,6 +11,20 @@ in { options.server = { enable = lib.mkEnableOption "The server services and configuration variables"; + mounts.fast = lib.mkOption { + default = "/mnt/cache"; + type = lib.types.path; + description = '' + Path to the 'fast' tier mount + ''; + }; + mounts.config = lib.mkOption { + default = "/persist/opt/services"; + type = lib.types.path; + description = '' + Path to the service configuration files + ''; + }; email = mkOption { default = ""; type = types.str; @@ -53,7 +67,6 @@ in GID to run the server services as ''; }; - timeZone = lib.mkOption { default = "Europe/Stockholm"; type = lib.types.str; @@ -62,6 +75,7 @@ in ''; }; }; + config = lib.mkIf cfg.enable { users = { groups.${cfg.group} = { diff --git a/modules/server/syncthing/default.nix b/modules/server/syncthing/default.nix new file mode 100644 index 00000000..5c6a1663 --- /dev/null +++ b/modules/server/syncthing/default.nix @@ -0,0 +1,68 @@ +{ + config, + lib, + ... +}: +let + unit = "syncthing"; + srv = config.server; + cfg = config.server.${unit}; + dir = [ + "${srv.mounts.config}/syncthing" + ]; +in +{ + options.server.${unit} = { + enable = lib.mkEnableOption { + description = "Enable ${unit}"; + }; + url = lib.mkOption { + type = lib.types.str; + default = "${unit}.${srv.domain}"; + }; + homepage.name = lib.mkOption { + type = lib.types.str; + default = "Syncthing"; + }; + homepage.description = lib.mkOption { + type = lib.types.str; + default = "Continuous file synchronization program."; + }; + homepage.icon = lib.mkOption { + type = lib.types.str; + default = "syncthing.svg"; + }; + homepage.category = lib.mkOption { + type = lib.types.str; + default = "Services"; + }; + }; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = map (x: "d ${x} 0775 share share - -") dir; + networking.firewall = { + allowedTCPPorts = [ + 8384 + 22000 + ]; + allowedUDPPorts = [ + 22000 + 21027 + ]; + }; + services.${unit} = { + enable = true; + user = srv.user; + group = srv.group; + overrideFolders = false; + overrideDevices = false; + dataDir = "${srv.mounts.fast}/Syncthing"; + configDir = "${srv.mounts.config}/syncthing"; + }; + services.caddy.virtualHosts."${cfg.url}" = { + useACMEHost = srv.domain; + extraConfig = '' + reverse_proxy http://127.0.0.1:8384} + ''; + }; + }; +}