diff --git a/guix/inferior.scm b/guix/inferior.scm index 680fe6a805b..1440c684ccd 100644 --- a/guix/inferior.scm +++ b/guix/inferior.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2018-2024 Ludovic Courtès +;;; Copyright © 2018-2025 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -860,9 +860,13 @@ failing when GUIX is too old and lacks the 'guix repl' command." ;;; (define %inferior-cache-directory - ;; Directory for cached inferiors (GC roots). - (make-parameter (string-append (cache-directory #:ensure? #f) - "/inferiors"))) + ;; Directory for cached inferiors (GC roots). It must be world-readable so + ;; the daemon can traverse it. + (make-parameter (string-append %profile-directory "/inferiors"))) + +(define %legacy-inferior-cache-directory + ;; Former directory for cached inferiors, by default under $HOME/.cache. + (string-append (cache-directory #:ensure? #f) "/inferiors")) (define* (channel-full-commit channel #:key (verify-certificate? #t)) "Return the commit designated by CHANNEL as quickly as possible. If @@ -950,6 +954,14 @@ X.509 host certificate; otherwise, warn about the problem and keep going." #:entry-expiration (file-expiration-time ttl)) + ;; Clean the legacy cache directory as well. Remove this call once at least + ;; one year has passed. + (maybe-remove-expired-cache-entries %legacy-inferior-cache-directory + cache-entries + #:entry-expiration + (file-expiration-time ttl)) + + (if (file-exists? cached) cached (run-with-store store diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index 41353e33053..15b84afb7fd 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -793,11 +793,24 @@ WHILE-LIST." (define (nesting-mappings) ;; Files shared with the host when enabling nesting. + + ;; Make sure these two directories exist so they can be shared. + (mkdir-p (string-append %profile-directory "/profiles")) + (mkdir-p (string-append %profile-directory "/inferiors")) + (cons* (file-system-mapping (source (%store-prefix)) (target source)) (file-system-mapping - (source (cache-directory)) + (source (cache-directory)) ;~/.cache/guix/checkouts etc. + (target source) + (writable? #t)) + (file-system-mapping ;'guix shell' cached GC roots + (source (string-append %profile-directory "/profiles")) + (target source) + (writable? #t)) + (file-system-mapping ;'guix time-machine' cached GC roots + (source (string-append %profile-directory "/inferiors")) (target source) (writable? #t)) (let ((uri (string->uri (%daemon-socket-uri)))) diff --git a/guix/scripts/shell.scm b/guix/scripts/shell.scm index d23362a15d5..80251606a32 100644 --- a/guix/scripts/shell.scm +++ b/guix/scripts/shell.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2021-2024 Ludovic Courtès +;;; Copyright © 2021-2025 Ludovic Courtès ;;; Copyright © 2023 Janneke Nieuwenhuizen ;;; ;;; This file is part of GNU Guix. @@ -327,10 +327,13 @@ echo ~a >> ~a ;;; (define %profile-cache-directory - ;; Directory where profiles created by 'guix shell' alone (without extra - ;; options) are cached. - (make-parameter (string-append (cache-directory #:ensure? #f) - "/profiles"))) + ;; Directory where profiles (GC roots) created by 'guix shell' are cached. + ;; It must be world-readable so the daemon can traverse it. + (make-parameter (string-append %profile-directory "/profiles"))) + +(define %legacy-cache-directory + ;; Former cache directory, by default under $HOME/.cache. + (string-append (cache-directory #:ensure? #f) "/profiles")) (define (profile-cache-primary-key) "Return the \"primary key\" used when computing keys for the profile cache. @@ -592,6 +595,13 @@ to make sure your shell does not clobber environment variables."))) ) (maybe-remove-expired-cache-entries (%profile-cache-directory) cache-entries + #:entry-expiration entry-expiration) + + ;; Clean the legacy cache directory as well. Remove this + ;; call once at least one year has passed. + (maybe-remove-expired-cache-entries + %legacy-cache-directory + cache-entries #:entry-expiration entry-expiration))) (if (assoc-ref opts 'export-manifest?)