2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2014-04-03 18:54:10 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2014-04-03 18:54:10 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.syncthing;
|
2016-04-01 01:26:52 +02:00
|
|
|
defaultUser = "syncthing";
|
2016-09-26 09:40:21 +02:00
|
|
|
in {
|
2014-04-03 18:54:10 +02:00
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.syncthing = {
|
|
|
|
|
2016-04-14 16:44:02 +02:00
|
|
|
enable = mkEnableOption ''
|
|
|
|
Syncthing - the self-hosted open-source alternative
|
|
|
|
to Dropbox and Bittorrent Sync. Initial interface will be
|
|
|
|
available on http://127.0.0.1:8384/.
|
|
|
|
'';
|
2014-04-03 18:54:10 +02:00
|
|
|
|
2016-04-14 10:42:04 +02:00
|
|
|
systemService = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Auto launch Syncthing as a system service.";
|
|
|
|
};
|
|
|
|
|
2014-04-03 18:54:10 +02:00
|
|
|
user = mkOption {
|
2016-04-01 01:26:52 +02:00
|
|
|
type = types.string;
|
|
|
|
default = defaultUser;
|
2014-04-03 18:54:10 +02:00
|
|
|
description = ''
|
2016-04-14 10:42:04 +02:00
|
|
|
Syncthing will be run under this user (user will be created if it doesn't exist.
|
|
|
|
This can be your user name).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "nogroup";
|
|
|
|
description = ''
|
|
|
|
Syncthing will be run under this group (group will not be created if it doesn't exist.
|
|
|
|
This can be your user name).
|
2014-04-03 18:54:10 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-12-15 13:07:40 +01:00
|
|
|
all_proxy = mkOption {
|
2016-04-01 01:26:52 +02:00
|
|
|
type = types.nullOr types.string;
|
|
|
|
default = null;
|
2015-12-15 13:07:40 +01:00
|
|
|
example = "socks5://address.com:1234";
|
|
|
|
description = ''
|
|
|
|
Overwrites all_proxy environment variable for the syncthing process to
|
|
|
|
the given value. This is normaly used to let relay client connect
|
|
|
|
through SOCKS5 proxy server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-04-03 18:54:10 +02:00
|
|
|
dataDir = mkOption {
|
2016-04-01 01:26:52 +02:00
|
|
|
type = types.path;
|
2014-04-03 18:54:10 +02:00
|
|
|
default = "/var/lib/syncthing";
|
|
|
|
description = ''
|
2015-08-27 16:01:10 +02:00
|
|
|
Path where the settings and keys will exist.
|
2014-04-03 18:54:10 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-09-26 09:40:21 +02:00
|
|
|
openDefaultPorts = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
example = literalExample "true";
|
|
|
|
description = ''
|
|
|
|
Open the default ports in the firewall:
|
|
|
|
- TCP 22000 for transfers
|
|
|
|
- UDP 21027 for discovery
|
|
|
|
If multiple users are running syncthing on this machine, you will need to manually open a set of ports for each instance and leave this disabled.
|
|
|
|
Alternatively, if are running only a single instance on this machine using the default ports, enable this.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-11-28 20:17:49 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.syncthing;
|
2016-01-17 19:34:55 +01:00
|
|
|
defaultText = "pkgs.syncthing";
|
2015-11-28 20:17:49 +01:00
|
|
|
example = literalExample "pkgs.syncthing";
|
|
|
|
description = ''
|
|
|
|
Syncthing package to use.
|
|
|
|
'';
|
|
|
|
};
|
2014-04-03 18:54:10 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-02-23 19:59:06 +01:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule ["services" "syncthing" "useInotify"] ''
|
|
|
|
This option was removed because syncthing now has the inotify functionality included under the name "fswatcher".
|
|
|
|
It can be enabled on a per-folder basis through the webinterface.
|
|
|
|
'')
|
|
|
|
];
|
2014-04-03 18:54:10 +02:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2014-04-04 10:46:19 +02:00
|
|
|
config = mkIf cfg.enable {
|
2014-04-03 18:54:10 +02:00
|
|
|
|
2016-09-26 09:40:21 +02:00
|
|
|
networking.firewall = mkIf cfg.openDefaultPorts {
|
|
|
|
allowedTCPPorts = [ 22000 ];
|
|
|
|
allowedUDPPorts = [ 21027 ];
|
|
|
|
};
|
|
|
|
|
2018-02-23 19:59:06 +01:00
|
|
|
systemd.packages = [ pkgs.syncthing ];
|
2016-09-26 09:40:21 +02:00
|
|
|
|
2016-04-01 01:26:52 +02:00
|
|
|
users = mkIf (cfg.user == defaultUser) {
|
|
|
|
extraUsers."${defaultUser}" =
|
2016-04-14 10:42:04 +02:00
|
|
|
{ group = cfg.group;
|
2016-04-01 01:26:52 +02:00
|
|
|
home = cfg.dataDir;
|
|
|
|
createHome = true;
|
|
|
|
uid = config.ids.uids.syncthing;
|
|
|
|
description = "Syncthing daemon user";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraGroups."${defaultUser}".gid =
|
|
|
|
config.ids.gids.syncthing;
|
|
|
|
};
|
|
|
|
|
2016-08-06 17:20:18 +02:00
|
|
|
systemd.services = {
|
2016-09-26 09:40:21 +02:00
|
|
|
syncthing = mkIf cfg.systemService {
|
|
|
|
description = "Syncthing service";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
environment = {
|
|
|
|
STNORESTART = "yes";
|
|
|
|
STNOUPGRADE = "yes";
|
|
|
|
inherit (cfg) all_proxy;
|
|
|
|
} // config.networking.proxy.envVars;
|
2016-04-14 10:42:04 +02:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-26 09:40:21 +02:00
|
|
|
serviceConfig = {
|
|
|
|
Restart = "on-failure";
|
|
|
|
SuccessExitStatus = "2 3 4";
|
|
|
|
RestartForceExitStatus="3 4";
|
2016-04-14 10:42:04 +02:00
|
|
|
User = cfg.user;
|
2016-09-26 09:40:21 +02:00
|
|
|
Group = cfg.group;
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
ExecStart = "${cfg.package}/bin/syncthing -no-browser -home=${cfg.dataDir}";
|
2014-04-03 18:54:10 +02:00
|
|
|
};
|
2016-09-26 09:40:21 +02:00
|
|
|
};
|
2014-04-03 18:54:10 +02:00
|
|
|
|
2016-09-26 09:40:21 +02:00
|
|
|
syncthing-resume = {
|
|
|
|
wantedBy = [ "suspend.target" ];
|
2016-04-14 10:42:04 +02:00
|
|
|
};
|
2016-08-06 17:20:18 +02:00
|
|
|
};
|
2014-04-03 18:54:10 +02:00
|
|
|
};
|
|
|
|
}
|