From 80d544b9ed2ffa73627e1908b4102a71b1dbc7f2 Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Sun, 8 Dec 2024 07:17:06 +0300 Subject: [PATCH] Syncthing: Add document dir. --- config/Syncthing.nix | 62 ++++++++++++++++++++++++++++---------------- option/Syncthing.nix | 60 ++++++++++++++++-------------------------- 2 files changed, 62 insertions(+), 60 deletions(-) diff --git a/config/Syncthing.nix b/config/Syncthing.nix index 131d7729..b04c5d0a 100644 --- a/config/Syncthing.nix +++ b/config/Syncthing.nix @@ -1,32 +1,50 @@ { config, lib, + pkgs, ... }: let cfg = config.module.syncthing; in { - # NOTE: Access at `http://localhost:8384`. - options.module.syncthing = { - enable = lib.mkEnableOption "the file sync."; - dataDir = lib.mkOption { - default = "/home/${cfg.user}/sync"; - type = lib.types.str; - }; - settings = lib.mkOption { - default = { }; - type = lib.types.attrs; - }; - user = lib.mkOption { - default = "voronind"; - type = lib.types.str; - }; - group = lib.mkOption { - default = "users"; - type = lib.types.str; - }; - openDefaultPorts = lib.mkOption { - default = true; - type = lib.types.bool; + config = lib.mkIf cfg.enable { + environment.systemPackages = with pkgs; [ syncthing ]; + services.syncthing = { + inherit (cfg) enable dataDir user group openDefaultPorts; + systemService = true; + settings = lib.recursiveUpdate cfg.settings { + devices = { + "desktop" = { id = "767Z675-SOCY4FL-JNYEBB6-5E2RG5O-XTZR6OP-BGOBZ7G-XVRLMD6-DQEB2AT"; }; + "home" = { id = "L5A5IPE-2FPJPHP-RJRV2PV-BLMLC3F-QPHSCUQ-4U3NM2I-AFPOE2A-HOPQZQF"; }; + "phone" = { id = "6RO5JXW-2XO4S3E-VCDAHPD-4ADK6LL-HQGMZHU-GD6DE2O-6KNHWXJ-BCSBGQ7"; }; + }; + folders = let + everyone = lib.mapAttrsToList (n: v: n) config.services.syncthing.settings.devices; + in { + "save" = { + path = "${cfg.dataDir}/save"; + devices = [ + "desktop" + "home" + # "work" + ]; + }; + "photo" = { + path = "${cfg.dataDir}/photo"; + devices = [ + "home" + "phone" + ]; + }; + "tmp" = { + path = "${cfg.dataDir}/tmp"; + devices = everyone; + }; + "document" = { + path = "${cfg.dataDir}/document"; + devices = everyone; + }; + }; + }; }; }; } diff --git a/option/Syncthing.nix b/option/Syncthing.nix index 8554dac8..131d7729 100644 --- a/option/Syncthing.nix +++ b/option/Syncthing.nix @@ -1,48 +1,32 @@ { config, lib, - pkgs, ... }: let cfg = config.module.syncthing; in { - config = lib.mkIf cfg.enable { - environment.systemPackages = with pkgs; [ syncthing ]; - services.syncthing = { - inherit (cfg) enable dataDir user group openDefaultPorts; - systemService = true; - settings = lib.recursiveUpdate { - devices = { - "desktop" = { id = "767Z675-SOCY4FL-JNYEBB6-5E2RG5O-XTZR6OP-BGOBZ7G-XVRLMD6-DQEB2AT"; }; - "home" = { id = "L5A5IPE-2FPJPHP-RJRV2PV-BLMLC3F-QPHSCUQ-4U3NM2I-AFPOE2A-HOPQZQF"; }; - "phone" = { id = "6RO5JXW-2XO4S3E-VCDAHPD-4ADK6LL-HQGMZHU-GD6DE2O-6KNHWXJ-BCSBGQ7"; }; - }; - folders = { - "save" = { - path = "${cfg.dataDir}/save"; - devices = [ - "desktop" - "home" - # "work" - ]; - }; - "photo" = { - path = "${cfg.dataDir}/photo"; - devices = [ - "home" - "phone" - ]; - }; - "tmp" = { - path = "${cfg.dataDir}/tmp"; - devices = [ - "desktop" - "home" - "phone" - ]; - }; - }; - } cfg.settings; + # NOTE: Access at `http://localhost:8384`. + options.module.syncthing = { + enable = lib.mkEnableOption "the file sync."; + dataDir = lib.mkOption { + default = "/home/${cfg.user}/sync"; + type = lib.types.str; + }; + settings = lib.mkOption { + default = { }; + type = lib.types.attrs; + }; + user = lib.mkOption { + default = "voronind"; + type = lib.types.str; + }; + group = lib.mkOption { + default = "users"; + type = lib.types.str; + }; + openDefaultPorts = lib.mkOption { + default = true; + type = lib.types.bool; }; }; }