dots/modules/nixos/features/syncthing.nix
2025-09-29 22:47:18 +10:00

102 lines
2.3 KiB
Nix

{
config,
lib,
pkgs,
userName,
hostName,
...
}:
let
feature = "syncthing";
port = "5008";
devicesList = [
# keep-sorted start block=yes
{
device = "desktop";
id = "SKDADYB-DQVC2EG-BZ67OJR-DO25ZUR-URP2G5U-FXRNC65-OWPEKHN-STTRRQG";
}
{
device = "laptop";
id = "XDDGWB2-5OFYWSY-7LN652V-3WNQMWV-4WCVHCR-2EXLDW7-FUL2MC4-MMLO4QV";
}
{
device = "phone";
id = "DF56S5M-2EDKAML-LZBB35J-MNNK7UE-WAYE2QW-EKUGKXN-U5JW3RX-S3FUGA4";
}
{
device = "server";
id = "OP7EU3A-7A4CCMY-D4T3ND7-YWMRBNJ-KVE34FG-ZJQFSLS-WMLRWB4-FL2O7AZ";
}
# keep-sorted end
];
devices = builtins.listToAttrs (
map (
{ device, id }:
{
name = device;
value = {
addresses = [
"tcp://${device}:22000"
];
autoAcceptFolders = true;
inherit id;
};
}
) (builtins.filter (deviceSet: deviceSet.device != hostName) devicesList)
);
in
{
config = lib.mkIf config.${feature}.enable {
services = {
# service
syncthing = {
enable = true;
guiAddress = "0.0.0.0:${port}";
openDefaultPorts = true;
user = "${userName}";
dataDir = "/home/${userName}";
overrideDevices = true;
settings = {
inherit devices;
};
};
# backup
borgbackup.jobs =
# we only need one syncthing host to be backed up
# choose server because borgbackup is the most fleshed out
# on srv currently
if userName == "srv" then
import ../backup.nix feature
{
paths = [
"/home/srv/.config/syncthing"
"/home/srv/Sync"
];
}
{
inherit config;
inherit lib;
inherit pkgs;
}
else
null;
# reverse proxy
nginx = {
virtualHosts."${feature}.fi33.buzz" = {
forceSSL = true;
useACMEHost = "fi33.buzz";
locations."/" = {
proxyPass = "http://localhost:${port}";
# proxyWebsockets = true;
};
};
};
};
};
options.${feature}.enable = lib.mkEnableOption "enables ${feature}";
}