2017-05-25 21:14:39 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.gnupg;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
options.programs.gnupg = {
|
|
|
|
agent.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enables GnuPG agent with socket-activation for every user session.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
agent.enableSSHSupport = mkOption {
|
|
|
|
type = types.bool;
|
2017-06-15 19:40:09 +02:00
|
|
|
default = false;
|
2017-05-25 21:14:39 +02:00
|
|
|
description = ''
|
|
|
|
Enable SSH agent support in GnuPG agent. Also sets SSH_AUTH_SOCK
|
|
|
|
environment variable correctly. This will disable socket-activation
|
|
|
|
and thus always start a GnuPG agent per user session.
|
|
|
|
'';
|
|
|
|
};
|
2017-06-15 19:40:09 +02:00
|
|
|
|
|
|
|
agent.enableExtraSocket = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable extra socket for GnuPG agent.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
agent.enableBrowserSocket = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable browser socket for GnuPG agent.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dirmngr.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enables GnuPG network certificate management daemon with socket-activation for every user session.
|
|
|
|
'';
|
|
|
|
};
|
2017-05-25 21:14:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.agent.enable {
|
|
|
|
systemd.user.sockets.gpg-agent = {
|
|
|
|
wantedBy = [ "sockets.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.user.sockets.gpg-agent-ssh = mkIf cfg.agent.enableSSHSupport {
|
|
|
|
wantedBy = [ "sockets.target" ];
|
2017-06-15 19:40:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.user.sockets.gpg-agent-extra = mkIf cfg.agent.enableExtraSocket {
|
|
|
|
wantedBy = [ "sockets.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.user.sockets.gpg-agent-browser = mkIf cfg.agent.enableBrowserSocket {
|
|
|
|
wantedBy = [ "sockets.target" ];
|
|
|
|
};
|
|
|
|
|
2017-06-27 01:33:23 +02:00
|
|
|
systemd.user.sockets.dirmngr = mkIf cfg.dirmngr.enable {
|
2017-06-15 19:40:09 +02:00
|
|
|
wantedBy = [ "sockets.target" ];
|
2017-05-25 21:14:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.packages = [ pkgs.gnupg ];
|
|
|
|
|
2018-10-21 11:19:04 +02:00
|
|
|
environment.interactiveShellInit = ''
|
2017-05-25 21:14:39 +02:00
|
|
|
# Bind gpg-agent to this TTY if gpg commands are used.
|
|
|
|
export GPG_TTY=$(tty)
|
|
|
|
|
|
|
|
'' + (optionalString cfg.agent.enableSSHSupport ''
|
|
|
|
# SSH agent protocol doesn't support changing TTYs, so bind the agent
|
|
|
|
# to every new TTY.
|
|
|
|
${pkgs.gnupg}/bin/gpg-connect-agent --quiet updatestartuptty /bye > /dev/null
|
2019-02-23 19:20:12 +01:00
|
|
|
'');
|
2017-05-25 21:14:39 +02:00
|
|
|
|
2019-02-23 19:20:12 +01:00
|
|
|
environment.extraInit = mkIf cfg.agent.enableSSHSupport ''
|
2017-05-25 21:14:39 +02:00
|
|
|
if [ -z "$SSH_AUTH_SOCK" ]; then
|
|
|
|
export SSH_AUTH_SOCK=$(${pkgs.gnupg}/bin/gpgconf --list-dirs agent-ssh-socket)
|
|
|
|
fi
|
2019-02-23 19:20:12 +01:00
|
|
|
'';
|
2017-05-25 21:14:39 +02:00
|
|
|
|
|
|
|
assertions = [
|
2017-07-11 01:24:13 +02:00
|
|
|
{ assertion = cfg.agent.enableSSHSupport -> !config.programs.ssh.startAgent;
|
2017-05-25 21:14:39 +02:00
|
|
|
message = "You can't use ssh-agent and GnuPG agent with SSH support enabled at the same time!";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|