Subject: [PATCH] gnu: Prevent stale cache use when `%package-module-path' is parameterized.

From: antlers <[email-masked]>
Date: Sun, 31 Dec 2023 06:06:21 +0000

* gnu/packages.scm(find-package-by-name/direct): Convert `delay'-ed cache
construction in closure into a form memoized over `%package-module-path'.

Change-Id: I6e4b4b3fa58082b79aacf307468aec43ec60bf22
---
This enables `specification->package' to be parameterized to resolve packages
from within the module-under-compilation.

I use this to parse my init.el[0] into packages in my guix-home profile, all
in one repo.

 gnu/packages.scm | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/gnu/packages.scm b/gnu/packages.scm
index 80c22d1d7f..b0cc2f7427 100644
--- a/gnu/packages.scm
+++ b/gnu/packages.scm
@@ -281,18 +281,21 @@ (define load-package-cache
                #f
                (apply throw args))))))))
 
-(define find-packages-by-name/direct              ;bypass the cache
-  (let ((packages (delay
-                    (fold-packages (lambda (p r)
-                                     (vhash-cons (package-name p) p r))
-                                   vlist-null)))
+(define find-packages-by-name/direct
+  ;; Bypass pre-built cache, but still memoize over `(%package-module-path)'
+  (let ((packages (lambda ()
+                    ((mlambda (_%package-module-path)
+                       (fold-packages (lambda (p r)
+                                        (vhash-cons (package-name p) p r))
+                                      vlist-null))
+                     (%package-module-path))))
         (version>? (lambda (p1 p2)
                      (version>? (package-version p1) (package-version p2)))))
     (lambda* (name #:optional version)
       "Return the list of packages with the given NAME.  If VERSION is not #f,
 then only return packages whose version is prefixed by VERSION, sorted in
 decreasing version order."
-      (let ((matching (sort (vhash-fold* cons '() name (force packages))
+      (let ((matching (sort (vhash-fold* cons '() name (packages))
                             version>?)))
         (if version
             (filter (lambda (package)

base-commit: 2a242e86379ebddbdddf2927f26e5e27a98fc605
-- 
2.41.0