Files
home-manager/tests/modules/misc/ssh-auth-sock/enabled.nix
Benedikt Rips f1d5aa6f69 sshAuthSock: set in systemd
`SSH_AUTH_SOCK` is exported in shells only, which systemd does not
inherit from. With this commit, it is also set in systemd such that
systemd-managed applications can access the SSH agent by declaring
dependencies onto 'sshAuthSock.systemd.socketProviderUnit'.

Closes #7971.
2026-06-04 12:20:50 -05:00

39 lines
1.3 KiB
Nix

{ config, lib, ... }:
{
programs.bash.enable = true;
programs.fish.enable = true;
programs.nushell.enable = true;
programs.zsh.enable = true;
sshAuthSock = {
enable = true;
initialization = {
bash = "echo bash/zsh";
fish = "echo fish";
nushell = "echo nushell";
};
systemd.socketProviderUnit = "foo.socket";
};
nmt.script = ''
assertFileContains \
home-files/.profile \
'if [ -z "$SSH_AUTH_SOCK" -o -z "$SSH_CONNECTION" ]; then'
assertFileContains \
home-files/.config/fish/config.fish \
'if test -z "$SSH_AUTH_SOCK"; or test -z "$SSH_CONNECTION"'
assertFileContains \
home-files/.config/nushell/config.nu \
'if ("SSH_AUTH_SOCK" not-in $env) or ($env.SSH_AUTH_SOCK | is-empty) or ("SSH_CONNECTION" not-in $env) or ($env.SSH_CONNECTION | is-empty) {'
assertFileContains \
home-files/.zshenv \
'if [ -z "$SSH_AUTH_SOCK" -o -z "$SSH_CONNECTION" ]; then'
''
+ lib.optionalString config.systemd.user.enable ''
assertFileExists home-files/.config/systemd/user/set-SSH_AUTH_SOCK.service
assertFileContains home-files/.config/systemd/user/set-SSH_AUTH_SOCK.service 'Before=foo.socket'
assertFileContains home-files/.config/systemd/user/set-SSH_AUTH_SOCK.service 'WantedBy=foo.socket'
'';
}