2024-12-08 04:04:34 +03:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
2024-12-08 07:17:06 +03:00
|
|
|
pkgs,
|
2024-12-08 22:25:43 +03:00
|
|
|
util,
|
2024-12-08 04:04:34 +03:00
|
|
|
...
|
|
|
|
}: let
|
|
|
|
cfg = config.module.syncthing;
|
|
|
|
in {
|
2024-12-08 07:17:06 +03:00
|
|
|
config = lib.mkIf cfg.enable {
|
2024-12-08 22:25:43 +03:00
|
|
|
# CLI tools.
|
2024-12-08 07:17:06 +03:00
|
|
|
environment.systemPackages = with pkgs; [ syncthing ];
|
2024-12-08 22:25:43 +03:00
|
|
|
|
|
|
|
# Access at sync.lan.
|
|
|
|
networking.hosts = { "127.0.0.1" = [ "sync.local" ]; };
|
|
|
|
services.nginx.enable = true;
|
|
|
|
services.nginx.virtualHosts."sync.local".extraConfig = util.trimTabs ''
|
|
|
|
location / {
|
|
|
|
allow 127.0.0.1;
|
|
|
|
deny all;
|
|
|
|
proxy_pass http://127.0.0.1:8384;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
2024-12-08 07:17:06 +03:00
|
|
|
services.syncthing = {
|
2024-12-08 22:25:43 +03:00
|
|
|
inherit (cfg) enable dataDir user group;
|
|
|
|
openDefaultPorts = false;
|
2024-12-08 07:17:06 +03:00
|
|
|
systemService = true;
|
2024-12-09 23:41:06 +03:00
|
|
|
settings = let
|
|
|
|
myDevices = {
|
2024-12-08 07:17:06 +03:00
|
|
|
"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"; };
|
2024-12-10 02:15:46 +03:00
|
|
|
"work" = { id = "CMG6QMP-WCJJEUG-UQ3KDUI-AHRADRH-666JQ3Z-HYFEPDA-URMAMNP-Z4MSGQT"; };
|
2024-12-08 07:17:06 +03:00
|
|
|
};
|
2024-12-09 23:41:06 +03:00
|
|
|
dashaDevices = {
|
|
|
|
"dasha" = { id = "VNRA5VH-LWNPVV4-Y2RF7FJ-446FHRQ-PET7Q4R-D3H5RT3-AUNARH5-5XYB3AT"; };
|
|
|
|
"dashaphone" = { id = "QKGXSZC-HGAA6S5-RJJAT5Z-UPUGDAA-3GXEO6C-WHKMBUD-ESKQPZE-TZFNYA6"; };
|
|
|
|
};
|
|
|
|
in lib.recursiveUpdate cfg.settings {
|
|
|
|
devices = myDevices // dashaDevices;
|
2024-12-08 07:17:06 +03:00
|
|
|
folders = let
|
2024-12-09 23:41:06 +03:00
|
|
|
allMyDevices = lib.mapAttrsToList (n: v: n) myDevices;
|
|
|
|
allDashaDevices = lib.mapAttrsToList (n: v: n) dashaDevices;
|
2024-12-10 00:36:05 +03:00
|
|
|
in lib.filterAttrs (n: v: builtins.elem config.networking.hostName v.devices) {
|
2024-12-08 07:17:06 +03:00
|
|
|
"save" = {
|
|
|
|
path = "${cfg.dataDir}/save";
|
|
|
|
devices = [
|
|
|
|
"desktop"
|
|
|
|
"home"
|
2024-12-10 02:15:46 +03:00
|
|
|
"work"
|
2024-12-08 07:17:06 +03:00
|
|
|
];
|
|
|
|
};
|
|
|
|
"photo" = {
|
|
|
|
path = "${cfg.dataDir}/photo";
|
|
|
|
devices = [
|
2024-12-09 23:41:06 +03:00
|
|
|
"dashaphone"
|
2024-12-08 07:17:06 +03:00
|
|
|
"home"
|
|
|
|
"phone"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
"tmp" = {
|
|
|
|
path = "${cfg.dataDir}/tmp";
|
2024-12-09 23:41:06 +03:00
|
|
|
devices = allMyDevices;
|
2024-12-08 07:17:06 +03:00
|
|
|
};
|
|
|
|
"document" = {
|
|
|
|
path = "${cfg.dataDir}/document";
|
2024-12-09 23:41:06 +03:00
|
|
|
devices = allMyDevices;
|
|
|
|
};
|
|
|
|
"dima" = {
|
|
|
|
path = "${cfg.dataDir}/dima";
|
|
|
|
devices = allMyDevices ++ allDashaDevices;
|
|
|
|
};
|
|
|
|
"dasha" = {
|
|
|
|
path = "${cfg.dataDir}/dasha";
|
|
|
|
devices = allDashaDevices;
|
2024-12-08 07:17:06 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-12-08 04:04:34 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|