syncthing service: add syncthing-inotify (#17320)

authored by

jokogr and committed by
Franz Pletz
adeab67b f126b1a7

+42 -11
+42 -11
nixos/modules/services/networking/syncthing.nix
··· 23 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 + 26 38 in 27 39 28 40 { ··· 38 50 to Dropbox and Bittorrent Sync. Initial interface will be 39 51 available on http://127.0.0.1:8384/. 40 52 ''; 53 + 54 + useInotify = mkOption { 55 + type = types.bool; 56 + default = false; 57 + description = "Provide syncthing-inotify as a service."; 58 + }; 41 59 42 60 systemService = mkOption { 43 61 type = types.bool; ··· 112 130 config.ids.gids.syncthing; 113 131 }; 114 132 115 - environment.systemPackages = [ cfg.package ]; 133 + systemd.services = { 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 + }); 116 144 117 - systemd.services = mkIf cfg.systemService { 118 - syncthing = header // { 145 + syncthing-inotify = mkIf (cfg.systemService && cfg.useInotify) (iNotifyHeader // { 119 146 wantedBy = [ "multi-user.target" ]; 120 - serviceConfig = service // { 147 + serviceConfig = iNotifyService // { 121 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 = 130 - header // { 131 - wantedBy = [ "default.target" ]; 154 + systemd.user.services = { 155 + syncthing = header // { 132 156 serviceConfig = service // { 133 157 ExecStart = "${cfg.package}/bin/syncthing -no-browser"; 134 158 }; 135 159 }; 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 + }; 136 167 137 168 }; 138 169 }