git.iko.soy/typeable/nixpkgs
on master help sign in
syncthing service: add syncthing-inotify (#17320)
adeab67jokogr
nixos/modules/services/networking/syncthing.nix+43−12
@@ -23,6 +23,18 @@ let
23 RestartForceExitStatus="3 4";
23 RestartForceExitStatus="3 4";
24 };
24 };
25
25
26+ iNotifyHeader = {
27+ description = "Syncthing Inotify File Watcher service";
28+ after = [ "network.target" "syncthing.service" ];
29+ requires = [ "syncthing.service" ];
30+ };
31+
32+ iNotifyService = {
33+ SuccessExitStatus = "2";
34+ RestartForceExitStatus = "3";
35+ Restart = "on-failure";
36+ };
37+
26in
38in
27
39
28{
40{
@@ -39,6 +51,12 @@ in
39 available on http://127.0.0.1:8384/.
51 available on http://127.0.0.1:8384/.
40 '';
52 '';
41
53
54+ useInotify = mkOption {
55+ type = types.bool;
56+ default = false;
57+ description = "Provide syncthing-inotify as a service.";
58+ };
59+
42 systemService = mkOption {
60 systemService = mkOption {
43 type = types.bool;
61 type = types.bool;
44 default = true;
62 default = true;
@@ -112,27 +130,40 @@ in
112 config.ids.gids.syncthing;
130 config.ids.gids.syncthing;
113 };
131 };
114
132
115− environment.systemPackages = [ cfg.package ];
116−
117− systemd.services = mkIf cfg.systemService {
133+ systemd.services = {
118− syncthing = header // {
134+ syncthing = mkIf cfg.systemService (header // {
135+ wants = mkIf cfg.useInotify [ "syncthing-inotify.service" ];
136+ wantedBy = [ "multi-user.target" ];
137+ serviceConfig = service // {
138+ User = cfg.user;
139+ Group = cfg.group;
140+ PermissionsStartOnly = true;
141+ ExecStart = "${cfg.package}/bin/syncthing -no-browser -home=${cfg.dataDir}";
142+ };
143+ });
144+
145+ syncthing-inotify = mkIf (cfg.systemService && cfg.useInotify) (iNotifyHeader // {
119 wantedBy = [ "multi-user.target" ];
146 wantedBy = [ "multi-user.target" ];
120− serviceConfig = service // {
147+ serviceConfig = iNotifyService // {
121 User = cfg.user;
148 User = cfg.user;
122− Group = cfg.group;
123− PermissionsStartOnly = true;
124− ExecStart = "${cfg.package}/bin/syncthing -no-browser -home=${cfg.dataDir}";
149+ ExecStart = "${pkgs.syncthing-inotify.bin}/bin/syncthing-inotify -home=${cfg.dataDir} -logflags=0";
125 };
150 };
126− };
151+ });
127 };
152 };
128
153
129− systemd.user.services.syncthing =
154+ systemd.user.services = {
130− header // {
155+ syncthing = header // {
131− wantedBy = [ "default.target" ];
132 serviceConfig = service // {
156 serviceConfig = service // {
133 ExecStart = "${cfg.package}/bin/syncthing -no-browser";
157 ExecStart = "${cfg.package}/bin/syncthing -no-browser";
134 };
158 };
135 };
159 };
136
160
161+ syncthing-inotify = mkIf cfg.useInotify (iNotifyHeader // {
162+ serviceConfig = iNotifyService // {
163+ ExecStart = "${pkgs.syncthing-inotify.bin}/bin/syncthing-inotify -logflags=0";
164+ };
165+ });
166+ };
167+
137 };
168 };
138}
169}