1
0
Fork 0
nix-configuration/modules/nixos/services/syncthing/default.nix

67 lines
1.9 KiB
Nix
Raw Normal View History

# See https://wiki.nixos.org/wiki/Syncthing
2024-12-06 18:04:47 +00:00
{
config,
lib,
namespace,
...
}:
let
2024-12-06 18:04:47 +00:00
cfg = config.${namespace}.services.syncthing;
in
{
options = {
2024-12-06 18:04:47 +00:00
${namespace}.services.syncthing = {
enable = lib.mkEnableOption "Enables Syncthing.";
enableTray = lib.mkEnableOption "Enables the Syncthing Tray applet.";
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 ];
services = {
2024-12-06 18:04:47 +00:00
flatpak.packages = lib.mkIf (config.${namespace}.ui.flatpak.enable && cfg.enableTray) [
"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}";
};
};
systemd.services.syncthing = {
environment.STNODEFAULTFOLDER = "true"; # Don't create default ~/Sync folder
unitConfig.RequiresMountsFor = cfg.home;
};
};
}