3
0
Fork 0
forked from mirrors/nixpkgs

syncthing service: add syncthing-inotify (#17320)

This commit is contained in:
jokogr 2016-08-06 18:20:18 +03:00 committed by Franz Pletz
parent f126b1a7a9
commit adeab67bd8

View file

@ -23,6 +23,18 @@ let
RestartForceExitStatus="3 4"; RestartForceExitStatus="3 4";
}; };
iNotifyHeader = {
description = "Syncthing Inotify File Watcher service";
after = [ "network.target" "syncthing.service" ];
requires = [ "syncthing.service" ];
};
iNotifyService = {
SuccessExitStatus = "2";
RestartForceExitStatus = "3";
Restart = "on-failure";
};
in in
{ {
@ -39,6 +51,12 @@ in
available on http://127.0.0.1:8384/. available on http://127.0.0.1:8384/.
''; '';
useInotify = mkOption {
type = types.bool;
default = false;
description = "Provide syncthing-inotify as a service.";
};
systemService = mkOption { systemService = mkOption {
type = types.bool; type = types.bool;
default = true; default = true;
@ -112,27 +130,40 @@ in
config.ids.gids.syncthing; config.ids.gids.syncthing;
}; };
environment.systemPackages = [ cfg.package ]; systemd.services = {
syncthing = mkIf cfg.systemService (header // {
wants = mkIf cfg.useInotify [ "syncthing-inotify.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = service // {
User = cfg.user;
Group = cfg.group;
PermissionsStartOnly = true;
ExecStart = "${cfg.package}/bin/syncthing -no-browser -home=${cfg.dataDir}";
};
});
systemd.services = mkIf cfg.systemService { syncthing-inotify = mkIf (cfg.systemService && cfg.useInotify) (iNotifyHeader // {
syncthing = header // {
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
serviceConfig = service // { serviceConfig = iNotifyService // {
User = cfg.user; User = cfg.user;
Group = cfg.group; ExecStart = "${pkgs.syncthing-inotify.bin}/bin/syncthing-inotify -home=${cfg.dataDir} -logflags=0";
PermissionsStartOnly = true;
ExecStart = "${cfg.package}/bin/syncthing -no-browser -home=${cfg.dataDir}";
}; };
}; });
}; };
systemd.user.services.syncthing = systemd.user.services = {
header // { syncthing = header // {
wantedBy = [ "default.target" ];
serviceConfig = service // { serviceConfig = service // {
ExecStart = "${cfg.package}/bin/syncthing -no-browser"; ExecStart = "${cfg.package}/bin/syncthing -no-browser";
}; };
}; };
syncthing-inotify = mkIf cfg.useInotify (iNotifyHeader // {
serviceConfig = iNotifyService // {
ExecStart = "${pkgs.syncthing-inotify.bin}/bin/syncthing-inotify -logflags=0";
};
});
};
}; };
} }