Skip to content

Conversation

@yzx9
Copy link

@yzx9 yzx9 commented Oct 27, 2025

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

@n8henrie
Copy link
Collaborator

Is this only an issue for home-manager users?

$ launchctl print system/org.nixos.activate-agenix | grep runs
        runs = 1

@yzx9
Copy link
Author

yzx9 commented Oct 28, 2025

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.

agenix/modules/age.nix

Lines 343 to 356 in 9ba0d85

launchd.daemons.activate-agenix = {
script = ''
set -e
set -o pipefail
export PATH="${pkgs.gnugrep}/bin:${pkgs.coreutils}/bin:@out@/sw/bin:/usr/bin:/bin:/usr/sbin:/sbin"
${newGeneration}
${installSecrets}
${chownSecrets}
exit 0
'';
serviceConfig = {
RunAtLoad = true;
KeepAlive.SuccessfulExit = false;
};

agenix/modules/age-home.nix

Lines 219 to 226 in 9274b82

launchd.agents.activate-agenix = {
enable = true;
config = {
ProgramArguments = [mountingScript];
KeepAlive = {
Crashed = false;
SuccessfulExit = false;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Why set launched.agents...KeepAlive.Crashed = false

2 participants