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;
|
|
|
|
|
|
|
|
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
|
2015-11-28 19:17:49 +00:00
|
|
|
available on http://127.0.0.1:8384/.
|
2014-04-03 17:54:10 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
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 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;
|
|
|
|
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
|
|
|
|
|
|
|
systemd.services.syncthing =
|
|
|
|
{
|
|
|
|
description = "Syncthing service";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2015-09-21 22:17:38 +01:00
|
|
|
environment.STNORESTART = "yes"; # do not self-restart
|
|
|
|
environment.STNOUPGRADE = "yes";
|
2014-04-03 17:54:10 +01:00
|
|
|
serviceConfig = {
|
2014-04-04 09:46:19 +01:00
|
|
|
User = "${cfg.user}";
|
|
|
|
PermissionsStartOnly = true;
|
2015-09-21 22:17:38 +01:00
|
|
|
Restart = "on-failure";
|
2015-08-27 15:01:10 +01:00
|
|
|
ExecStart = "${pkgs.syncthing}/bin/syncthing -no-browser -home=${cfg.dataDir}";
|
2015-09-21 22:17:38 +01:00
|
|
|
SuccessExitStatus = "2 3 4";
|
|
|
|
RestartForceExitStatus="3 4";
|
2014-04-03 17:54:10 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-11-28 19:17:49 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2014-04-03 17:54:10 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|