diff --git a/modules/services/syncthing.nix b/modules/services/syncthing.nix index 8551b25d1..d82d626f0 100644 --- a/modules/services/syncthing.nix +++ b/modules/services/syncthing.nix @@ -202,7 +202,6 @@ in { services.syncthing = { enable = mkEnableOption '' Syncthing, a self-hosted open-source alternative to Dropbox and Bittorrent Sync. - Further declarative configuration options only supported on Linux devices. ''; cert = mkOption { @@ -686,11 +685,20 @@ in { }; }; - launchd.agents = { + 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 = syncthingArgs; + 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; @@ -698,6 +706,14 @@ in { ProcessType = "Background"; }; }; + + syncthing-init = { + enable = true; + config = { + ProgramArguments = [ "${updateConfig}" ]; + WatchPaths = [ "${config.home.homeDirectory}/Library/Application Support/Syncthing/${watch_file}" ]; + }; + }; }; })