2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2014-04-03 17:54:10 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2014-04-03 17:54:10 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.syncthing;
|
2016-04-01 00:26:52 +01:00
|
|
|
defaultUser = "syncthing";
|
2014-04-03 17:54:10 +01:00
|
|
|
|
2016-04-14 09:42:04 +01:00
|
|
|
header = {
|
|
|
|
description = "Syncthing service";
|
2016-07-21 03:49:58 +01:00
|
|
|
after = [ "network.target" ];
|
2016-04-14 09:42:04 +01:00
|
|
|
environment = {
|
|
|
|
STNORESTART = "yes";
|
|
|
|
STNOUPGRADE = "yes";
|
|
|
|
inherit (cfg) all_proxy;
|
|
|
|
} // config.networking.proxy.envVars;
|
|
|
|
};
|
|
|
|
|
|
|
|
service = {
|
|
|
|
Restart = "on-failure";
|
|
|
|
SuccessExitStatus = "2 3 4";
|
|
|
|
RestartForceExitStatus="3 4";
|
|
|
|
};
|
|
|
|
|
2016-08-06 16:20:18 +01:00
|
|
|
iNotifyHeader = {
|
|
|
|
description = "Syncthing Inotify File Watcher service";
|
|
|
|
after = [ "network.target" "syncthing.service" ];
|
|
|
|
requires = [ "syncthing.service" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
iNotifyService = {
|
|
|
|
SuccessExitStatus = "2";
|
|
|
|
RestartForceExitStatus = "3";
|
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
|
2014-04-03 17:54:10 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.syncthing = {
|
|
|
|
|
2016-04-14 15:44:02 +01: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 17:54:10 +01:00
|
|
|
|
2016-08-06 16:20:18 +01:00
|
|
|
useInotify = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Provide syncthing-inotify as a service.";
|
|
|
|
};
|
|
|
|
|
2016-04-14 09:42:04 +01:00
|
|
|
systemService = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Auto launch Syncthing as a system service.";
|
|
|
|
};
|
|
|
|
|
2014-04-03 17:54:10 +01:00
|
|
|
user = mkOption {
|
2016-04-01 00:26:52 +01:00
|
|
|
type = types.string;
|
|
|
|
default = defaultUser;
|
2014-04-03 17:54:10 +01:00
|
|
|
description = ''
|
2016-04-14 09:42:04 +01: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 17:54:10 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-12-15 12:07:40 +00:00
|
|
|
all_proxy = mkOption {
|
2016-04-01 00:26:52 +01:00
|
|
|
type = types.nullOr types.string;
|
|
|
|
default = null;
|
2015-12-15 12:07:40 +00: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 17:54:10 +01:00
|
|
|
dataDir = mkOption {
|
2016-04-01 00:26:52 +01:00
|
|
|
type = types.path;
|
2014-04-03 17:54:10 +01:00
|
|
|
default = "/var/lib/syncthing";
|
|
|
|
description = ''
|
2015-08-27 15:01:10 +01:00
|
|
|
Path where the settings and keys will exist.
|
2014-04-03 17:54:10 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-11-28 19:17:49 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.syncthing;
|
2016-01-17 18:34:55 +00:00
|
|
|
defaultText = "pkgs.syncthing";
|
2015-11-28 19:17:49 +00:00
|
|
|
example = literalExample "pkgs.syncthing";
|
|
|
|
description = ''
|
|
|
|
Syncthing package to use.
|
|
|
|
'';
|
|
|
|
};
|
2014-04-03 17:54:10 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2014-04-04 09:46:19 +01:00
|
|
|
config = mkIf cfg.enable {
|
2014-04-03 17:54:10 +01:00
|
|
|
|
2016-04-01 00:26:52 +01:00
|
|
|
users = mkIf (cfg.user == defaultUser) {
|
|
|
|
extraUsers."${defaultUser}" =
|
2016-04-14 09:42:04 +01:00
|
|
|
{ group = cfg.group;
|
2016-04-01 00:26:52 +01: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 16:20:18 +01:00
|
|
|
systemd.services = {
|
|
|
|
syncthing = mkIf cfg.systemService (header // {
|
|
|
|
wants = mkIf cfg.useInotify [ "syncthing-inotify.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = service // {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
ExecStart = "${cfg.package}/bin/syncthing -no-browser -home=${cfg.dataDir}";
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
syncthing-inotify = mkIf (cfg.systemService && cfg.useInotify) (iNotifyHeader // {
|
2016-04-14 09:42:04 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-08-06 16:20:18 +01:00
|
|
|
serviceConfig = iNotifyService // {
|
2016-04-14 09:42:04 +01:00
|
|
|
User = cfg.user;
|
2016-08-06 16:20:18 +01:00
|
|
|
ExecStart = "${pkgs.syncthing-inotify.bin}/bin/syncthing-inotify -home=${cfg.dataDir} -logflags=0";
|
2014-04-03 17:54:10 +01:00
|
|
|
};
|
2016-08-06 16:20:18 +01:00
|
|
|
});
|
2016-07-26 11:10:15 +01:00
|
|
|
};
|
2014-04-03 17:54:10 +01:00
|
|
|
|
2016-08-06 16:20:18 +01:00
|
|
|
systemd.user.services = {
|
|
|
|
syncthing = header // {
|
2016-04-14 09:42:04 +01:00
|
|
|
serviceConfig = service // {
|
2016-05-30 09:14:19 +01:00
|
|
|
ExecStart = "${cfg.package}/bin/syncthing -no-browser";
|
2016-04-14 09:42:04 +01:00
|
|
|
};
|
|
|
|
};
|
2016-07-21 03:49:58 +01:00
|
|
|
|
2016-08-06 16:20:18 +01:00
|
|
|
syncthing-inotify = mkIf cfg.useInotify (iNotifyHeader // {
|
|
|
|
serviceConfig = iNotifyService // {
|
|
|
|
ExecStart = "${pkgs.syncthing-inotify.bin}/bin/syncthing-inotify -logflags=0";
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-04-03 17:54:10 +01:00
|
|
|
};
|
|
|
|
}
|