From af53e9b502f6cb363e5a93bad6d0232523352af0 Mon Sep 17 00:00:00 2001 From: Yan Lin Date: Thu, 12 Feb 2026 21:04:58 +0100 Subject: [PATCH] expand syncthing folder options --- hosts/nixos/nfss/home.nix | 6 +++ hosts/nixos/thinkpad/home.nix | 7 +++ modules/syncthing.nix | 82 +++++++++++++++++------------------ 3 files changed, 52 insertions(+), 43 deletions(-) diff --git a/hosts/nixos/nfss/home.nix b/hosts/nixos/nfss/home.nix index 10ec8e1..e5f1188 100644 --- a/hosts/nixos/nfss/home.nix +++ b/hosts/nixos/nfss/home.nix @@ -7,4 +7,10 @@ ../../../modules/media/tool.nix ]; + syncthing-custom.folders = { + Credentials.maxAgeDays = 30; + Documents.maxAgeDays = 30; + Media.maxAgeDays = 7; + Archive.maxAgeDays = 30; + }; } diff --git a/hosts/nixos/thinkpad/home.nix b/hosts/nixos/thinkpad/home.nix index c147a7a..ed725b6 100644 --- a/hosts/nixos/thinkpad/home.nix +++ b/hosts/nixos/thinkpad/home.nix @@ -8,6 +8,13 @@ ../../../modules/schedule.nix ]; + syncthing-custom.folders = { + Credentials.maxAgeDays = 30; + Documents.maxAgeDays = 30; + Media.maxAgeDays = 7; + Archive.maxAgeDays = 30; + }; + services.scheduled-commands.dcim-consume = { enable = true; description = "Move files in dcim consume folder to DCIM"; diff --git a/modules/syncthing.nix b/modules/syncthing.nix index ab13e91..5e06d31 100644 --- a/modules/syncthing.nix +++ b/modules/syncthing.nix @@ -2,26 +2,45 @@ let cfg = config.syncthing-custom; - + pcDevices = [ "macbook" "imac" "thinkpad" "nfss" ]; touchDevices = [ "iphone" "ipad" ]; allDevices = pcDevices ++ touchDevices; - commonVersioning = { - type = "staggered"; - params = { - maxAge = "604800"; # 7 days - cleanInterval = "3600"; # 1 hour - }; + mkFolderOptions = name: { maxAgeDays ? 0 }: { + enable = lib.mkEnableOption "${name} folder" // { default = true; }; + path = lib.mkOption { type = lib.types.str; default = "~/${name}"; }; + maxAgeDays = lib.mkOption { type = lib.types.int; default = maxAgeDays; }; }; + mkVersioning = days: + if days == 0 then {} + else { + versioning = { + type = "staggered"; + params = { + maxAge = toString (days * 86400); + cleanInterval = "3600"; + }; + }; + }; + + mkFolder = name: folderCfg: extraAttrs: + lib.optionalAttrs folderCfg.enable { + ${name} = { + path = folderCfg.path; + devices = extraAttrs.devices; + } // mkVersioning folderCfg.maxAgeDays; + }; + in { options.syncthing-custom = { - enabledFolders = lib.mkOption { - type = lib.types.listOf lib.types.str; - default = [ "Credentials" "Documents" "Archive" "Media" ]; - description = "List of Syncthing folders to enable for this host."; + folders = { + Credentials = mkFolderOptions "Credentials" {}; + Documents = mkFolderOptions "Documents" {}; + Media = mkFolderOptions "Media" {}; + Archive = mkFolderOptions "Archive" {}; }; enableGui = lib.mkOption { type = lib.types.bool; @@ -36,9 +55,9 @@ in tray.enable = false; overrideDevices = true; overrideFolders = true; - + guiAddress = lib.mkIf cfg.enableGui "127.0.0.1:8384"; - + settings = { devices = { "iphone" = { @@ -60,36 +79,13 @@ in id = "S4QZW76-BOLIOW7-DVP326F-JIGW5DW-3PAD47L-OA456LB-2L6JZW7-YUGJRA6"; }; }; - + folders = - (lib.optionalAttrs (lib.elem "Credentials" cfg.enabledFolders) { - "Credentials" = { - path = "~/Credentials"; - devices = allDevices; - versioning = commonVersioning; - }; - }) - // (lib.optionalAttrs (lib.elem "Documents" cfg.enabledFolders) { - "Documents" = { - path = "~/Documents"; - devices = pcDevices; - versioning = commonVersioning; - }; - }) - // (lib.optionalAttrs (lib.elem "Media" cfg.enabledFolders) { - "Media" = { - path = "~/Media"; - devices = lib.filter (d: d != "iphone") allDevices; - }; - }) - // (lib.optionalAttrs (lib.elem "Archive" cfg.enabledFolders) { - "Archive" = { - path = "~/Archive"; - devices = allDevices; - versioning = commonVersioning; - }; - }); - + mkFolder "Credentials" cfg.folders.Credentials { devices = allDevices; } + // mkFolder "Documents" cfg.folders.Documents { devices = pcDevices; } + // mkFolder "Media" cfg.folders.Media { devices = lib.filter (d: d != "iphone") allDevices; } + // mkFolder "Archive" cfg.folders.Archive { devices = allDevices; }; + gui = { enabled = cfg.enableGui; user = "yanlin"; @@ -97,7 +93,7 @@ in useTLS = false; insecureSkipHostcheck = true; }; - + options = { urAccepted = -1; relaysEnabled = true;