From 592901ea2c7ae225e69606e0b28518515fe1e726 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Tue, 5 Nov 2019 22:39:57 +0100 Subject: [PATCH] syncthing: add proper versioning --- configs/sterni/syncthing.nix | 2 +- modules/later/syncthing.nix | 62 +++++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/configs/sterni/syncthing.nix b/configs/sterni/syncthing.nix index f2af999..125e3c0 100644 --- a/configs/sterni/syncthing.nix +++ b/configs/sterni/syncthing.nix @@ -21,7 +21,7 @@ }; finance = { enable = true; - path = "/home/palo/finance"; + path = "/home/palo/finance"; }; lost-fotos = { enable = true; diff --git a/modules/later/syncthing.nix b/modules/later/syncthing.nix index 927f50c..2f9d365 100644 --- a/modules/later/syncthing.nix +++ b/modules/later/syncthing.nix @@ -18,7 +18,7 @@ let fsWatcherEnabled = folder.watch; fsWatcherDelayS = folder.watchDelay; ignorePerms = folder.ignorePerms; - versioning = optionalAttrs folder.versioning.enable { type = "simple"; params.keep = toString folder.versioning.keep; }; + versioning = folder.versioning; }) (filterAttrs ( _: folder: folder.enable @@ -221,17 +221,57 @@ in { ''; }; - versioning = { - enable = mkEnableOption '' - simple versioning, see https://docs.syncthing.net/users/versioning.html#simple-file-versioning + versioning = mkOption { + default = null; + description = '' + how to keep changed/deleted files with syncthing. + there are 4 different types of versioning with different parameters + see https://docs.syncthing.net/users/versioning.html#simple-file-versioning ''; - keep = mkOption { - type = types.int; - default = 5; - description = '' - The number of old versions to keep, per file. - ''; - }; + example = [ + { + versioning = { + type = "simple"; + params.keep = "10"; + }; + } + { + versioning = { + type = "trashcan"; + params.cleanoutDays = "1000"; + }; + } + { + versioning = { + type = "staggered"; + params = { + cleanInterval = "3600"; + maxAge = "31536000"; + versionsPath = "/syncthing/backup"; + }; + }; + } + { + versioning = { + type = "external"; + params.versionsPath = pkgs.writers.writeBash "backup" '' + folderpath="$1" + filepath="$2" + rm -rf "$folderpath/$filepath" + ''; + }; + } + ]; + type = with types; nullOr (submodule { + options = { + type = mkOption { + type = enum [ "external" "simple" "staggered" "trashcan" ]; + }; + params = mkOption { + type = attrsOf (either str path); + }; + }; + }); }; rescanInterval = mkOption {