Skip to content

Commit 0467d02

Browse files
committed
ssh-agent: Allow other systemd units access to $SSH_AUTH_SOCK
If another systemd unit wants to talk to the ssh-agent service, they need to know the SSH_AUTH_SOCK variable to do so.
1 parent 43e2056 commit 0467d02

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

modules/services/ssh-agent.nix

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,18 @@ in
8686
Description = "SSH authentication agent";
8787
Documentation = "man:ssh-agent(1)";
8888
};
89-
Service.ExecStart = "${lib.getExe' cfg.package "ssh-agent"} -D -a %t/${cfg.socket}${
90-
lib.optionalString (
91-
cfg.defaultMaximumIdentityLifetime != null
92-
) " -t ${toString cfg.defaultMaximumIdentityLifetime}"
93-
}";
89+
Service = {
90+
ExecStart = "${lib.getExe' cfg.package "ssh-agent"} -D -a %t/${cfg.socket}${
91+
lib.optionalString (
92+
cfg.defaultMaximumIdentityLifetime != null
93+
) " -t ${toString cfg.defaultMaximumIdentityLifetime}"
94+
}";
95+
ExecStartPost = "${pkgs.writeShellScript "update-ssh-agent-env" ''
96+
if [ -z "$SSH_AUTH_SOCK" ]; then
97+
${pkgs.dbus}/bin/dbus-update-activation-environment --systemd "$@"
98+
fi
99+
''} SSH_AUTH_SOCK=%t/${cfg.socket}";
100+
};
94101
};
95102
};
96103
}

tests/modules/services/ssh-agent/basic-service-expected.service

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ WantedBy=default.target
33

44
[Service]
55
ExecStart=@openssh@/bin/ssh-agent -D -a %t/ssh-agent/socket
6+
ExecStartPost=/nix/store/00000000000000000000000000000000-update-ssh-agent-env SSH_AUTH_SOCK=%t/ssh-agent/socket
67

78
[Unit]
89
Description=SSH authentication agent

tests/modules/services/ssh-agent/basic-service.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
nmt.script = ''
88
assertFileContent \
9-
home-files/.config/systemd/user/ssh-agent.service \
9+
$(normalizeStorePaths home-files/.config/systemd/user/ssh-agent.service) \
1010
${./basic-service-expected.service}
1111
'';
1212
}

tests/modules/services/ssh-agent/timeout-service-expected.service

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ WantedBy=default.target
33

44
[Service]
55
ExecStart=@openssh@/bin/ssh-agent -D -a %t/ssh-agent -t 1337
6+
ExecStartPost=/nix/store/00000000000000000000000000000000-update-ssh-agent-env SSH_AUTH_SOCK=%t/ssh-agent
67

78
[Unit]
89
Description=SSH authentication agent

tests/modules/services/ssh-agent/timeout-service.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
nmt.script = ''
88
assertFileContent \
9-
home-files/.config/systemd/user/ssh-agent.service \
9+
$(normalizeStorePaths home-files/.config/systemd/user/ssh-agent.service) \
1010
${./timeout-service-expected.service}
1111
'';
1212
}

0 commit comments

Comments
 (0)