From patchwork Tue Nov 12 15:39:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Hinsen X-Patchwork-Id: 16093 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 248A017737; Tue, 12 Nov 2019 15:54:11 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id CEE9F17735 for ; Tue, 12 Nov 2019 15:54:10 +0000 (GMT) Received: from localhost ([::1]:36968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUYUc-0007vU-DW for patchwork@mira.cbaines.net; Tue, 12 Nov 2019 10:54:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48764) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUYUV-0007ue-Ip for guix-patches@gnu.org; Tue, 12 Nov 2019 10:54:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUYUU-0007BM-6n for guix-patches@gnu.org; Tue, 12 Nov 2019 10:54:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:49426) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iUYUU-0007BA-38 for guix-patches@gnu.org; Tue, 12 Nov 2019 10:54:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iUYUT-0002xg-W0 for guix-patches@gnu.org; Tue, 12 Nov 2019 10:54:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#37978] [PATCH 2/3] guix: don't connect to daemon in cached-channel-instance References: In-Reply-To: Resent-From: Konrad Hinsen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 12 Nov 2019 15:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37978 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 37978@debbugs.gnu.org Received: via spool by 37978-submit@debbugs.gnu.org id=B37978.157357403011365 (code B ref 37978); Tue, 12 Nov 2019 15:54:01 +0000 Received: (at 37978) by debbugs.gnu.org; 12 Nov 2019 15:53:50 +0000 Received: from localhost ([127.0.0.1]:58247 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iUYUD-0002xA-NZ for submit@debbugs.gnu.org; Tue, 12 Nov 2019 10:53:48 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:49131) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iUYUB-0002wx-B6 for 37978@debbugs.gnu.org; Tue, 12 Nov 2019 10:53:43 -0500 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 8BDD46C4; Tue, 12 Nov 2019 10:53:37 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Tue, 12 Nov 2019 10:53:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.net; h= from:to:subject:date:message-id:mime-version:content-type; s= fm1; bh=B96nd8N58kGKsu4wc6Dm7IOai7wvmgysgYh7md8GKGo=; b=g/LFAK7i +gm70eoJstYqtrWaOrsJwoZGJA6SgPmuDpr7kR2U3NU1ErraZBqeHtWkm/8FUbX5 LcRVBDYBnVi6CiV4tSGfFHHz6HYprvvp8K0/XU1Lv7+hRrlEOgJnjteNby2fxzsJ TJmUhJUKQqTPC5BH4i64PjY9nKT/3wkl/wpgrR24jNkFJpS78RVjjGooUPumIn3B ayIUH84I0+G26lBTeWHO4pvac3RYmPVOqd6ifbydTnl5jk0onkjjezPYFyszXLlZ 3HXJcq8Pxual8aXbrBbJNNFLg6NMhP/sBwUZxQ0spI5NYv4DHBAwyu2AuehgJS/v QEJEFmtXxIaC5g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=B96nd8N58kGKsu4wc6Dm7IOai7wvm gysgYh7md8GKGo=; b=Uh6GN5vrY3SxZelSFikITr4Y39z/dtUVkoquDI3ZLF5VG +rWzNKzhqI9CWbbk9ZzfIS5uVJsEWb9ma/7XOb+yjrTGIhvBgIIdVgfUcGAAUK9B rvP5EDH0JzfrQ+5i+6rCdN4/Lwza3HFyJuew6TYmA2wqWbyLHNsTQjgBNgvNuAtm 972tlxycT3F4asmNuB4Lp8upjItGoMmeT5WgYVcr9e3qqt4yLncu4LYl2b3KVATc 3eunc/Viy6xvNV+HBacYHN3dCwroShHjO2MwDVpVSzhy3vGzoRX2eo+G2QSxX2gu nhT91r3+uoQVRDgbOYteZ7N0sH3KwL6aiQFUV7tpA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedruddvledgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkgggtsehttdertddttd dtnecuhfhrohhmpefmohhnrhgrugcujfhinhhsvghnuceokhhonhhrrggurdhhihhnshgv nhesfhgrshhtmhgrihhlrdhnvghtqeenucfkphepudelhedrvddvuddrtddrvddtieenuc frrghrrghmpehmrghilhhfrhhomhepkhhonhhrrggurdhhihhnshgvnhesfhgrshhtmhgr ihhlrdhnvghtnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from KHs-MacBook.local (soleil-ext.synchrotron-soleil.fr [195.221.0.206]) by mail.messagingengine.com (Postfix) with ESMTPA id 72E1D3060060; Tue, 12 Nov 2019 10:53:36 -0500 (EST) From: Konrad Hinsen Date: Tue, 12 Nov 2019 16:39:46 +0100 Message-ID: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * 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)))))))