Skip to content

Commit b8ed90c

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 d305eec commit b8ed90c

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
@@ -54,11 +54,18 @@ in
5454
Description = "SSH authentication agent";
5555
Documentation = "man:ssh-agent(1)";
5656
};
57-
Service.ExecStart = "${lib.getExe' cfg.package "ssh-agent"} -D -a %t/${cfg.socket}${
58-
lib.optionalString (
59-
cfg.defaultMaximumIdentityLifetime != null
60-
) " -t ${toString cfg.defaultMaximumIdentityLifetime}"
61-
}";
57+
Service = {
58+
ExecStart = "${lib.getExe' cfg.package "ssh-agent"} -D -a %t/${cfg.socket}${
59+
lib.optionalString (
60+
cfg.defaultMaximumIdentityLifetime != null
61+
) " -t ${toString cfg.defaultMaximumIdentityLifetime}"
62+
}";
63+
ExecStartPost = "${pkgs.writeShellScript "update-ssh-agent-env" ''
64+
if [ -z "$SSH_AUTH_SOCK" ]; then
65+
${pkgs.dbus}/bin/dbus-update-activation-environment --systemd "$@"
66+
fi
67+
''} SSH_AUTH_SOCK=%t/${cfg.socket}";
68+
};
6269
};
6370
};
6471
}

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)