unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Konrad Hinsen <konrad.hinsen@fastmail.net>
To: 37978@debbugs.gnu.org
Subject: [bug#37978] [PATCH 2/3] guix: don't connect to daemon in cached-channel-instance
Date: Tue, 12 Nov 2019 16:39:46 +0100	[thread overview]
Message-ID: <m1woc5gkg0.fsf@fastmail.net> (raw)
In-Reply-To: <m1bltzd4z7.fsf@ordinateur-de-catherine--konrad.home>

* guix/inferior.scm (cached-channel-instance): take an explicit store argument
* guix/inferior.scm (inferior-for-channels): wrap call to
  cached-channel-instance in with-store
* guix/time-machine.scm (guix-time-machine): wrap call to
  cached-channel-instance in with-store
---
 guix/inferior.scm             | 99 ++++++++++++++++++-----------------
 guix/scripts/time-machine.scm |  4 +-
 2 files changed, 53 insertions(+), 50 deletions(-)

diff --git a/guix/inferior.scm b/guix/inferior.scm
index be50e0ec26..71dae89e92 100644
--- a/guix/inferior.scm
+++ b/guix/inferior.scm
@@ -636,58 +636,57 @@ failing when GUIX is too old and lacks the 'guix repl' command."
   (make-parameter (string-append (cache-directory #:ensure? #f)
                                  "/inferiors")))
 
-(define* (cached-channel-instance channels
+(define* (cached-channel-instance store
+                                  channels
                                   #:key
                                   (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."
-  (with-store store
-    (let ()
-      (define instances
-        (latest-channel-instances store channels))
-
-      (define key
-        (bytevector->base32-string
-         (sha256
-          (string->utf8
-           (string-concatenate (map channel-instance-commit instances))))))
-
-      (define cached
-        (string-append cache-directory "/" key))
-
-      (define (base32-encoded-sha256? str)
-        (= (string-length str) 52))
-
-      (define (cache-entries directory)
-        (map (lambda (file)
-               (string-append directory "/" file))
-             (scandir directory base32-encoded-sha256?)))
-
-      (define symlink*
-        (lift2 symlink %store-monad))
-
-      (define add-indirect-root*
-        (store-lift add-indirect-root))
-
-      (mkdir-p cache-directory)
-      (maybe-remove-expired-cache-entries cache-directory
-                                          cache-entries
-                                          #:entry-expiration
-                                          (file-expiration-time ttl))
-
-      (if (file-exists? cached)
-          cached
-          (run-with-store store
-            (mlet %store-monad ((profile
-                                 (channel-instances->derivation instances)))
-              (mbegin %store-monad
-                (show-what-to-build* (list profile))
-                (built-derivations (list profile))
-                (symlink* (derivation->output-path profile) cached)
-                (add-indirect-root* cached)
-                (return cached))))))))
+  (define instances
+    (latest-channel-instances store channels))
+
+  (define key
+    (bytevector->base32-string
+     (sha256
+      (string->utf8
+       (string-concatenate (map channel-instance-commit instances))))))
+
+  (define cached
+    (string-append cache-directory "/" key))
+
+  (define (base32-encoded-sha256? str)
+    (= (string-length str) 52))
+
+  (define (cache-entries directory)
+    (map (lambda (file)
+           (string-append directory "/" file))
+         (scandir directory base32-encoded-sha256?)))
+
+  (define symlink*
+    (lift2 symlink %store-monad))
+
+  (define add-indirect-root*
+    (store-lift add-indirect-root))
+
+  (mkdir-p cache-directory)
+  (maybe-remove-expired-cache-entries cache-directory
+                                      cache-entries
+                                      #:entry-expiration
+                                      (file-expiration-time ttl))
+
+  (if (file-exists? cached)
+      cached
+      (run-with-store store
+        (mlet %store-monad ((profile
+                             (channel-instances->derivation instances)))
+          (mbegin %store-monad
+            (show-what-to-build* (list profile))
+            (built-derivations (list profile))
+            (symlink* (derivation->output-path profile) cached)
+            (add-indirect-root* cached)
+            (return cached))))))
 
 (define* (inferior-for-channels channels
                                 #:key
@@ -700,7 +699,9 @@ procedure opens a new connection to the build daemon.
 This is a convenience procedure that people may use in manifests passed to
 'guix package -m', for instance."
   (define cached
-    (cached-channel-instance channels
-                             #:cache-directory cache-directory
-                             #:ttl ttl))
+    (with-store store
+      (cached-channel-instance store
+                               channels
+                               #:cache-directory cache-directory
+                               #:ttl ttl)))
   (open-inferior cached))
diff --git a/guix/scripts/time-machine.scm b/guix/scripts/time-machine.scm
index a6598fb0f7..a64badc27b 100644
--- a/guix/scripts/time-machine.scm
+++ b/guix/scripts/time-machine.scm
@@ -21,6 +21,7 @@
   #:use-module (guix scripts)
   #:use-module (guix inferior)
   #:use-module (guix channels)
+  #:use-module (guix store)
   #:use-module ((guix scripts pull) #:select (channel-list))
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-1)
@@ -97,6 +98,7 @@ Execute COMMAND ARGS... in an older version of Guix.\n"))
            (channels     (channel-list opts))
            (command-line (assoc-ref opts 'exec)))
       (when command-line
-        (let* ((directory  (cached-channel-instance channels))
+        (let* ((directory  (with-store store
+                             (cached-channel-instance store channels)))
                (executable (string-append directory "/bin/guix")))
           (apply execl (cons* executable executable command-line)))))))
-- 
2.24.0

      parent reply	other threads:[~2019-11-12 15:54 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-25 15:42 [bug#37978] [PATCH] guix: new command "guix time-machine" Konrad Hinsen
2019-10-25 15:42 ` [bug#37978] [PATCH 1/3] " Konrad Hinsen
2019-11-06 13:53 ` [bug#37978] [PATCH] " Ludovic Courtès
2019-11-06 14:27   ` Tobias Geerinckx-Rice via Guix-patches via
2019-11-07 13:11     ` Konrad Hinsen
2019-11-06 14:30   ` Ludovic Courtès
2019-11-07 19:40     ` Konrad Hinsen
2019-11-07 21:10       ` Ludovic Courtès
2019-11-08  7:14   ` Konrad Hinsen
2019-11-08 14:13     ` [bug#37978] [PATCH 1/2] " Konrad Hinsen
2019-11-10 12:00       ` Ludovic Courtès
2019-11-12 15:52         ` Konrad Hinsen
2019-11-08 14:15     ` [bug#37978] [PATCH 2/2] news: Add entry for " Konrad Hinsen
2019-11-08 20:43       ` pelzflorian (Florian Pelz)
2019-11-10 12:02         ` Ludovic Courtès
2019-11-08 14:16     ` [bug#37978] [PATCH] guix: new command " Konrad Hinsen
2019-11-15 22:35       ` bug#37978: " Ludovic Courtès
2019-11-16  9:06         ` [bug#37978] " Konrad Hinsen
2019-11-08 20:09     ` Ludovic Courtès
2019-11-08 10:16 ` [bug#37978] [PATCH 3/3] news: Add entry for " Konrad Hinsen
2019-11-08 14:15 ` [bug#37978] [PATCH 2/2] " Konrad Hinsen
2019-11-12 15:39 ` Konrad Hinsen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m1woc5gkg0.fsf@fastmail.net \
    --to=konrad.hinsen@fastmail.net \
    --cc=37978@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).