summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNox <noximilien@riseup.net>2026-07-01 14:23:41 +0200
committerLudovic Courtès <ludo@gnu.org>2026-08-27 14:41:26 +0200
commitd5a73f4734f21ac15b9ade3ec71162f00ae746c4 (patch)
treead983ef51502d13adc3d7f17b671a0305f2b3b4e
parent8a1a029f8fb6360d4b2c955e55f46b99f02a5c0f (diff)
home: services: Add GnuPG home directory configuration.
* gnu/home/services/gnupg.scm (home-gpg-agent-configuration) [home]: New field. (home-gpg-agent-files): Use it. (gpg-agent-activation): Use it (edited into a procedure). (home-gpg-agent-service-type): Use it. (sanitize-home): New procedure. * doc/guix.texi: Update it. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Merges: #9655
-rw-r--r--doc/guix.texi8
-rw-r--r--gnu/home/services/gnupg.scm32
2 files changed, 26 insertions, 14 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index 19be19c6d20..b30237e21ce 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -54909,6 +54909,10 @@ Pinentry program to use. Pinentry is a small user interface that
54909passphrase or @acronym{PIN,personal identification number} 54909passphrase or @acronym{PIN,personal identification number}
54910(@pxref{Top,,, pinentry,Using the PIN-Entry}). 54910(@pxref{Top,,, pinentry,Using the PIN-Entry}).
54911 54911
54912@item @code{home} (default: @code{"~/.gnupg"}) (type: string)
54913The GnuPG home directory, relative to @var{$HOME}. Defaults to
54914@file{~/.gnupg}.
54915
54912@item @code{ssh-support?} (default: @code{#f}) (type: boolean) 54916@item @code{ssh-support?} (default: @code{#f}) (type: boolean)
54913Whether to enable @acronym{SSH,secure shell} support. When true, 54917Whether to enable @acronym{SSH,secure shell} support. When true,
54914@command{gpg-agent} acts as a drop-in replacement for OpenSSH's 54918@command{gpg-agent} acts as a drop-in replacement for OpenSSH's
@@ -54929,9 +54933,9 @@ Time a cache entry for SSH keys is valid, in seconds.
54929Maximum time a cache entry for SSH keys is valid, in seconds. 54933Maximum time a cache entry for SSH keys is valid, in seconds.
54930 54934
54931@item @code{extra-content} (default: @code{""}) (type: raw-configuration-string) 54935@item @code{extra-content} (default: @code{""}) (type: raw-configuration-string)
54932Raw content to add to the end of @file{~/.gnupg/gpg-agent.conf}. 54936Raw content to add to the end of @file{gpg-agent.conf}.
54933 54937
54934@item @code{shepherd-requirement} (default: @code{'()}) (type: list-of-symbols) 54938@item @code{shepherd-requirement} (default: @code{()}) (type: list-of-symbols)
54935List of services that should be started before this service. 54939List of services that should be started before this service.
54936 54940
54937@end table 54941@end table
diff --git a/gnu/home/services/gnupg.scm b/gnu/home/services/gnupg.scm
index bbc83492260..38fa58e2fab 100644
--- a/gnu/home/services/gnupg.scm
+++ b/gnu/home/services/gnupg.scm
@@ -30,6 +30,7 @@
30 home-gpg-agent-configuration? 30 home-gpg-agent-configuration?
31 home-gpg-agent-configuration-gnupg 31 home-gpg-agent-configuration-gnupg
32 home-gpg-agent-configuration-pinentry-program 32 home-gpg-agent-configuration-pinentry-program
33 home-gpg-agent-configuration-home
33 home-gpg-agent-configuration-ssh-support? 34 home-gpg-agent-configuration-ssh-support?
34 home-gpg-agent-configuration-default-cache-ttl 35 home-gpg-agent-configuration-default-cache-ttl
35 home-gpg-agent-configuration-max-cache-ttl 36 home-gpg-agent-configuration-max-cache-ttl
@@ -60,6 +61,9 @@
60@command{gpg-agent} delegates to anytime it needs user input for a passphrase 61@command{gpg-agent} delegates to anytime it needs user input for a passphrase
61or @acronym{PIN, personal identification number} (@pxref{Top,,, pinentry, 62or @acronym{PIN, personal identification number} (@pxref{Top,,, pinentry,
62Using the PIN-Entry}).") 63Using the PIN-Entry}).")
64 (home
65 (string ".gnupg")
66 "The GnuPG home directory, relative to @var{$HOME}. Defaults to @file{.gnupg}.")
63 (ssh-support? 67 (ssh-support?
64 (boolean #f) 68 (boolean #f)
65 "Whether to enable @acronym{SSH, secure shell} support. When true, 69 "Whether to enable @acronym{SSH, secure shell} support. When true,
@@ -81,7 +85,7 @@ entry will be expired even if it has been accessed recently.")
81 "Maximum time a cache entry for SSH keys is valid, in seconds.") 85 "Maximum time a cache entry for SSH keys is valid, in seconds.")
82 (extra-content 86 (extra-content
83 (raw-configuration-string "") 87 (raw-configuration-string "")
84 "Raw content to add to the end of @file{~/.gnupg/gpg-agent.conf}.") 88 "Raw content to add to the end of @file{gpg-agent.conf}.")
85 (shepherd-requirement 89 (shepherd-requirement
86 (list-of-symbols '()) 90 (list-of-symbols '())
87 "List of services that should be started before this service.")) 91 "List of services that should be started before this service."))
@@ -147,25 +151,29 @@ agent, with support for handling OpenSSH material."))))
147 '()))) 151 '())))
148 152
149(define (home-gpg-agent-files config) 153(define (home-gpg-agent-files config)
150 `((".gnupg/gpg-agent.conf" ,(home-gpg-agent-configuration-file config)))) 154 `((,(in-vicinity
155 (home-gpg-agent-configuration-home config) "gpg-agent.conf")
156 ,(home-gpg-agent-configuration-file config))))
151 157
152(define (home-gpg-agent-environment-variables config) 158(define (home-gpg-agent-environment-variables config)
153 "Return GnuPG environment variables needed for @var{config}." 159 "Return GnuPG environment variables needed for @var{config}."
154 (if (home-gpg-agent-configuration-ssh-support? config) 160 (let ((home (getenv "HOME"))
155 `(("SSH_AUTH_SOCK" 161 (gnupghome (home-gpg-agent-configuration-home config)))
156 . "$XDG_RUNTIME_DIR/gnupg/S.gpg-agent.ssh")) 162 `(,@(if (home-gpg-agent-configuration-ssh-support? config)
157 '())) 163 '(("SSH_AUTH_SOCK" . "$XDG_RUNTIME_DIR/gnupg/S.gpg-agent.ssh"))
164 '())
165 ("GNUPGHOME" . ,(in-vicinity home gnupghome)))))
158 166
159(define gpg-agent-activation 167(define (gpg-agent-activation config)
160 (with-imported-modules (source-module-closure 168 (with-imported-modules (source-module-closure
161 '((gnu build activation))) 169 '((gnu build activation)))
162 #~(begin 170 #~(begin
163 (use-modules (gnu build activation)) 171 (use-modules (gnu build activation))
164 172
165 ;; Make sure ~/.gnupg is #o700. 173 ;; Make sure GnuPG home is #o700.
166 (let* ((home (getenv "HOME")) 174 (let ((home (getenv "HOME"))
167 (dot-ssh (string-append home "/.gnupg"))) 175 (gnupghome #$(home-gpg-agent-configuration-home config)))
168 (mkdir-p/perms dot-ssh (getpw (getuid)) #o700))))) 176 (mkdir-p/perms (in-vicinity home gnupghome) (getpw (getuid)) #o700)))))
169 177
170(define home-gpg-agent-service-type 178(define home-gpg-agent-service-type
171 (service-type 179 (service-type
@@ -176,7 +184,7 @@ agent, with support for handling OpenSSH material."))))
176 (service-extension home-shepherd-service-type 184 (service-extension home-shepherd-service-type
177 home-gpg-agent-shepherd-services) 185 home-gpg-agent-shepherd-services)
178 (service-extension home-activation-service-type 186 (service-extension home-activation-service-type
179 (const gpg-agent-activation)) 187 gpg-agent-activation)
180 (service-extension home-environment-variables-service-type 188 (service-extension home-environment-variables-service-type
181 home-gpg-agent-environment-variables))) 189 home-gpg-agent-environment-variables)))
182 (default-value (home-gpg-agent-configuration)) 190 (default-value (home-gpg-agent-configuration))