summary refs log tree commit diff
path: root/guix/inferior.scm
diff options
context:
space:
mode:
authorMathieu Othacehe <othacehe@gnu.org>2021-03-05 09:51:42 +0100
committerMathieu Othacehe <othacehe@gnu.org>2021-03-10 08:49:48 +0100
commit7d63b775513e7049047222dbe403a4181f63828d (patch)
treeefb28c5fa392b5b9c602316a468226ea7ddba874 /guix/inferior.scm
parent0be2474d42990871170578e3a14a2e6b548157bd (diff)
downloadguix-7d63b775513e7049047222dbe403a4181f63828d.tar.gz
inferior: Break cached-channel-instance into two procedures.
Break cached-channel-instance into two different procedures:
channels->cached-profile and instances->cached-profile operating respectively
on channels and channels instances.

* guix/inferior.scm (cached-channel-instance): Rename it into ...
(cached-profile): ... this new procedure.
(channels->cached-profile, instances->cached-profile): New procedures.
* guix/scripts/time-machine.scm (guix-time-machine): Adapt accordingly.
Diffstat (limited to 'guix/inferior.scm')
-rw-r--r--guix/inferior.scm82
1 files changed, 55 insertions, 27 deletions
diff --git a/guix/inferior.scm b/guix/inferior.scm
index 0990696e6c..714e1e1eae 100644
--- a/guix/inferior.scm
+++ b/guix/inferior.scm
@@ -98,7 +98,8 @@
             gexp->derivation-in-inferior
 
             %inferior-cache-directory
-            cached-channel-instance
+            channels->cached-profile
+            instances->cached-profile
             inferior-for-channels))
 
 ;;; Commentary:
@@ -708,22 +709,14 @@ prefix, resolve it; and if 'commit' is unset, fetch CHANNEL's branch tip."
                                              #:check-out? #f)))
           commit))))
 
-(define* (cached-channel-instance store
-                                  channels
-                                  #:key
-                                  (authenticate? #t)
-                                  (cache-directory (%inferior-cache-directory))
-                                  (ttl (* 3600 24 30)))
-  "Return a directory containing a guix filetree defined by CHANNELS, a list of channels.
-The directory is a subdirectory of CACHE-DIRECTORY, where entries can be reclaimed after TTL seconds.
-This procedure opens a new connection to the build daemon.  AUTHENTICATE?
-determines whether CHANNELS are authenticated."
-  (define commits
-    ;; Since computing the instances of CHANNELS is I/O-intensive, use a
-    ;; cheaper way to get the commit list of CHANNELS.  This limits overhead
-    ;; to the minimum in case of a cache hit.
-    (map channel-full-commit channels))
-
+(define* (cached-profile store instances
+                         #:key
+                         cache-directory
+                         commits ttl)
+  "Return a directory containing a guix filetree defined by INSTANCES, a
+procedure returning a list of channel instances.  The directory is a
+subdirectory of CACHE-DIRECTORY, where entries can be reclaimed after TTL
+seconds.  This procedure opens a new connection to the build daemon."
   (define key
     (bytevector->base32-string
      (sha256
@@ -755,12 +748,8 @@ determines whether CHANNELS are authenticated."
   (if (file-exists? cached)
       cached
       (run-with-store store
-        (mlet* %store-monad ((instances
-                              -> (latest-channel-instances store channels
-                                                           #:authenticate?
-                                                           authenticate?))
-                             (profile
-                              (channel-instances->derivation instances)))
+        (mlet* %store-monad ((profile
+                              (channel-instances->derivation (instances))))
           (mbegin %store-monad
             (show-what-to-build* (list profile))
             (built-derivations (list profile))
@@ -770,6 +759,45 @@ determines whether CHANNELS are authenticated."
             (add-indirect-root* cached)
             (return cached))))))
 
+(define* (channels->cached-profile store channels
+                                   #:key
+                                   (authenticate? #t)
+                                   (cache-directory
+                                    (%inferior-cache-directory))
+                                   (ttl (* 3600 24 30)))
+  "Return a cached profile from CHANNELS using the CACHED-PROFILE procedure.
+AUTHENTICATE? determines whether CHANNELS are authenticated."
+  (define commits
+    ;; Since computing the instances of CHANNELS is I/O-intensive, use a
+    ;; cheaper way to get the commit list of CHANNELS.  This limits overhead
+    ;; to the minimum in case of a cache hit.
+    (map channel-full-commit channels))
+
+  (define instances
+    (lambda ()
+      (latest-channel-instances store channels
+                                #:authenticate? authenticate?)))
+
+  (cached-profile store instances
+                  #:cache-directory cache-directory
+                  #:commits commits
+                  #:ttl ttl))
+
+(define* (instances->cached-profile store instances
+                                    #:key
+                                    (cache-directory
+                                     (%inferior-cache-directory))
+                                    (ttl (* 3600 24 30)))
+  "Return a cached profile from INSTANCES a list of channel instances using
+the CACHED-PROFILE procedure."
+  (define commits
+    (map channel-instance-commit instances))
+
+  (cached-profile store (lambda () instances)
+                  #:cache-directory cache-directory
+                  #:commits commits
+                  #:ttl ttl))
+
 (define* (inferior-for-channels channels
                                 #:key
                                 (cache-directory (%inferior-cache-directory))
@@ -782,10 +810,10 @@ This is a convenience procedure that people may use in manifests passed to
 'guix package -m', for instance."
   (define cached
     (with-store store
-      (cached-channel-instance store
-                               channels
-                               #:cache-directory cache-directory
-                               #:ttl ttl)))
+      (channels->cached-profile store
+                                channels
+                                #:cache-directory cache-directory
+                                #:ttl ttl)))
   (open-inferior cached))
 
 ;;; Local Variables: