1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.syncthing;
8
9in
10
11{
12
13 ###### interface
14
15 options = {
16
17 services.syncthing = {
18
19 enable = mkOption {
20 default = false;
21 description = ''
22 Whether to enable the Syncthing, self-hosted open-source alternative
23 to Dropbox and BittorrentSync. Initial interface will be
24 available on http://127.0.0.1:8384/.
25 '';
26 };
27
28 user = mkOption {
29 default = "syncthing";
30 description = ''
31 Syncthing will be run under this user (user must exist,
32 this can be your user name).
33 '';
34 };
35
36 dataDir = mkOption {
37 default = "/var/lib/syncthing";
38 description = ''
39 Path where the settings and keys will exist.
40 '';
41 };
42
43 package = mkOption {
44 type = types.package;
45 default = pkgs.syncthing;
46 defaultText = "pkgs.syncthing";
47 example = literalExample "pkgs.syncthing";
48 description = ''
49 Syncthing package to use.
50 '';
51 };
52
53
54
55 };
56
57 };
58
59
60 ###### implementation
61
62 config = mkIf cfg.enable {
63
64 systemd.services.syncthing =
65 {
66 description = "Syncthing service";
67 after = [ "network.target" ];
68 wantedBy = [ "multi-user.target" ];
69 environment.STNORESTART = "yes"; # do not self-restart
70 environment.STNOUPGRADE = "yes";
71 serviceConfig = {
72 User = "${cfg.user}";
73 PermissionsStartOnly = true;
74 Restart = "on-failure";
75 ExecStart = "${pkgs.syncthing}/bin/syncthing -no-browser -home=${cfg.dataDir}";
76 SuccessExitStatus = "2 3 4";
77 RestartForceExitStatus="3 4";
78 };
79 };
80
81 environment.systemPackages = [ cfg.package ];
82
83 };
84
85}