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";
|
|
|
|
environment = {
|
|
|
|
STNORESTART = "yes";
|
|
|
|
STNOUPGRADE = "yes";
|
|
|
|
inherit (cfg) all_proxy;
|
|
|
|
} // config.networking.proxy.envVars;
|
|
|
|
};
|
|
|
|
|
|
|
|
service = {
|
|
|
|
Restart = "on-failure";
|
|
|
|
SuccessExitStatus = "2 3 4";
|
|
|
|
RestartForceExitStatus="3 4";
|
|
|
|
};
|
|
|
|
|
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-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-04-14 09:42:04 +01:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
systemd.services = mkIf cfg.systemService {
|
|
|
|
syncthing = header // {
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = service // {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2014-04-04 09:46:19 +01:00
|
|
|
PermissionsStartOnly = true;
|
2016-05-30 09:14:19 +01:00
|
|
|
ExecStart = "${cfg.package}/bin/syncthing -no-browser -home=${cfg.dataDir}";
|
2014-04-03 17:54:10 +01:00
|
|
|
};
|
|
|
|
};
|
2016-04-14 09:42:04 +01:00
|
|
|
};
|
2014-04-03 17:54:10 +01:00
|
|
|
|
2016-04-14 09:42:04 +01:00
|
|
|
systemd.user.services = {
|
|
|
|
syncthing = header // {
|
|
|
|
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
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2014-04-03 17:54:10 +01:00
|
|
|
};
|
|
|
|
}
|