services: guix: Factorize ‘guix-daemon’ arguments.

* gnu/services/base.scm (guix-shepherd-service): In ‘start’ method,
move ‘fork+exec-command/container’ arguments to the new variables
‘daemon-command’ and ‘environment-variables’.

Change-Id: Ic04a1006849697e4e185ad94185bbdec8a91a05a
This commit is contained in:
Ludovic Courtès 2025-03-22 17:36:42 +01:00
parent 21221710f2
commit b16e3f451f
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -2061,29 +2061,7 @@ proxy of 'guix-daemon'...~%")
(define discover?
(or (getenv "discover") #$discover?))
(mkdir-p "/var/guix")
;; Ensure that a fresh directory is used, in case the old
;; one was more permissive and processes have a file
;; descriptor referencing it hanging around, ready to use
;; with openat.
(false-if-exception
(delete-file-recursively "/var/guix/daemon-socket"))
(let ((perms #$(logand socket-directory-permissions
(lognot #o022))))
(mkdir "/var/guix/daemon-socket" perms)
;; Override umask
(chmod "/var/guix/daemon-socket" perms))
(let* ((user #$socket-directory-user)
(uid (if user (passwd:uid (getpwnam user)) -1))
(group #$socket-directory-group)
(gid (if group (group:gid (getgrnam group)) -1)))
(chown "/var/guix/daemon-socket" uid gid))
;; Start the guix-daemon from a container, when supported,
;; to solve an installation issue. See the comment below for
;; more details.
(fork+exec-command/container
(define daemon-command
(cons* #$(file-append guix "/bin/guix-daemon")
"--build-users-group" #$build-group
"--max-silent-time"
@ -2112,19 +2090,9 @@ proxy of 'guix-daemon'...~%")
(call-with-input-file file
read)))
'#$(map references-file
chroot-directories)))
chroot-directories))))
;; When running the installer, we need guix-daemon to
;; operate from within the same MNT namespace as the
;; installation container. In that case only, enter the
;; namespace of the process PID passed as start argument.
;; Otherwise, for symmetry purposes enter the caller
;; namespaces which is a no-op.
#:pid (match args
((pid) (string->number pid))
(else (getpid)))
#:environment-variables
(define environment-variables
(append (list #$@(if tmpdir
(list (string-append "TMPDIR=" tmpdir))
'())
@ -2148,8 +2116,43 @@ proxy of 'guix-daemon'...~%")
(list (string-append "http_proxy=" proxy)
(string-append "https_proxy=" proxy))
'())
'#$environment)
'#$environment))
(mkdir-p "/var/guix")
;; Ensure that a fresh directory is used, in case the old
;; one was more permissive and processes have a file
;; descriptor referencing it hanging around, ready to use
;; with openat.
(false-if-exception
(delete-file-recursively "/var/guix/daemon-socket"))
(let ((perms #$(logand socket-directory-permissions
(lognot #o022))))
(mkdir "/var/guix/daemon-socket" perms)
;; Override umask
(chmod "/var/guix/daemon-socket" perms))
(let* ((user #$socket-directory-user)
(uid (if user (passwd:uid (getpwnam user)) -1))
(group #$socket-directory-group)
(gid (if group (group:gid (getgrnam group)) -1)))
(chown "/var/guix/daemon-socket" uid gid))
;; Start the guix-daemon from a container, when supported,
;; to solve an installation issue. See the comment below for
;; more details.
(fork+exec-command/container
daemon-command
;; When running the installer, we need guix-daemon to
;; operate from within the same MNT namespace as the
;; installation container. In that case only, enter the
;; namespace of the process PID passed as start argument.
;; Otherwise, for symmetry purposes enter the caller
;; namespaces which is a no-op.
#:pid (match args
((pid) (string->number pid))
(else (getpid)))
#:environment-variables environment-variables
#:log-file #$log-file))))
(stop #~(make-kill-destructor))))))