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 = ''
|
|
|
|
Path where the `.syncthing` (settings and keys) and `Sync`
|
|
|
|
(your synced files) directories will exist. This can be your home
|
|
|
|
directory.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### 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
|
2014-04-04 09:46:19 +01:00
|
|
|
environment.HOME = "${cfg.dataDir}";
|
2014-04-03 17:54:10 +01:00
|
|
|
serviceConfig = {
|
2014-04-04 09:46:19 +01:00
|
|
|
User = "${cfg.user}";
|
|
|
|
PermissionsStartOnly = true;
|
2014-04-03 17:54:10 +01:00
|
|
|
Restart = "always";
|
2014-04-04 09:46:19 +01:00
|
|
|
ExecStart = "${pkgs.syncthing}/bin/syncthing -home=${cfg.dataDir}/.syncthing";
|
2014-04-03 17:54:10 +01:00
|
|
|
};
|
2014-04-04 09:46:19 +01:00
|
|
|
preStart = ''
|
|
|
|
mkdir -p ${cfg.dataDir}
|
|
|
|
chown ${cfg.user} ${cfg.dataDir}
|
|
|
|
'';
|
2014-04-03 17:54:10 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.syncthing ];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|