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

@ -2665,12 +2665,10 @@ This machine mainly acts as an external sync helper. It manages the following th
:END: :END:
#+begin_src nix-ts :tangle hosts/nixos/moonside/default.nix #+begin_src nix-ts :tangle hosts/nixos/moonside/default.nix
{ lib, config, globals, ... }: { lib, config, ... }:
let let
inherit (config.repo.secrets.common) workHostName;
inherit (config.repo.secrets.local.syncthing) dev1 dev2 dev3 loc1; inherit (config.repo.secrets.local.syncthing) dev1 dev2 dev3 loc1;
inherit (config.swarselsystems) sopsFile; inherit (config.swarselsystems) sopsFile;
serviceDomain = config.repo.secrets.common.services.domains.syncthing3;
in in
{ {
imports = [ imports = [
@ -2693,15 +2691,6 @@ This machine mainly acts as an external sync helper. It manages the following th
environment = { environment = {
etc."issue".text = "\4"; etc."issue".text = "\4";
persistence."/persist".directories = lib.mkIf config.swarselsystems.isImpermanence [
{
directory = "/var/lib/syncthing";
user = "syncthing";
group = "syncthing";
mode = "0700";
}
];
}; };
topology.self.interfaces.wg = { topology.self.interfaces.wg = {
@ -2748,122 +2737,50 @@ This machine mainly acts as an external sync helper. It manages the following th
system.stateVersion = "23.11"; system.stateVersion = "23.11";
globals.services."syncthing-${config.networking.hostName}".domain = serviceDomain; services.syncthing = {
dataDir = lib.mkForce "/sync";
services = { settings = {
nginx = { devices = config.swarselsystems.syncthing.devices // {
virtualHosts = { "${dev1}" = {
${serviceDomain} = { id = "OCCDGDF-IPZ6HHQ-5SSLQ3L-MSSL5ZW-IX5JTAM-PW4PYEK-BRNMJ7E-Q7YDMA7";
enableACME = true; };
forceSSL = true; "${dev2}" = {
acmeRoot = null; id = "LPCFIIB-ENUM2V6-F2BWVZ6-F2HXCL2-BSBZXUF-TIMNKYB-7CATP7H-YU5D3AH";
locations = { };
"/" = { "${dev3}" = {
proxyPass = "http://localhost:8384"; id = "LAUT2ZP-KEZY35H-AHR3ARD-URAREJI-2B22P5T-PIMUNWW-PQRDETU-7KIGNQR";
extraConfig = ''
client_max_body_size 0;
'';
};
};
}; };
}; };
}; folders = {
"Documents" = {
syncthing = { path = "/sync/Documents";
enable = true; type = "receiveonly";
guiAddress = "0.0.0.0:8384"; versioning = {
openDefaultPorts = true; type = "simple";
relay.enable = false; params.keep = "2";
settings = {
urAccepted = -1;
devices = {
"magicant" = {
id = "VMWGEE2-4HDS2QO-KNQOVGN-LXLX6LA-666E4EK-ZBRYRRO-XFEX6FB-6E3XLQO";
};
"winters" = {
id = "O7RWDMD-AEAHPP7-7TAVLKZ-BSWNBTU-2VA44MS-EYGUNBB-SLHKB3C-ZSLMOAA";
};
"${workHostName}" = {
id = "YAPV4BV-I26WPTN-SIP32MV-SQP5TBZ-3CHMTCI-Z3D6EP2-MNDQGLP-53FT3AB";
};
"${dev1}" = {
id = "OCCDGDF-IPZ6HHQ-5SSLQ3L-MSSL5ZW-IX5JTAM-PW4PYEK-BRNMJ7E-Q7YDMA7";
};
"${dev2}" = {
id = "LPCFIIB-ENUM2V6-F2BWVZ6-F2HXCL2-BSBZXUF-TIMNKYB-7CATP7H-YU5D3AH";
};
"${dev3}" = {
id = "LAUT2ZP-KEZY35H-AHR3ARD-URAREJI-2B22P5T-PIMUNWW-PQRDETU-7KIGNQR";
}; };
devices = [ "pyramid" ];
id = "hgr3d-pfu3w";
}; };
folders = { "runandbun" = {
"Default Folder" = lib.mkForce { path = "/sync/runandbun";
path = "/sync/Sync"; type = "receiveonly";
type = "receiveonly"; versioning = {
versioning = null; type = "simple";
devices = [ "winters" "magicant" "${workHostName}" ]; params.keep = "5";
id = "default";
}; };
"Obsidian" = { devices = [ "winters" "magicant" ];
path = "/sync/Obsidian"; id = "kwnql-ev64v";
type = "receiveonly"; };
versioning = { "${loc1}" = {
type = "simple"; path = "/sync/${loc1}";
params.keep = "5"; type = "receiveonly";
}; versioning = {
devices = [ "winters" "magicant" "${workHostName}" ]; type = "simple";
id = "yjvni-9eaa7"; params.keep = "3";
};
"Org" = {
path = "/sync/Org";
type = "receiveonly";
versioning = {
type = "simple";
params.keep = "5";
};
devices = [ "winters" "magicant" "${workHostName}" ];
id = "a7xnl-zjj3d";
};
"Vpn" = {
path = "/sync/Vpn";
type = "receiveonly";
versioning = {
type = "simple";
params.keep = "5";
};
devices = [ "winters" "magicant" "${workHostName}" ];
id = "hgp9s-fyq3p";
};
"Documents" = {
path = "/sync/Documents";
type = "receiveonly";
versioning = {
type = "simple";
params.keep = "2";
};
devices = [ "winters" ];
id = "hgr3d-pfu3w";
};
"runandbun" = {
path = "/sync/runandbun";
type = "receiveonly";
versioning = {
type = "simple";
params.keep = "5";
};
devices = [ "winters" "magicant" ];
id = "kwnql-ev64v";
};
"${loc1}" = {
path = "/sync/${loc1}";
type = "receiveonly";
versioning = {
type = "simple";
params.keep = "3";
};
devices = [ dev1 dev2 dev3 ];
id = "5gsxv-rzzst";
}; };
devices = [ dev1 dev2 dev3 ];
id = "5gsxv-rzzst";
}; };
}; };
}; };
@ -2883,6 +2800,10 @@ This machine mainly acts as an external sync helper. It manages the following th
isBtrfs = true; isBtrfs = true;
isNixos = true; isNixos = true;
isLinux = true; isLinux = true;
syncthing = {
serviceDomain = config.repo.secrets.common.services.domains.syncthing3;
serviceIP = "localhost";
};
}; };
} }
@ -5189,6 +5110,7 @@ Here I disable global completion to prevent redundant compinit calls and cache i
{ lib, config, pkgs, ... }: { lib, config, pkgs, ... }:
let let
inherit (config.swarselsystems) mainUser homeDir; inherit (config.swarselsystems) mainUser homeDir;
devices = config.swarselsystems.syncthing.syncDevices;
in in
{ {
options.swarselmodules.syncthing = lib.mkEnableOption "syncthing config"; options.swarselmodules.syncthing = lib.mkEnableOption "syncthing config";
@ -5206,39 +5128,26 @@ Here I disable global completion to prevent redundant compinit calls and cache i
options = { options = {
urAccepted = -1; urAccepted = -1;
}; };
devices = { inherit (config.swarselsystems.syncthing) 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";
};
};
folders = { folders = {
"Default Folder" = lib.mkDefault { "Default Folder" = lib.mkDefault {
path = "${homeDir}/Sync"; path = "${homeDir}/Sync";
devices = [ "sync@oracle" "magicant" "winters" "moonside@oracle" ]; inherit devices;
id = "default"; id = "default";
}; };
"Obsidian" = { "Obsidian" = {
path = "${homeDir}/Nextcloud/Obsidian"; path = "${homeDir}/Nextcloud/Obsidian";
devices = [ "sync@oracle" "magicant" "winters" "moonside@oracle" ]; inherit devices;
id = "yjvni-9eaa7"; id = "yjvni-9eaa7";
}; };
"Org" = { "Org" = {
path = "${homeDir}/Nextcloud/Org"; path = "${homeDir}/Nextcloud/Org";
devices = [ "sync@oracle" "magicant" "winters" "moonside@oracle" ]; inherit devices;
id = "a7xnl-zjj3d"; id = "a7xnl-zjj3d";
}; };
"Vpn" = { "Vpn" = {
path = "${homeDir}/Vpn"; path = "${homeDir}/Vpn";
devices = [ "sync@oracle" "magicant" "winters" "moonside@oracle" ]; inherit devices;
id = "hgp9s-fyq3p"; id = "hgp9s-fyq3p";
}; };
}; };
@ -7522,20 +7431,55 @@ Also I install Tika and Gotenberg, which are needed to create PDFs out of =.eml=
:END: :END:
#+begin_src nix-ts :tangle modules/nixos/server/syncthing.nix #+begin_src nix-ts :tangle modules/nixos/server/syncthing.nix
{ lib, config, ... }: { lib, config, configName, ... }:
let let
inherit (config.repo.secrets.common) workHostName;
servicePort = 8384; servicePort = 8384;
serviceUser = "syncthing"; serviceUser = "syncthing";
serviceGroup = serviceUser; serviceGroup = serviceUser;
serviceName = "syncthing"; 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}; cfg = config.services.${serviceName};
devices = config.swarselsystems.syncthing.syncDevices;
in 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} { config = lib.mkIf config.swarselmodules.server.${serviceName} {
users.users.${serviceUser} = { users.users.${serviceUser} = {
@ -7548,39 +7492,26 @@ Also I install Tika and Gotenberg, which are needed to create PDFs out of =.eml=
networking.firewall.allowedTCPPorts = [ servicePort ]; networking.firewall.allowedTCPPorts = [ servicePort ];
globals.services."${serviceName}-${config.networking.hostName}".domain = serviceDomain; globals.services."${specificServiceName}".domain = serviceDomain;
services.${serviceName} = rec { services.${serviceName} = rec {
enable = true; enable = true;
user = serviceUser; user = serviceUser;
group = serviceGroup; group = serviceGroup;
dataDir = "/Vault/data/${serviceName}"; dataDir = lib.mkDefault "/Vault/data/${serviceName}";
configDir = "${cfg.dataDir}/.config/${serviceName}"; configDir = "${cfg.dataDir}/.config/${serviceName}";
guiAddress = "0.0.0.0:${builtins.toString servicePort}"; guiAddress = "0.0.0.0:${builtins.toString servicePort}";
openDefaultPorts = true; # opens ports TCP/UDP 22000 and UDP 21027 for discovery openDefaultPorts = true; # opens ports TCP/UDP 22000 and UDP 21027 for discovery
relay.enable = false; relay.enable = false;
settings = { settings = {
urAccepted = -1; urAccepted = -1;
devices = { inherit (config.swarselsystems.syncthing) 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";
};
};
folders = { folders = {
"Default Folder" = lib.mkForce { "Default Folder" = lib.mkForce {
path = "${cfg.dataDir}/Sync"; path = "${cfg.dataDir}/Sync";
type = "receiveonly"; type = "receiveonly";
versioning = null; versioning = null;
devices = [ "milkywell@oracle" "magicant" "${workHostName}" "moonside@oracle" ]; inherit devices;
id = "default"; id = "default";
}; };
"Obsidian" = { "Obsidian" = {
@ -7590,7 +7521,7 @@ Also I install Tika and Gotenberg, which are needed to create PDFs out of =.eml=
type = "simple"; type = "simple";
params.keep = "5"; params.keep = "5";
}; };
devices = [ "milkywell@oracle" "magicant" "${workHostName}" "moonside@oracle" ]; inherit devices;
id = "yjvni-9eaa7"; id = "yjvni-9eaa7";
}; };
"Org" = { "Org" = {
@ -7600,7 +7531,7 @@ Also I install Tika and Gotenberg, which are needed to create PDFs out of =.eml=
type = "simple"; type = "simple";
params.keep = "5"; params.keep = "5";
}; };
devices = [ "milkywell@oracle" "magicant" "${workHostName}" "moonside@oracle" ]; inherit devices;
id = "a7xnl-zjj3d"; id = "a7xnl-zjj3d";
}; };
"Vpn" = { "Vpn" = {
@ -7610,28 +7541,18 @@ Also I install Tika and Gotenberg, which are needed to create PDFs out of =.eml=
type = "simple"; type = "simple";
params.keep = "5"; params.keep = "5";
}; };
devices = [ "milkywell@oracle" "magicant" "${workHostName}" "moonside@oracle" ]; inherit devices;
id = "hgp9s-fyq3p"; 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 = { nodes.moonside.services.nginx = {
upstreams = { upstreams = {
${serviceName} = { ${specificServiceName} = {
servers = { servers = {
"192.168.1.2:${builtins.toString servicePort}" = { }; "${serviceIP}:${builtins.toString servicePort}" = { };
}; };
}; };
}; };
@ -7642,7 +7563,7 @@ Also I install Tika and Gotenberg, which are needed to create PDFs out of =.eml=
acmeRoot = null; acmeRoot = null;
locations = { locations = {
"/" = { "/" = {
proxyPass = "http://${serviceName}"; proxyPass = "http://${specificServiceName}";
extraConfig = '' extraConfig = ''
client_max_body_size 0; client_max_body_size 0;
''; '';
@ -16693,6 +16614,7 @@ Modules that need to be loaded on the NixOS level. Note that these will not be a
microbin = lib.mkDefault true; microbin = lib.mkDefault true;
shlink = lib.mkDefault true; shlink = lib.mkDefault true;
slink = lib.mkDefault true; slink = lib.mkDefault true;
syncthing = lib.mkDefault true;
}; };
}; };
}; };

View file

@ -1,9 +1,7 @@
{ lib, config, globals, ... }: { lib, config, ... }:
let let
inherit (config.repo.secrets.common) workHostName;
inherit (config.repo.secrets.local.syncthing) dev1 dev2 dev3 loc1; inherit (config.repo.secrets.local.syncthing) dev1 dev2 dev3 loc1;
inherit (config.swarselsystems) sopsFile; inherit (config.swarselsystems) sopsFile;
serviceDomain = config.repo.secrets.common.services.domains.syncthing3;
in in
{ {
imports = [ imports = [
@ -26,15 +24,6 @@ in
environment = { environment = {
etc."issue".text = "\4"; etc."issue".text = "\4";
persistence."/persist".directories = lib.mkIf config.swarselsystems.isImpermanence [
{
directory = "/var/lib/syncthing";
user = "syncthing";
group = "syncthing";
mode = "0700";
}
];
}; };
topology.self.interfaces.wg = { topology.self.interfaces.wg = {
@ -81,122 +70,50 @@ in
system.stateVersion = "23.11"; system.stateVersion = "23.11";
globals.services."syncthing-${config.networking.hostName}".domain = serviceDomain; services.syncthing = {
dataDir = lib.mkForce "/sync";
services = { settings = {
nginx = { devices = config.swarselsystems.syncthing.devices // {
virtualHosts = { "${dev1}" = {
${serviceDomain} = { id = "OCCDGDF-IPZ6HHQ-5SSLQ3L-MSSL5ZW-IX5JTAM-PW4PYEK-BRNMJ7E-Q7YDMA7";
enableACME = true; };
forceSSL = true; "${dev2}" = {
acmeRoot = null; id = "LPCFIIB-ENUM2V6-F2BWVZ6-F2HXCL2-BSBZXUF-TIMNKYB-7CATP7H-YU5D3AH";
locations = { };
"/" = { "${dev3}" = {
proxyPass = "http://localhost:8384"; id = "LAUT2ZP-KEZY35H-AHR3ARD-URAREJI-2B22P5T-PIMUNWW-PQRDETU-7KIGNQR";
extraConfig = ''
client_max_body_size 0;
'';
};
};
}; };
}; };
}; folders = {
"Documents" = {
syncthing = { path = "/sync/Documents";
enable = true; type = "receiveonly";
guiAddress = "0.0.0.0:8384"; versioning = {
openDefaultPorts = true; type = "simple";
relay.enable = false; params.keep = "2";
settings = {
urAccepted = -1;
devices = {
"magicant" = {
id = "VMWGEE2-4HDS2QO-KNQOVGN-LXLX6LA-666E4EK-ZBRYRRO-XFEX6FB-6E3XLQO";
};
"winters" = {
id = "O7RWDMD-AEAHPP7-7TAVLKZ-BSWNBTU-2VA44MS-EYGUNBB-SLHKB3C-ZSLMOAA";
};
"${workHostName}" = {
id = "YAPV4BV-I26WPTN-SIP32MV-SQP5TBZ-3CHMTCI-Z3D6EP2-MNDQGLP-53FT3AB";
};
"${dev1}" = {
id = "OCCDGDF-IPZ6HHQ-5SSLQ3L-MSSL5ZW-IX5JTAM-PW4PYEK-BRNMJ7E-Q7YDMA7";
};
"${dev2}" = {
id = "LPCFIIB-ENUM2V6-F2BWVZ6-F2HXCL2-BSBZXUF-TIMNKYB-7CATP7H-YU5D3AH";
};
"${dev3}" = {
id = "LAUT2ZP-KEZY35H-AHR3ARD-URAREJI-2B22P5T-PIMUNWW-PQRDETU-7KIGNQR";
}; };
devices = [ "pyramid" ];
id = "hgr3d-pfu3w";
}; };
folders = { "runandbun" = {
"Default Folder" = lib.mkForce { path = "/sync/runandbun";
path = "/sync/Sync"; type = "receiveonly";
type = "receiveonly"; versioning = {
versioning = null; type = "simple";
devices = [ "winters" "magicant" "${workHostName}" ]; params.keep = "5";
id = "default";
}; };
"Obsidian" = { devices = [ "winters" "magicant" ];
path = "/sync/Obsidian"; id = "kwnql-ev64v";
type = "receiveonly"; };
versioning = { "${loc1}" = {
type = "simple"; path = "/sync/${loc1}";
params.keep = "5"; type = "receiveonly";
}; versioning = {
devices = [ "winters" "magicant" "${workHostName}" ]; type = "simple";
id = "yjvni-9eaa7"; params.keep = "3";
};
"Org" = {
path = "/sync/Org";
type = "receiveonly";
versioning = {
type = "simple";
params.keep = "5";
};
devices = [ "winters" "magicant" "${workHostName}" ];
id = "a7xnl-zjj3d";
};
"Vpn" = {
path = "/sync/Vpn";
type = "receiveonly";
versioning = {
type = "simple";
params.keep = "5";
};
devices = [ "winters" "magicant" "${workHostName}" ];
id = "hgp9s-fyq3p";
};
"Documents" = {
path = "/sync/Documents";
type = "receiveonly";
versioning = {
type = "simple";
params.keep = "2";
};
devices = [ "winters" ];
id = "hgr3d-pfu3w";
};
"runandbun" = {
path = "/sync/runandbun";
type = "receiveonly";
versioning = {
type = "simple";
params.keep = "5";
};
devices = [ "winters" "magicant" ];
id = "kwnql-ev64v";
};
"${loc1}" = {
path = "/sync/${loc1}";
type = "receiveonly";
versioning = {
type = "simple";
params.keep = "3";
};
devices = [ dev1 dev2 dev3 ];
id = "5gsxv-rzzst";
}; };
devices = [ dev1 dev2 dev3 ];
id = "5gsxv-rzzst";
}; };
}; };
}; };
@ -216,5 +133,9 @@ in
isBtrfs = true; isBtrfs = true;
isNixos = true; isNixos = true;
isLinux = true; isLinux = true;
syncthing = {
serviceDomain = config.repo.secrets.common.services.domains.syncthing3;
serviceIP = "localhost";
};
}; };
} }

View file

@ -1,6 +1,7 @@
{ lib, config, pkgs, ... }: { lib, config, pkgs, ... }:
let let
inherit (config.swarselsystems) mainUser homeDir; inherit (config.swarselsystems) mainUser homeDir;
devices = config.swarselsystems.syncthing.syncDevices;
in in
{ {
options.swarselmodules.syncthing = lib.mkEnableOption "syncthing config"; options.swarselmodules.syncthing = lib.mkEnableOption "syncthing config";
@ -18,39 +19,26 @@ in
options = { options = {
urAccepted = -1; urAccepted = -1;
}; };
devices = { inherit (config.swarselsystems.syncthing) 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";
};
};
folders = { folders = {
"Default Folder" = lib.mkDefault { "Default Folder" = lib.mkDefault {
path = "${homeDir}/Sync"; path = "${homeDir}/Sync";
devices = [ "sync@oracle" "magicant" "winters" "moonside@oracle" ]; inherit devices;
id = "default"; id = "default";
}; };
"Obsidian" = { "Obsidian" = {
path = "${homeDir}/Nextcloud/Obsidian"; path = "${homeDir}/Nextcloud/Obsidian";
devices = [ "sync@oracle" "magicant" "winters" "moonside@oracle" ]; inherit devices;
id = "yjvni-9eaa7"; id = "yjvni-9eaa7";
}; };
"Org" = { "Org" = {
path = "${homeDir}/Nextcloud/Org"; path = "${homeDir}/Nextcloud/Org";
devices = [ "sync@oracle" "magicant" "winters" "moonside@oracle" ]; inherit devices;
id = "a7xnl-zjj3d"; id = "a7xnl-zjj3d";
}; };
"Vpn" = { "Vpn" = {
path = "${homeDir}/Vpn"; path = "${homeDir}/Vpn";
devices = [ "sync@oracle" "magicant" "winters" "moonside@oracle" ]; inherit devices;
id = "hgp9s-fyq3p"; id = "hgp9s-fyq3p";
}; };
}; };

View file

@ -1,17 +1,52 @@
{ lib, config, ... }: { lib, config, configName, ... }:
let let
inherit (config.repo.secrets.common) workHostName;
servicePort = 8384; servicePort = 8384;
serviceUser = "syncthing"; serviceUser = "syncthing";
serviceGroup = serviceUser; serviceGroup = serviceUser;
serviceName = "syncthing"; 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}; cfg = config.services.${serviceName};
devices = config.swarselsystems.syncthing.syncDevices;
in 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} { config = lib.mkIf config.swarselmodules.server.${serviceName} {
users.users.${serviceUser} = { users.users.${serviceUser} = {
@ -24,39 +59,26 @@ in
networking.firewall.allowedTCPPorts = [ servicePort ]; networking.firewall.allowedTCPPorts = [ servicePort ];
globals.services."${serviceName}-${config.networking.hostName}".domain = serviceDomain; globals.services."${specificServiceName}".domain = serviceDomain;
services.${serviceName} = rec { services.${serviceName} = rec {
enable = true; enable = true;
user = serviceUser; user = serviceUser;
group = serviceGroup; group = serviceGroup;
dataDir = "/Vault/data/${serviceName}"; dataDir = lib.mkDefault "/Vault/data/${serviceName}";
configDir = "${cfg.dataDir}/.config/${serviceName}"; configDir = "${cfg.dataDir}/.config/${serviceName}";
guiAddress = "0.0.0.0:${builtins.toString servicePort}"; guiAddress = "0.0.0.0:${builtins.toString servicePort}";
openDefaultPorts = true; # opens ports TCP/UDP 22000 and UDP 21027 for discovery openDefaultPorts = true; # opens ports TCP/UDP 22000 and UDP 21027 for discovery
relay.enable = false; relay.enable = false;
settings = { settings = {
urAccepted = -1; urAccepted = -1;
devices = { inherit (config.swarselsystems.syncthing) 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";
};
};
folders = { folders = {
"Default Folder" = lib.mkForce { "Default Folder" = lib.mkForce {
path = "${cfg.dataDir}/Sync"; path = "${cfg.dataDir}/Sync";
type = "receiveonly"; type = "receiveonly";
versioning = null; versioning = null;
devices = [ "milkywell@oracle" "magicant" "${workHostName}" "moonside@oracle" ]; inherit devices;
id = "default"; id = "default";
}; };
"Obsidian" = { "Obsidian" = {
@ -66,7 +88,7 @@ in
type = "simple"; type = "simple";
params.keep = "5"; params.keep = "5";
}; };
devices = [ "milkywell@oracle" "magicant" "${workHostName}" "moonside@oracle" ]; inherit devices;
id = "yjvni-9eaa7"; id = "yjvni-9eaa7";
}; };
"Org" = { "Org" = {
@ -76,7 +98,7 @@ in
type = "simple"; type = "simple";
params.keep = "5"; params.keep = "5";
}; };
devices = [ "milkywell@oracle" "magicant" "${workHostName}" "moonside@oracle" ]; inherit devices;
id = "a7xnl-zjj3d"; id = "a7xnl-zjj3d";
}; };
"Vpn" = { "Vpn" = {
@ -86,28 +108,18 @@ in
type = "simple"; type = "simple";
params.keep = "5"; params.keep = "5";
}; };
devices = [ "milkywell@oracle" "magicant" "${workHostName}" "moonside@oracle" ]; inherit devices;
id = "hgp9s-fyq3p"; 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 = { nodes.moonside.services.nginx = {
upstreams = { upstreams = {
${serviceName} = { ${specificServiceName} = {
servers = { servers = {
"192.168.1.2:${builtins.toString servicePort}" = { }; "${serviceIP}:${builtins.toString servicePort}" = { };
}; };
}; };
}; };
@ -118,7 +130,7 @@ in
acmeRoot = null; acmeRoot = null;
locations = { locations = {
"/" = { "/" = {
proxyPass = "http://${serviceName}"; proxyPass = "http://${specificServiceName}";
extraConfig = '' extraConfig = ''
client_max_body_size 0; client_max_body_size 0;
''; '';

View file

@ -21,6 +21,7 @@
microbin = lib.mkDefault true; microbin = lib.mkDefault true;
shlink = lib.mkDefault true; shlink = lib.mkDefault true;
slink = lib.mkDefault true; slink = lib.mkDefault true;
syncthing = lib.mkDefault true;
}; };
}; };
}; };