{ config, lib, username, ... }: let cfg = config.os.srv.syncthing; syncDirs = lib.mapAttrsToList (_: folder: folder.path) config.services.syncthing.settings.folders; in { options.os.srv.syncthing.enable = lib.mkEnableOption "enables syncthing syncing"; config = lib.mkIf cfg.enable { systemd.tmpfiles.rules = map (path: "d ${path} 0755 ${username} users -") syncDirs; services.syncthing = { enable = true; user = username; dataDir = "/home/${username}/.local/share/syncthing"; configDir = "/home/${username}/.config/syncthing"; guiPasswordFile = config.sops.secrets."syncthing/gui_password".path; settings = { devices."oci".id = "DQXGVDC-KGPM6RK-5NDEBJJ-R7PEWYZ-N6Z3WFZ-TSVJG5X-235SHG4-4BEJNQJ"; folders = { "openmw-config" = { path = "/home/${username}/.config/openmw"; id = "openmw-config"; devices = [ { name = "oci"; encryptionPasswordFile = config.sops.secrets."syncthing/encryption/openmw-config".path; } ]; versioning = { type = "simple"; params.keep = "3"; }; ignorePatterns = [ "settings.cfg" "*.log" ]; }; "openmw-mods" = { path = "/home/${username}/games/openmw"; id = "openmw-mods"; devices = [ { name = "oci"; encryptionPasswordFile = config.sops.secrets."syncthing/encryption/openmw-mods".path; } ]; versioning = { type = "trashcan"; params.cleanoutDays = "7"; }; }; "game-saves" = { path = "/home/${username}/.saves"; id = "game-saves"; devices = [ { name = "oci"; encryptionPasswordFile = config.sops.secrets."syncthing/encryption/game-saves".path; } ]; versioning = { type = "staggered"; params = { cleanInterval = "3600"; maxAge = "2592000"; }; }; }; "keepass" = { path = "/home/${username}/.keepass"; id = "keepass"; devices = [ { name = "oci"; encryptionPasswordFile = config.sops.secrets."syncthing/encryption/keepass".path; } ]; versioning = { type = "simple"; params.keep = "10"; }; }; "sync" = { path = "/home/${username}/sync"; id = "sync"; devices = [ { name = "oci"; encryptionPasswordFile = config.sops.secrets."syncthing/encryption/sync".path; } ]; versioning = { type = "simple"; params.keep = "3"; }; }; }; }; }; }; }