1 { config, lib, pkgs, ... }:
6 cfg = config.services.syncthing.relay;
8 dataDirectory = "/var/lib/syncthing-relay";
12 "--keys=${dataDirectory}"
13 "--listen=${cfg.listenAddress}:${toString cfg.port}"
14 "--status-srv=${cfg.statusListenAddress}:${toString cfg.statusPort}"
15 "--provided-by=${escapeShellArg cfg.providedBy}"
17 ++ optional (cfg.pools != null) "--pools=${escapeShellArg (concatStringsSep "," cfg.pools)}"
18 ++ optional (cfg.globalRateBps != null) "--global-rate=${toString cfg.globalRateBps}"
19 ++ optional (cfg.perSessionRateBps != null) "--per-session-rate=${toString cfg.perSessionRateBps}"
24 options.services.syncthing.relay = {
25 enable = mkEnableOption "Syncthing relay service";
27 listenAddress = mkOption {
32 Address to listen on for relay traffic.
40 Port to listen on for relay traffic. This port should be added to
41 `networking.firewall.allowedTCPPorts`.
45 statusListenAddress = mkOption {
50 Address to listen on for serving the relay status API.
54 statusPort = mkOption {
58 Port to listen on for serving the relay status API. This port should be
59 added to `networking.firewall.allowedTCPPorts`.
64 type = types.nullOr (types.listOf types.str);
67 Relay pools to join. If null, uses the default global pool.
71 providedBy = mkOption {
75 Human-readable description of the provider of the relay (you).
79 globalRateBps = mkOption {
80 type = types.nullOr types.ints.positive;
83 Global bandwidth rate limit in bytes per second.
87 perSessionRateBps = mkOption {
88 type = types.nullOr types.ints.positive;
91 Per session bandwidth rate limit in bytes per second.
95 extraOptions = mkOption {
96 type = types.listOf types.str;
99 Extra command line arguments to pass to strelaysrv.
104 ###### implementation
106 config = mkIf cfg.enable {
107 systemd.services.syncthing-relay = {
108 description = "Syncthing relay service";
109 wantedBy = [ "multi-user.target" ];
110 after = [ "network.target" ];
114 StateDirectory = baseNameOf dataDirectory;
116 Restart = "on-failure";
117 ExecStart = "${pkgs.syncthing-relay}/bin/strelaysrv ${concatStringsSep " " relayOptions}";