Disable `KeepAlive.Crashed` option to prevent unnecessary restarts
We previously set KeepAlive.Crashed = false. However, this option causes the script to restart automatically after 10 seconds (the minimum restart interval enforced by launchd), even if it has already run successfully.
As a result, you may observe excessive runs:
launchctl print gui/501/org.nix-community.home.activate-agenix | grep runs
This behavior can also be confirmed in the logs:
sudo log show --last boot --predicate "process == 'launchd' AND composedMessage CONTAINS 'org.nix-community.home.activate-agenix'"
Therefore, this PR removes this option to prevent unnecessary restarts.
document
> man launchd.plist | grep Crashed -B42 -A2
KeepAlive <boolean or dictionary of stuff>
This optional key is used to control whether your job is to be kept continuously running or to let demand and conditions
control the invocation. The default is false and therefore only demand will start the job. The value may be set to true to
unconditionally keep the job alive. Alternatively, a dictionary of conditions may be specified to selectively control
whether launchd keeps a job alive or not. If multiple keys are provided, launchd ORs them, thus providing maximum flexibil‐
ty to the job to refine the logic and stall if necessary. If launchd finds no reason to restart the job, it falls back on
demand based invocation. Jobs that exit quickly and frequently when configured to be kept alive will be throttled to con‐
serve system resources. The use of this key implicitly implies RunAtLoad, causing launchd to speculatively launch the job.
SuccessfulExit <boolean>
If true, the job will be restarted as long as the program exits and with an exit status of zero. If false, the job
will be restarted in the inverse condition. This key implies that "RunAtLoad" is set to true, since the job needs to
run at least once before an exit status can be determined.
...
Crashed <boolean>
If true, the the job will be restarted as long as it exited due to a signal which is typically associated with a
crash (SIGILL, SIGSEGV, etc.). If false, the job will be restarted in the inverse condition.
close #308
Is this only an issue for home-manager users?
$ launchctl print system/org.nixos.activate-agenix | grep runs
runs = 1
Yes, KeepAlive.Crashed is not enabled in the nix-darwin module.
After some investigation, I found that these two launchd agents use different KeepAlive conditions. This divergence has been there since their introduction in PR #141 and PR #180.
https://github.com/ryantm/agenix/blob/9ba0d85de3eaa7afeab493fed622008b6e4924f5/modules/age.nix#L343-L356
https://github.com/ryantm/agenix/blob/9274b82816ae4450ff13f634113e99a83d1bd4b1/modules/age-home.nix#L219-L226
Can confirm this to fix https://github.com/ryantm/agenix/issues/308