Unfortunately I had a problem with my server that doesn’t have a desktop environment.
on that the gpg-agent was not falling back to the command line and was just giving error.
The solution was to used the “curses” flavor.
But weirdly the “curses” flavor doesn’t work when X display is activated, in other word when a desktop environment is there.
This is not very nice because now i have to handle two different config …
Digging a little bit it seems that the issue come from the gnupg that in one case will try to use the tty and in the other case will try to use X display and there is no easy way to force it.
Blockquote https://www.gnupg.org/documentation/manuals/gnupg/Agent-Options.html
Since the ssh-agent protocol does not contain a mechanism for telling the agent on which display/terminal it is running, gpg-agent’s ssh-support will use the TTY or X display where gpg-agent has been started.
Blockquote
looking more in detail, actually it detect out of box the correct pinentry flavor, so in most of the case it the pinentryFlavor option is even not needed.
After following all comments and suggestions I am struggling here on a laptop - it seems pinentry-curses was invoked, but I got no chance to type anything, as it ran to error without delay.
[nrb@mintanin:~]$ gpg --homedir . --quick-gen-key hovno
About to create a key for:
"hovno"
Continue? (Y/n) y
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: agent_genkey failed: No pinentry
Key generation failed: No pinentry
[nrb@mintanin:~]$
Don’t set home directory. It moves the agent socket location to some hashed directory for no reason and then starts its own agent because it cannot find the socket.
I think the problem is that documentation for GnuPG and Pinentry is strewn across the Wiki (but there is no GPG/GnuPG page), discourse, the nix-dev-mailing-list etc. but no official documentation. @colemickens Would you mind creating some documentation based on your config? Preferably a section in the NixOS manual?
Will be happy to review the PR.
I’m using home-manager to configure my gpg/gpg-agent, and I’m a bit occupied, so I’m not sure I can commit to that. However…
I simplified my gpg config (mostly cleaning un-used cruft from ages ago when I was testing various combos of scdaemon / pscslite / disable-ccid) in the meantime, re-tested, and pushed.
NOTE: At one point in time I was also convinced that it was important to restart the systemd user services for gpg-agent*, for example after killing gpg-agent by hand, rather than letting gpg naively trigger it to startup. I still have a (not-cleaned-up) fix-gpg script that does that.