syncthing: more reliable syncthing launchd agent
Starts the syncthing-init launchd agent (responsible for updating the configuration) as a oneshot agent instead of via WatchPaths (the latter is too unreliable). Ideally, the syncthing-init agent should be started after the syncthing agent started the Syncthing server, since syncthing-init updates the configuration using API calls to the Syncthing server. The Linux systemd service versions handle this via the Requires and After attribute. Launchd under macOS is missing a reliable way to order agents. Theoretically, one can achieve similar things via, e.g., WatchPaths (used before this commit). But this is known to be very unreliable (see also my comment in issue #6542). Thus, we just start syncthing-init and rely on the wrapped curl bash function (see curlShellFunction in nix file) to wait for the Syncthing server to be up and running.
This commit is contained in:
parent
bc5652b227
commit
cadfe449aa
1 changed files with 24 additions and 31 deletions
|
|
@ -825,40 +825,33 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
launchd.agents =
|
||||
let
|
||||
# agent `syncthing` uses `${syncthing_dir}/${watch_file}` to notify agent `syncthing-init`
|
||||
watch_file = ".launchd_update_config";
|
||||
in
|
||||
{
|
||||
syncthing = {
|
||||
enable = true;
|
||||
config = {
|
||||
ProgramArguments = [
|
||||
"${pkgs.writers.writeBash "syncthing-wrapper" ''
|
||||
${copyKeys} # simulate systemd's `syncthing-init.Service.ExecStartPre`
|
||||
touch "${syncthing_dir}/${watch_file}" # notify syncthing-init agent
|
||||
exec ${lib.escapeShellArgs syncthingArgs}
|
||||
''}"
|
||||
];
|
||||
KeepAlive = {
|
||||
Crashed = true;
|
||||
SuccessfulExit = false;
|
||||
};
|
||||
ProcessType = "Background";
|
||||
};
|
||||
};
|
||||
|
||||
syncthing-init = {
|
||||
enable = cleanedConfig != { };
|
||||
config = {
|
||||
ProgramArguments = [ "${updateConfig}" ];
|
||||
WatchPaths = [
|
||||
"${config.home.homeDirectory}/Library/Application Support/Syncthing/${watch_file}"
|
||||
];
|
||||
launchd.agents = {
|
||||
syncthing = {
|
||||
enable = true;
|
||||
config = {
|
||||
ProgramArguments = [
|
||||
"${pkgs.writers.writeBash "syncthing-wrapper" ''
|
||||
${copyKeys} # simulate systemd's `syncthing-init.Service.ExecStartPre`
|
||||
exec ${lib.escapeShellArgs syncthingArgs}
|
||||
''}"
|
||||
];
|
||||
KeepAlive = {
|
||||
Crashed = true;
|
||||
SuccessfulExit = false;
|
||||
};
|
||||
ProcessType = "Background";
|
||||
};
|
||||
};
|
||||
|
||||
syncthing-init = {
|
||||
enable = cleanedConfig != { };
|
||||
config = {
|
||||
ProgramArguments = [ "${updateConfig}" ];
|
||||
ProcessType = "Background";
|
||||
RunAtLoad = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
})
|
||||
|
||||
(lib.mkIf cfg.tray.enable {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue