gpg-agent: add launchd service agent and sockets

This adds a Darwin Launchd agent along with its sockets to make
gpg-agent starts at load or whenever the sockets are needed.

Fixes: https://github.com/nix-community/home-manager/issues/3864
This commit is contained in:
Ayman Bagabas 2024-08-31 21:12:16 -04:00 committed by Robert Helgesson
parent c82fc8cf3f
commit ef50612457
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED
6 changed files with 151 additions and 87 deletions

View file

@ -2,7 +2,7 @@
with lib;
{
mkIf pkgs.stdenv.isLinux {
config = {
services.gpg-agent.enable = true;
services.gpg-agent.pinentryPackage = pkgs.pinentry-gnome3;

View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>GNUPGHOME</key>
<string>/path/to/hash</string>
</dict>
<key>KeepAlive</key>
<dict>
<key>Crashed</key>
<true/>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>org.nix-community.home.gpg-agent</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>
<array>
<string>@gpg@/bin/gpg-agent</string>
<string>--supervised</string>
</array>
<key>RunAtLoad</key>
<false/>
<key>Sockets</key>
<dict>
<key>Agent</key>
<dict>
<key>SockPathMode</key>
<integer>384</integer>
<key>SockPathName</key>
<string>/private/var/run/org.nix-community.home.gpg-agent/d.wp4h7ks5zxy4dodqadgpbbpz/S.gpg-agent</string>
<key>SockType</key>
<string>stream</string>
</dict>
</dict>
</dict>
</plist>

View file

@ -2,19 +2,25 @@
with lib;
{
let inherit (pkgs.stdenv) isDarwin;
in {
config = {
services.gpg-agent.enable = true;
services.gpg-agent.pinentryPackage = null; # Don't build pinentry package.
programs.gpg = {
enable = true;
homedir = "/path/to/hash";
package = config.lib.test.mkStubPackage { outPath = "@gpg@"; };
};
test.stubs.gnupg = { };
test.stubs.systemd = { }; # depends on gnupg.override
nmt.script = ''
nmt.script = if isDarwin then ''
serviceFile=LaunchAgents/org.nix-community.home.gpg-agent.plist
assertFileExists "$serviceFile"
assertFileContent "$serviceFile" ${./expected-agent.plist}
'' else ''
in="${config.systemd.user.sockets.gpg-agent.Socket.ListenStream}"
if [[ $in != "%t/gnupg/d.wp4h7ks5zxy4dodqadgpbbpz/S.gpg-agent" ]]
then