Skip to content

Commit 8fb1f10

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 8fb1f10

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

modules/services/ssh-agent.nix

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,16 @@ 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 = ''
64+
${pkgs.dbus}/bin/dbus-update-activation-environment --systemd SSH_AUTH_SOCK=%t/${cfg.socket}
65+
'';
66+
};
6267
};
6368
};
6469
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ WantedBy=default.target
33

44
[Service]
55
ExecStart=@openssh@/bin/ssh-agent -D -a %t/ssh-agent/socket
6+
ExecStartPost=@dbus@/bin/dbus-update-activation-environment --systemd SSH_AUTH_SOCK=%t/ssh-agent/socket
7+
68

79
[Unit]
810
Description=SSH authentication agent

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ WantedBy=default.target
33

44
[Service]
55
ExecStart=@openssh@/bin/ssh-agent -D -a %t/ssh-agent -t 1337
6+
ExecStartPost=@dbus@/bin/dbus-update-activation-environment --systemd SSH_AUTH_SOCK=%t/ssh-agent
7+
68

79
[Unit]
810
Description=SSH authentication agent

0 commit comments

Comments
 (0)