services/ssh-agent: treat SIGTERM exit as clean

OpenSSH ssh-agent exits with status 2 when systemd stops it in
non-socket-activated mode.

Home Manager runs ssh-agent that way, so normal user-manager
shutdowns show up as unit failures.

Set SuccessExitStatus=2 for the Linux user service to match
upstream behavior. Startup failures and other unexpected exits
still fail the unit.
This commit is contained in:
Ihar Hrachyshka 2026-03-27 22:16:41 -04:00 committed by Bruno BELANYI
parent 769e07ef8f
commit 5ed75a0312
4 changed files with 15 additions and 9 deletions

View file

@ -108,15 +108,18 @@ in
Description = "SSH authentication agent";
Documentation = "man:ssh-agent(1)";
};
Service.ExecStart = "${lib.getExe' cfg.package "ssh-agent"} -D -a %t/${cfg.socket}${
lib.optionalString (
cfg.defaultMaximumIdentityLifetime != null
) " -t ${toString cfg.defaultMaximumIdentityLifetime}"
}${
lib.optionalString (
cfg.pkcs11Whitelist != [ ]
) " -P '${lib.concatStringsSep "," cfg.pkcs11Whitelist}'"
}";
Service = {
ExecStart = "${lib.getExe' cfg.package "ssh-agent"} -D -a %t/${cfg.socket}${
lib.optionalString (
cfg.defaultMaximumIdentityLifetime != null
) " -t ${toString cfg.defaultMaximumIdentityLifetime}"
}${
lib.optionalString (
cfg.pkcs11Whitelist != [ ]
) " -P '${lib.concatStringsSep "," cfg.pkcs11Whitelist}'"
}";
SuccessExitStatus = 2;
};
};
launchd.agents.ssh-agent = {

View file

@ -3,6 +3,7 @@ WantedBy=default.target
[Service]
ExecStart=@openssh@/bin/ssh-agent -D -a %t/ssh-agent/socket
SuccessExitStatus=2
[Unit]
Description=SSH authentication agent

View file

@ -3,6 +3,7 @@ WantedBy=default.target
[Service]
ExecStart=@openssh@/bin/ssh-agent -D -a %t/ssh-agent -P '/nix/store/*/lib,/usr/lib/libpkcs11.so,/usr/lib/other.so'
SuccessExitStatus=2
[Unit]
Description=SSH authentication agent

View file

@ -3,6 +3,7 @@ WantedBy=default.target
[Service]
ExecStart=@openssh@/bin/ssh-agent -D -a %t/ssh-agent -t 1337
SuccessExitStatus=2
[Unit]
Description=SSH authentication agent