2024-11-24 16:38:09 +00:00
|
|
|
# See https://wiki.nixos.org/wiki/Syncthing
|
2024-12-06 18:04:47 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
namespace,
|
|
|
|
...
|
|
|
|
}:
|
2024-11-24 16:38:09 +00:00
|
|
|
|
|
|
|
let
|
2024-12-06 18:04:47 +00:00
|
|
|
cfg = config.${namespace}.services.syncthing;
|
2024-11-24 16:38:09 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2024-12-06 18:04:47 +00:00
|
|
|
${namespace}.services.syncthing = {
|
2024-11-24 18:38:58 +00:00
|
|
|
enable = lib.mkEnableOption "Enables Syncthing.";
|
|
|
|
enableTray = lib.mkEnableOption "Enables the Syncthing Tray applet.";
|
2024-11-24 16:38:09 +00:00
|
|
|
home = lib.mkOption {
|
|
|
|
default = "/var/lib/syncthing";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "Where to store Syncthing's configuration files";
|
|
|
|
};
|
|
|
|
user = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "syncthing";
|
|
|
|
description = "User account under which Syncthing runs.";
|
|
|
|
};
|
|
|
|
web = {
|
|
|
|
enable = lib.mkEnableOption "Enables the Syncthing web UI.";
|
|
|
|
port = lib.mkOption {
|
|
|
|
type = lib.types.int;
|
|
|
|
default = 8384;
|
|
|
|
description = "The port to host Syncthing web on.";
|
|
|
|
};
|
|
|
|
public = lib.mkEnableOption "Whether to expose the Syncthing web UI to the network.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
# If the web UI is public, open the port in the firewall
|
|
|
|
networking.firewall.allowedTCPPorts = with cfg.web; lib.mkIf (enable && public) [ port ];
|
|
|
|
|
2024-11-24 18:38:58 +00:00
|
|
|
services = {
|
2024-12-06 18:04:47 +00:00
|
|
|
flatpak.packages = lib.mkIf (config.${namespace}.ui.flatpak.enable && cfg.enableTray) [
|
2024-11-24 18:38:58 +00:00
|
|
|
"io.github.martchus.syncthingtray"
|
|
|
|
];
|
|
|
|
|
|
|
|
syncthing = {
|
|
|
|
enable = true;
|
|
|
|
user = cfg.user;
|
|
|
|
group = config.users.users.${cfg.user}.group;
|
|
|
|
configDir = cfg.home;
|
|
|
|
guiAddress =
|
|
|
|
let
|
|
|
|
listenAddress = with cfg.web; (if (enable && public) then "0.0.0.0" else "127.0.0.1");
|
|
|
|
in
|
|
|
|
"${listenAddress}:${builtins.toString cfg.web.port}";
|
|
|
|
};
|
2024-11-24 16:38:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.syncthing = {
|
|
|
|
environment.STNODEFAULTFOLDER = "true"; # Don't create default ~/Sync folder
|
|
|
|
unitConfig.RequiresMountsFor = cfg.home;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|