diff options
| author | Maxim Cournoyer <maxim@guixotic.coop> | 2025-11-13 09:23:34 +0900 |
|---|---|---|
| committer | Maxim Cournoyer <maxim@guixotic.coop> | 2025-12-01 14:59:30 +0900 |
| commit | c4298638ca27717be4a83cb033dcbfecdea88093 (patch) | |
| tree | b607390b81afa68d9833df31212519ed1e9733ec /gnu/build | |
| parent | 83690f15c3a51600274a279f696f1b988e47921c (diff) | |
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 <ludo@gnu.org>
Diffstat (limited to 'gnu/build')
| -rw-r--r-- | gnu/build/activation.scm | 41 |
1 files 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 @@ | |||
| 11 | ;;; Copyright © 2022 Tobias Geerinckx-Rice <me@tobias.gr> | 11 | ;;; Copyright © 2022 Tobias Geerinckx-Rice <me@tobias.gr> |
| 12 | ;;; Copyright © 2024 Nicolas Graves <ngraves@ngraves.fr> | 12 | ;;; Copyright © 2024 Nicolas Graves <ngraves@ngraves.fr> |
| 13 | ;;; Copyright © 2024 Giacomo Leidi <goodoldpaul@autistici.org> | 13 | ;;; Copyright © 2024 Giacomo Leidi <goodoldpaul@autistici.org> |
| 14 | ;;; Copyright © 2025 Maxim Cournoyer <maxim@guixotic.coop> | ||
| 14 | ;;; | 15 | ;;; |
| 15 | ;;; This file is part of GNU Guix. | 16 | ;;; This file is part of GNU Guix. |
| 16 | ;;; | 17 | ;;; |
| @@ -278,6 +279,17 @@ they already exist." | |||
| 278 | 279 | ||
| 279 | (for-each ensure-user-home users)) | 280 | (for-each ensure-user-home users)) |
| 280 | 281 | ||
| 282 | (define* (canonicalize-path* file) | ||
| 283 | "A safe version of `canonicalize-path' that warns rather than raises on errors. | ||
| 284 | `canonicalize-path' uses `realpath(2)', which can return various errors like | ||
| 285 | EINVAL, ELOOP, etc." | ||
| 286 | (or (false-if-exception (canonicalize-path file)) | ||
| 287 | (begin | ||
| 288 | (format (warning-error-port) | ||
| 289 | "warning: could not canonicalize file `~a'; using as-is~%" | ||
| 290 | file) | ||
| 291 | file))) | ||
| 292 | |||
| 281 | (define (activate-etc etc) | 293 | (define (activate-etc etc) |
| 282 | "Install ETC, a directory in the store, as the source of static files for | 294 | "Install ETC, a directory in the store, as the source of static files for |
| 283 | /etc." | 295 | /etc." |
| @@ -300,26 +312,23 @@ they already exist." | |||
| 300 | (rm-f "/etc/ssl") | 312 | (rm-f "/etc/ssl") |
| 301 | (symlink "/run/current-system/profile/etc/ssl" "/etc/ssl") | 313 | (symlink "/run/current-system/profile/etc/ssl" "/etc/ssl") |
| 302 | 314 | ||
| 303 | (rm-f "/etc/static") | ||
| 304 | (symlink etc "/etc/static") | ||
| 305 | (for-each (lambda (file) | 315 | (for-each (lambda (file) |
| 306 | (let ((target (string-append "/etc/" file)) | 316 | (let ((target (string-append "/etc/" file)) |
| 307 | (source (string-append "/etc/static/" file))) | 317 | ;; Canonicalize the file names to resolve any symlinks, to |
| 318 | ;; ensure /etc/localtime points to a timezone data file in | ||
| 319 | ;; the store containing the timezone name. This is done | ||
| 320 | ;; for compatibility with software expecting this systemd | ||
| 321 | ;; convention to be followed. | ||
| 322 | (source (canonicalize-path* (string-append etc "/" file)))) | ||
| 308 | (rm-f target) | 323 | (rm-f target) |
| 309 | 324 | (if (string=? (basename target) "sudoers") | |
| 310 | ;; Things such as /etc/sudoers must be regular files, not | 325 | (begin |
| 311 | ;; symlinks; furthermore, they could be modified behind our | 326 | ;; /etc/sudoers must be a regular file. |
| 312 | ;; back---e.g., with 'visudo'. Thus, make a copy instead of | 327 | (copy-file source target) |
| 313 | ;; symlinking them. | 328 | ;; XXX: dirty hack to meet sudo's expectations |
| 314 | (if (file-is-directory? source) | 329 | (chmod target #o440)) |
| 315 | (symlink source target) | 330 | (symlink source target)))) ;usual case |
| 316 | (copy-file source target)) | ||
| 317 | |||
| 318 | ;; XXX: Dirty hack to meet sudo's expectations. | ||
| 319 | (when (string=? (basename target) "sudoers") | ||
| 320 | (chmod target #o440)))) | ||
| 321 | (scandir etc (negate dot-or-dot-dot?) | 331 | (scandir etc (negate dot-or-dot-dot?) |
| 322 | |||
| 323 | ;; The default is 'string-locale<?', but we don't have | 332 | ;; The default is 'string-locale<?', but we don't have |
| 324 | ;; it when run from the initrd's statically-linked | 333 | ;; it when run from the initrd's statically-linked |
| 325 | ;; Guile. | 334 | ;; Guile. |
