chore: centralize syncthing config

This commit is contained in:
Leon Schwarzäugl 2025-07-21 22:28:48 +02:00
parent e107d0743b
commit 4323aed986
Signed by: swarsel
GPG key ID: 26A54C31F2A4FD84
5 changed files with 200 additions and 356 deletions

View file

@ -1,6 +1,7 @@
{ lib, config, pkgs, ... }:
let
inherit (config.swarselsystems) mainUser homeDir;
devices = config.swarselsystems.syncthing.syncDevices;
in
{
options.swarselmodules.syncthing = lib.mkEnableOption "syncthing config";
@ -18,39 +19,26 @@ in
options = {
urAccepted = -1;
};
devices = {
"magicant" = {
id = "VMWGEE2-4HDS2QO-KNQOVGN-LXLX6LA-666E4EK-ZBRYRRO-XFEX6FB-6E3XLQO";
};
"sync@oracle" = {
id = "ETW6TST-NPK7MKZ-M4LXMHA-QUPQHDT-VTSHH5X-CR5EIN2-YU7E55F-MGT7DQB";
};
"winters" = {
id = "O7RWDMD-AEAHPP7-7TAVLKZ-BSWNBTU-2VA44MS-EYGUNBB-SLHKB3C-ZSLMOAA";
};
"moonside@oracle" = {
id = "VPCDZB6-MGVGQZD-Q6DIZW3-IZJRJTO-TCC3QUQ-2BNTL7P-AKE7FBO-N55UNQE";
};
};
inherit (config.swarselsystems.syncthing) devices;
folders = {
"Default Folder" = lib.mkDefault {
path = "${homeDir}/Sync";
devices = [ "sync@oracle" "magicant" "winters" "moonside@oracle" ];
inherit devices;
id = "default";
};
"Obsidian" = {
path = "${homeDir}/Nextcloud/Obsidian";
devices = [ "sync@oracle" "magicant" "winters" "moonside@oracle" ];
inherit devices;
id = "yjvni-9eaa7";
};
"Org" = {
path = "${homeDir}/Nextcloud/Org";
devices = [ "sync@oracle" "magicant" "winters" "moonside@oracle" ];
inherit devices;
id = "a7xnl-zjj3d";
};
"Vpn" = {
path = "${homeDir}/Vpn";
devices = [ "sync@oracle" "magicant" "winters" "moonside@oracle" ];
inherit devices;
id = "hgp9s-fyq3p";
};
};

View file

@ -1,17 +1,52 @@
{ lib, config, ... }:
{ lib, config, configName, ... }:
let
inherit (config.repo.secrets.common) workHostName;
servicePort = 8384;
serviceUser = "syncthing";
serviceGroup = serviceUser;
serviceName = "syncthing";
serviceDomain = config.repo.secrets.common.services.domains.syncthing1;
specificServiceName = "syncthing-${configName}";
inherit (config.swarselsystems.syncthing) serviceDomain;
inherit (config.swarselsystems.syncthing) serviceIP;
cfg = config.services.${serviceName};
devices = config.swarselsystems.syncthing.syncDevices;
in
{
options.swarselmodules.server.${serviceName} = lib.mkEnableOption "enable ${serviceName} on server";
options = {
swarselmodules.server.${serviceName} = lib.mkEnableOption "enable ${serviceName} on server";
swarselsystems.syncthing = {
serviceDomain = lib.mkOption {
type = lib.types.str;
default = config.repo.secrets.common.services.domains.syncthing1;
};
serviceIP = lib.mkOption {
type = lib.types.str;
default = "192.168.1.2";
};
syncDevices = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ "magicant" "winters" "pyramid" "moonside@oracle" ];
};
devices = lib.mkOption {
type = lib.types.attrs;
default = {
"magicant" = {
id = "VMWGEE2-4HDS2QO-KNQOVGN-LXLX6LA-666E4EK-ZBRYRRO-XFEX6FB-6E3XLQO";
};
"winters" = {
id = "O7RWDMD-AEAHPP7-7TAVLKZ-BSWNBTU-2VA44MS-EYGUNBB-SLHKB3C-ZSLMOAA";
};
"moonside@oracle" = {
id = "VPCDZB6-MGVGQZD-Q6DIZW3-IZJRJTO-TCC3QUQ-2BNTL7P-AKE7FBO-N55UNQE";
};
"pyramid" = {
id = "YAPV4BV-I26WPTN-SIP32MV-SQP5TBZ-3CHMTCI-Z3D6EP2-MNDQGLP-53FT3AB";
};
};
};
};
};
config = lib.mkIf config.swarselmodules.server.${serviceName} {
users.users.${serviceUser} = {
@ -24,39 +59,26 @@ in
networking.firewall.allowedTCPPorts = [ servicePort ];
globals.services."${serviceName}-${config.networking.hostName}".domain = serviceDomain;
globals.services."${specificServiceName}".domain = serviceDomain;
services.${serviceName} = rec {
enable = true;
user = serviceUser;
group = serviceGroup;
dataDir = "/Vault/data/${serviceName}";
dataDir = lib.mkDefault "/Vault/data/${serviceName}";
configDir = "${cfg.dataDir}/.config/${serviceName}";
guiAddress = "0.0.0.0:${builtins.toString servicePort}";
openDefaultPorts = true; # opens ports TCP/UDP 22000 and UDP 21027 for discovery
relay.enable = false;
settings = {
urAccepted = -1;
devices = {
"magicant" = {
id = "VMWGEE2-4HDS2QO-KNQOVGN-LXLX6LA-666E4EK-ZBRYRRO-XFEX6FB-6E3XLQO";
};
"milkywell@oracle" = {
id = "ETW6TST-NPK7MKZ-M4LXMHA-QUPQHDT-VTSHH5X-CR5EIN2-YU7E55F-MGT7DQB";
};
"${workHostName}" = {
id = "YAPV4BV-I26WPTN-SIP32MV-SQP5TBZ-3CHMTCI-Z3D6EP2-MNDQGLP-53FT3AB";
};
"moonside@oracle" = {
id = "VPCDZB6-MGVGQZD-Q6DIZW3-IZJRJTO-TCC3QUQ-2BNTL7P-AKE7FBO-N55UNQE";
};
};
inherit (config.swarselsystems.syncthing) devices;
folders = {
"Default Folder" = lib.mkForce {
path = "${cfg.dataDir}/Sync";
type = "receiveonly";
versioning = null;
devices = [ "milkywell@oracle" "magicant" "${workHostName}" "moonside@oracle" ];
inherit devices;
id = "default";
};
"Obsidian" = {
@ -66,7 +88,7 @@ in
type = "simple";
params.keep = "5";
};
devices = [ "milkywell@oracle" "magicant" "${workHostName}" "moonside@oracle" ];
inherit devices;
id = "yjvni-9eaa7";
};
"Org" = {
@ -76,7 +98,7 @@ in
type = "simple";
params.keep = "5";
};
devices = [ "milkywell@oracle" "magicant" "${workHostName}" "moonside@oracle" ];
inherit devices;
id = "a7xnl-zjj3d";
};
"Vpn" = {
@ -86,28 +108,18 @@ in
type = "simple";
params.keep = "5";
};
devices = [ "milkywell@oracle" "magicant" "${workHostName}" "moonside@oracle" ];
inherit devices;
id = "hgp9s-fyq3p";
};
# "Documents" = {
# path = "${cfg.dataDir}/Documents";
# type = "receiveonly";
# versioning = {
# type = "simple";
# params.keep = "5";
# };
# devices = [ "magicant" "${workHostName}" "moonside@oracle" ];
# id = "hgr3d-pfu3w";
# };
};
};
};
nodes.moonside.services.nginx = {
upstreams = {
${serviceName} = {
${specificServiceName} = {
servers = {
"192.168.1.2:${builtins.toString servicePort}" = { };
"${serviceIP}:${builtins.toString servicePort}" = { };
};
};
};
@ -118,7 +130,7 @@ in
acmeRoot = null;
locations = {
"/" = {
proxyPass = "http://${serviceName}";
proxyPass = "http://${specificServiceName}";
extraConfig = ''
client_max_body_size 0;
'';