mirror of
https://github.com/nix-community/home-manager.git
synced 2024-12-14 11:57:55 +00:00
gpg-agent: use systemd socket activation
This commit is contained in:
parent
acf813cadc
commit
196db18f5b
1 changed files with 77 additions and 29 deletions
|
@ -29,41 +29,89 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable (mkMerge [
|
||||||
home.file.".gnupg/gpg-agent.conf".text = concatStringsSep "\n" (
|
{
|
||||||
optional cfg.enableSshSupport
|
home.file.".gnupg/gpg-agent.conf".text = concatStringsSep "\n" (
|
||||||
"enable-ssh-support"
|
optional cfg.enableSshSupport
|
||||||
++
|
"enable-ssh-support"
|
||||||
optional (cfg.defaultCacheTtl != null)
|
++
|
||||||
"default-cache-ttl ${toString cfg.defaultCacheTtl}"
|
optional (cfg.defaultCacheTtl != null)
|
||||||
);
|
"default-cache-ttl ${toString cfg.defaultCacheTtl}"
|
||||||
|
);
|
||||||
|
|
||||||
home.sessionVariables =
|
home.sessionVariables =
|
||||||
optionalAttrs cfg.enableSshSupport {
|
optionalAttrs cfg.enableSshSupport {
|
||||||
SSH_AUTH_SOCK = "\${XDG_RUNTIME_DIR}/gnupg/S.gpg-agent.ssh";
|
SSH_AUTH_SOCK = "\${XDG_RUNTIME_DIR}/gnupg/S.gpg-agent.ssh";
|
||||||
|
};
|
||||||
|
|
||||||
|
programs.bash.initExtra = ''
|
||||||
|
GPG_TTY="$(tty)"
|
||||||
|
export GPG_TTY
|
||||||
|
gpg-connect-agent updatestartuptty /bye > /dev/null
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
|
||||||
|
# The systemd units below are direct translations of the
|
||||||
|
# descriptions in the
|
||||||
|
#
|
||||||
|
# ${pkgs.gnupg}/share/doc/gnupg/examples/systemd-user
|
||||||
|
#
|
||||||
|
# directory.
|
||||||
|
{
|
||||||
|
systemd.user.services.gpg-agent = {
|
||||||
|
Unit = {
|
||||||
|
Description = "GnuPG cryptographic agent and passphrase cache";
|
||||||
|
Documentation = "man:gpg-agent(1)";
|
||||||
|
Requires = "gpg-agent.socket";
|
||||||
|
After = "gpg-agent.socket";
|
||||||
|
# This is a socket-activated service:
|
||||||
|
RefuseManualStart = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
Service = {
|
||||||
|
ExecStart = "${pkgs.gnupg}/bin/gpg-agent --supervised";
|
||||||
|
ExecReload = "${pkgs.gnupg}/bin/gpgconf --reload gpg-agent";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
programs.bash.initExtra = ''
|
systemd.user.sockets.gpg-agent = {
|
||||||
GPG_TTY="$(tty)"
|
Unit = {
|
||||||
export GPG_TTY
|
Description = "GnuPG cryptographic agent and passphrase cache";
|
||||||
gpg-connect-agent updatestartuptty /bye > /dev/null
|
Documentation = "man:gpg-agent(1)";
|
||||||
'';
|
};
|
||||||
|
|
||||||
systemd.user.services.gpg-agent = {
|
Socket = {
|
||||||
Unit = {
|
ListenStream = "%t/gnupg/S.gpg-agent";
|
||||||
Description = "GnuPG private key agent";
|
FileDescriptorName = "std";
|
||||||
IgnoreOnIsolate = true;
|
SocketMode = "0600";
|
||||||
};
|
DirectoryMode = "0700";
|
||||||
|
};
|
||||||
|
|
||||||
Service = {
|
Install = {
|
||||||
Type = "forking";
|
WantedBy = [ "sockets.target" ];
|
||||||
ExecStart = "${pkgs.gnupg}/bin/gpg-agent --daemon";
|
};
|
||||||
Restart = "on-abort";
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Install = {
|
(mkIf cfg.enableSshSupport {
|
||||||
WantedBy = [ "default.target" ];
|
systemd.user.sockets.gpg-agent-ssh = {
|
||||||
|
Unit = {
|
||||||
|
Description = "GnuPG cryptographic agent (ssh-agent emulation)";
|
||||||
|
Documentation = "man:gpg-agent(1) man:ssh-add(1) man:ssh-agent(1) man:ssh(1)";
|
||||||
|
};
|
||||||
|
|
||||||
|
Socket = {
|
||||||
|
ListenStream = "%t/gnupg/S.gpg-agent.ssh";
|
||||||
|
FileDescriptorName = "ssh";
|
||||||
|
Service = "gpg-agent.service";
|
||||||
|
SocketMode = "0600";
|
||||||
|
DirectoryMode = "0700";
|
||||||
|
};
|
||||||
|
|
||||||
|
Install = {
|
||||||
|
WantedBy = [ "sockets.target" ];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
})
|
||||||
};
|
]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue