[Services/GnuPG] fix GPG issues when no tty is available (i.e. when ran by Pycharm)

This commit is contained in:
Antoine Viallon 2023-05-11 19:17:55 +02:00
parent 8326fa4d6e
commit e17b382062
Signed by: aviallon
GPG key ID: 186FC35EDEB25716

View file

@ -1,6 +1,10 @@
{ config, pkgs, lib, ... }: { config, pkgs, lib, ... }:
with lib; with lib;
{ let
gpgNoTTY = pkgs.writeShellScriptBin "gpg-no-tty" ''
exec ${pkgs.gnupg}/bin/gpg --batch --no-tty "$@"
'';
in {
config = { config = {
programs.gnupg = { programs.gnupg = {
@ -13,11 +17,19 @@ with lib;
}; };
environment.shellInit = '' environment.shellInit = ''
export GPG_TTY="$(tty)" if tty --silent; then
gpg-connect-agent /bye export GPG_TTY="$(tty)"
export SSH_AUTH_SOCK="/run/user/$UID/gnupg/S.gpg-agent.ssh" gpg-connect-agent /bye
export SSH_AUTH_SOCK="/run/user/$UID/gnupg/S.gpg-agent.ssh"
else
alias gpg=${gpgNoTTY}/bin/gpg-no-tty
fi
''; '';
environment.systemPackages = [
gpgNoTTY
];
systemd.user.services.gpg-agent = let systemd.user.services.gpg-agent = let
pinentrySwitcher = pkgs.callPackage ../packages/pinentry.nix {}; pinentrySwitcher = pkgs.callPackage ../packages/pinentry.nix {};
cfg = config.programs.gnupg; cfg = config.programs.gnupg;