guix_mirror_bot pushed a commit to branch master
in repository guix.

commit c4298638ca27717be4a83cb033dcbfecdea88093
Author: Maxim Cournoyer <[email protected]>
AuthorDate: Thu Nov 13 09:23:34 2025 +0900

    build/activation: Simplify the creation of /etc.
    
    Do not add a an extraneous /etc/static layer of indirection.
    
    * gnu/build/activation.scm (activate-etc) <realpath>: 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 <[email protected]>
---
 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 272a789291..690d86a038 100644
--- a/gnu/build/activation.scm
+++ b/gnu/build/activation.scm
@@ -11,6 +11,7 @@
 ;;; Copyright © 2022 Tobias Geerinckx-Rice <[email protected]>
 ;;; Copyright © 2024 Nicolas Graves <[email protected]>
 ;;; Copyright © 2024 Giacomo Leidi <[email protected]>
+;;; Copyright © 2025 Maxim Cournoyer <[email protected]>
 ;;;
 ;;; 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<?', but we don't have
                      ;; it when run from the initrd's statically-linked
                      ;; Guile.

Reply via email to