1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00

ssh-agent: add option for the socket name

This commit is contained in:
Benedikt Rips 2025-08-14 00:05:07 +02:00 committed by Austin Horstman
parent af03309c12
commit 94a238f9c1
3 changed files with 23 additions and 24 deletions

View file

@ -6,7 +6,6 @@
}: }:
let let
cfg = config.services.ssh-agent; cfg = config.services.ssh-agent;
in in
@ -16,11 +15,18 @@ in
lib.hm.maintainers.lheckemann lib.hm.maintainers.lheckemann
]; ];
options = { options.services.ssh-agent = {
services.ssh-agent = { enable = lib.mkEnableOption "OpenSSH private key agent";
enable = lib.mkEnableOption "OpenSSH private key agent";
package = lib.mkPackageOption pkgs "openssh" { }; package = lib.mkPackageOption pkgs "openssh" { };
socket = lib.mkOption {
type = lib.types.str;
default = "ssh-agent";
example = "ssh-agent/socket";
description = ''
The agent's socket; interpreted as a suffix to {env}`$XDG_RUNTIME_DIR`.
'';
}; };
}; };
@ -31,21 +37,17 @@ in
home.sessionVariablesExtra = '' home.sessionVariablesExtra = ''
if [ -z "$SSH_AUTH_SOCK" ]; then if [ -z "$SSH_AUTH_SOCK" ]; then
export SSH_AUTH_SOCK=$XDG_RUNTIME_DIR/ssh-agent export SSH_AUTH_SOCK=$XDG_RUNTIME_DIR/${cfg.socket}
fi fi
''; '';
systemd.user.services.ssh-agent = { systemd.user.services.ssh-agent = {
Install.WantedBy = [ "default.target" ]; Install.WantedBy = [ "default.target" ];
Unit = { Unit = {
Description = "SSH authentication agent"; Description = "SSH authentication agent";
Documentation = "man:ssh-agent(1)"; Documentation = "man:ssh-agent(1)";
}; };
Service.ExecStart = "${lib.getExe' cfg.package "ssh-agent"} -D -a %t/${cfg.socket}";
Service = {
ExecStart = "${lib.getExe' cfg.package "ssh-agent"} -D -a %t/ssh-agent";
};
}; };
}; };
} }

View file

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

View file

@ -1,15 +1,12 @@
{ config, ... }:
{ {
config = { services.ssh-agent = {
services.ssh-agent = { enable = true;
enable = true; socket = "ssh-agent/socket";
};
nmt.script = ''
assertFileContent \
home-files/.config/systemd/user/ssh-agent.service \
${./basic-service-expected.service}
'';
}; };
nmt.script = ''
assertFileContent \
home-files/.config/systemd/user/ssh-agent.service \
${./basic-service-expected.service}
'';
} }