From c4298638ca27717be4a83cb033dcbfecdea88093 Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Thu, 13 Nov 2025 09:23:34 +0900 Subject: [PATCH] build/activation: Simplify the creation of /etc. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not add a an extraneous /etc/static layer of indirection. * gnu/build/activation.scm (activate-etc) : New nested procedure. Do not create /etc/static. Symlink instead of copy all files under /etc, except for /etc/sudoers. Change-Id: I8ea16d07de256482efac37d2ff9482a5f56bd585 Reviewed-by: Ludovic Courtès --- gnu/build/activation.scm | 41 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/gnu/build/activation.scm b/gnu/build/activation.scm index 272a7892910..690d86a0383 100644 --- a/gnu/build/activation.scm +++ b/gnu/build/activation.scm @@ -11,6 +11,7 @@ ;;; Copyright © 2022 Tobias Geerinckx-Rice ;;; Copyright © 2024 Nicolas Graves ;;; Copyright © 2024 Giacomo Leidi +;;; Copyright © 2025 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -278,6 +279,17 @@ they already exist." (for-each ensure-user-home users)) +(define* (canonicalize-path* file) + "A safe version of `canonicalize-path' that warns rather than raises on errors. +`canonicalize-path' uses `realpath(2)', which can return various errors like +EINVAL, ELOOP, etc." + (or (false-if-exception (canonicalize-path file)) + (begin + (format (warning-error-port) + "warning: could not canonicalize file `~a'; using as-is~%" + file) + file))) + (define (activate-etc etc) "Install ETC, a directory in the store, as the source of static files for /etc." @@ -300,26 +312,23 @@ they already exist." (rm-f "/etc/ssl") (symlink "/run/current-system/profile/etc/ssl" "/etc/ssl") - (rm-f "/etc/static") - (symlink etc "/etc/static") (for-each (lambda (file) (let ((target (string-append "/etc/" file)) - (source (string-append "/etc/static/" file))) + ;; Canonicalize the file names to resolve any symlinks, to + ;; ensure /etc/localtime points to a timezone data file in + ;; the store containing the timezone name. This is done + ;; for compatibility with software expecting this systemd + ;; convention to be followed. + (source (canonicalize-path* (string-append etc "/" file)))) (rm-f target) - - ;; Things such as /etc/sudoers must be regular files, not - ;; symlinks; furthermore, they could be modified behind our - ;; back---e.g., with 'visudo'. Thus, make a copy instead of - ;; symlinking them. - (if (file-is-directory? source) - (symlink source target) - (copy-file source target)) - - ;; XXX: Dirty hack to meet sudo's expectations. - (when (string=? (basename target) "sudoers") - (chmod target #o440)))) + (if (string=? (basename target) "sudoers") + (begin + ;; /etc/sudoers must be a regular file. + (copy-file source target) + ;; XXX: dirty hack to meet sudo's expectations + (chmod target #o440)) + (symlink source target)))) ;usual case (scandir etc (negate dot-or-dot-dot?) - ;; The default is 'string-locale