2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2014-04-03 16:54:10 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2014-04-03 16:54:10 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.syncthing;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.syncthing = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the Syncthing, self-hosted open-source alternative
|
|
|
|
to Dropbox and BittorrentSync. Initial interface will be
|
|
|
|
available on http://127.0.0.1:8080/.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
default = "syncthing";
|
|
|
|
description = ''
|
|
|
|
Syncthing will be run under this user (user must exist,
|
|
|
|
this can be your user name).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
default = "/var/lib/syncthing";
|
|
|
|
description = ''
|
2015-08-27 14:01:10 +00:00
|
|
|
Path where the settings and keys will exist.
|
2014-04-03 16:54:10 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2014-04-04 08:46:19 +00:00
|
|
|
config = mkIf cfg.enable {
|
2014-04-03 16:54:10 +00:00
|
|
|
|
|
|
|
systemd.services.syncthing =
|
|
|
|
{
|
|
|
|
description = "Syncthing service";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2015-09-21 21:17:38 +00:00
|
|
|
environment.STNORESTART = "yes"; # do not self-restart
|
|
|
|
environment.STNOUPGRADE = "yes";
|
2014-04-03 16:54:10 +00:00
|
|
|
serviceConfig = {
|
2014-04-04 08:46:19 +00:00
|
|
|
User = "${cfg.user}";
|
|
|
|
PermissionsStartOnly = true;
|
2015-09-21 21:17:38 +00:00
|
|
|
Restart = "on-failure";
|
2015-08-27 14:01:10 +00:00
|
|
|
ExecStart = "${pkgs.syncthing}/bin/syncthing -no-browser -home=${cfg.dataDir}";
|
2015-09-21 21:17:38 +00:00
|
|
|
SuccessExitStatus = "2 3 4";
|
|
|
|
RestartForceExitStatus="3 4";
|
2014-04-03 16:54:10 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.syncthing ];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|