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
|
|
|
|
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 15:01:10 +01:00
|
|
|
Path where the settings and keys will exist.
|
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" ];
|
|
|
|
environment.STNORESTART = "placeholder"; # do not self-restart
|
|
|
|
serviceConfig = {
|
2014-04-04 09:46:19 +01:00
|
|
|
User = "${cfg.user}";
|
|
|
|
PermissionsStartOnly = true;
|
2014-04-03 17:54:10 +01:00
|
|
|
Restart = "always";
|
2015-08-27 15:01:10 +01:00
|
|
|
ExecStart = "${pkgs.syncthing}/bin/syncthing -no-browser -home=${cfg.dataDir}";
|
2014-04-03 17:54:10 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.syncthing ];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|