From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 0KOjH/rQbWFkigAAgWs5BA (envelope-from ) for ; Mon, 18 Oct 2021 21:54:34 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id CFFtG/rQbWFhDAAA1q6Kng (envelope-from ) for ; Mon, 18 Oct 2021 19:54:34 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 3C666127B4 for ; Mon, 18 Oct 2021 21:54:34 +0200 (CEST) Received: from localhost ([::1]:36720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcYiP-0000tN-F8 for larch@yhetil.org; Mon, 18 Oct 2021 15:54:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcYhw-0008Nv-Gc for guix-patches@gnu.org; Mon, 18 Oct 2021 15:54:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37138) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcYhu-0003y3-Rc for guix-patches@gnu.org; Mon, 18 Oct 2021 15:54:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mcYhu-0000R2-Ql for guix-patches@gnu.org; Mon, 18 Oct 2021 15:54:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50960] [PATCH v3 07/10] environment: Do not connect to the daemon when '--profile' is used. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 18 Oct 2021 19:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50960 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50960@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 50960-submit@debbugs.gnu.org id=B50960.16345867841553 (code B ref 50960); Mon, 18 Oct 2021 19:54:02 +0000 Received: (at 50960) by debbugs.gnu.org; 18 Oct 2021 19:53:04 +0000 Received: from localhost ([127.0.0.1]:48670 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mcYgy-0000Os-8u for submit@debbugs.gnu.org; Mon, 18 Oct 2021 15:53:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53460) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mcYgk-0000Mh-Rr for 50960@debbugs.gnu.org; Mon, 18 Oct 2021 15:52:51 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:51638) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcYgf-0002nS-Ix; Mon, 18 Oct 2021 15:52:45 -0400 Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:60778 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcYgf-0007lj-9b; Mon, 18 Oct 2021 15:52:45 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Mon, 18 Oct 2021 21:52:16 +0200 Message-Id: <20211018195219.13898-8-ludo@gnu.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211018195219.13898-1-ludo@gnu.org> References: <20211011213809.17482-1-ludo@gnu.org> <20211018195219.13898-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1634586874; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=qrQltwJK1GtYlIa9KPj1dPLc8IY9oh5zH+mc0YbG+jE=; b=Cz8dknY7JBaILguOWzZuOoA+PHEX7X11uG0dfWbyBToU6qWCdVeKFpCBBLEwvpcopVLTjE 9KLlD5JIcLIzbA7/UOrSsS1hGcFG2SziCRDB3bjqkrrbyAapLPH4tBV3HbIdO8PMbUVuGx 2KGEoDaEfBlL/oZu9RgB7NCnLdRl5RapHX6UR/rx6L1UJN53NZGCf+Mi2qqD6wfnvBDETK Wy8pIDTJm9A5aE+0ylsqimiZ6Y4uIAS5wNNAqN5R7sIDb0CNdQmoGU/vdde+O35s+iV2DM vuvnAlRB+brPgbHf3NOjxD7y09yVDLlLk/g/Wlj4bp7Z6ZIHZUiI4T5I3PTs2g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1634586874; a=rsa-sha256; cv=none; b=Ja6N2kw9ahF0yQjvBIpAKEC7tTHDZmVUxxw8cLzPq6d9XydT4jHgqJPUj62hrRD46ZWX0f niJpgvZ/Ykn4ElGOYQzhKseF5zNgLcNGmEKqS/YBSmhipoiQjyLM0iZzTCWFfmeoShgRZ+ FnpEn6kungWYd/e4bcTbwVpwNJiuZN12mBJL7vBo6ydEuNHRytsXdRj+7dvdIfzOicmXC2 ulm3rqQjuTxoOmQAhUZCsQzNirH2x9hi1XiNFBW2YVd+E618LyvZqj9IrcVDDL92otexXH hrP5qWrKxR1I6NaNckMkoEWKS8yThtzqk9WEqVuW+gLBDS0Tt+ftnas1CjFiEA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 3.57 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 3C666127B4 X-Spam-Score: 3.57 X-Migadu-Scanner: scn0.migadu.com X-TUID: LwoNL0VZCTdN This further speeds up the 'guix environment -p PROFILE' case. * guix/scripts/environment.scm (guix-environment*)[store-needed?]: New variable. [with-store/maybe]: New macro. Use it instead of 'with-store', and remove 'with-build-handler' form. --- guix/scripts/environment.scm | 169 +++++++++++++++++++---------------- 1 file changed, 93 insertions(+), 76 deletions(-) diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index 32f376fdd2..e23d52df39 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -691,6 +691,26 @@ (define (guix-environment* opts) (mappings (pick-all opts 'file-system-mapping)) (white-list (pick-all opts 'inherit-regexp))) + (define store-needed? + ;; Whether connecting to the daemon is needed. + (or container? (not profile))) + + (define-syntax-rule (with-store/maybe store exp ...) + ;; Evaluate EXP... with STORE bound to a connection, unless + ;; STORE-NEEDED? is false, in which case STORE is bound to #f. + (let ((proc (lambda (store) exp ...))) + (if store-needed? + (with-store s + (set-build-options-from-command-line s opts) + (with-build-handler (build-notifier #:use-substitutes? + (assoc-ref opts 'substitutes?) + #:verbosity + (assoc-ref opts 'verbosity) + #:dry-run? + (assoc-ref opts 'dry-run?)) + (proc s))) + (proc #f)))) + (when container? (assert-container-features)) (when (and (not container?) link-prof?) @@ -701,88 +721,85 @@ (define (guix-environment* opts) (leave (G_ "--no-cwd cannot be used without --container~%"))) - (with-store store - (with-build-handler (build-notifier #:use-substitutes? - (assoc-ref opts 'substitutes?) - #:verbosity - (assoc-ref opts 'verbosity) - #:dry-run? - (assoc-ref opts 'dry-run?)) - (with-status-verbosity (assoc-ref opts 'verbosity) - (define manifest-from-opts - (options/resolve-packages store opts)) + (with-store/maybe store + (with-status-verbosity (assoc-ref opts 'verbosity) + (define manifest-from-opts + (options/resolve-packages store opts)) - (define manifest - (if profile - (profile-manifest profile) - manifest-from-opts)) + (define manifest + (if profile + (profile-manifest profile) + manifest-from-opts)) - (when (and profile - (> (length (manifest-entries manifest-from-opts)) 0)) - (leave (G_ "'--profile' cannot be used with package options~%"))) + (when (and profile + (> (length (manifest-entries manifest-from-opts)) 0)) + (leave (G_ "'--profile' cannot be used with package options~%"))) - (when (null? (manifest-entries manifest)) - (warning (G_ "no packages specified; creating an empty environment~%"))) + (when (null? (manifest-entries manifest)) + (warning (G_ "no packages specified; creating an empty environment~%"))) - (set-build-options-from-command-line store opts) + ;; Use the bootstrap Guile when requested. + (parameterize ((%graft? (assoc-ref opts 'graft?)) + (%guile-for-build + (and store-needed? + (package-derivation + store + (if bootstrap? + %bootstrap-guile + (default-guile)))))) + (run-with-store store + ;; Containers need a Bourne shell at /bin/sh. + (mlet* %store-monad ((bash (environment-bash container? + bootstrap? + system)) + (prof-drv (if profile + (return #f) + (manifest->derivation + manifest system bootstrap?))) + (profile -> (if profile + (readlink* profile) + (derivation->output-path prof-drv))) + (gc-root -> (assoc-ref opts 'gc-root))) - ;; Use the bootstrap Guile when requested. - (parameterize ((%graft? (assoc-ref opts 'graft?)) - (%guile-for-build - (and (or container? (not profile)) - (package-derivation - store - (if bootstrap? - %bootstrap-guile - (default-guile)))))) - (run-with-store store - ;; Containers need a Bourne shell at /bin/sh. - (mlet* %store-monad ((bash (environment-bash container? - bootstrap? - system)) - (prof-drv (if profile - (return #f) - (manifest->derivation - manifest system bootstrap?))) - (profile -> (if profile - (readlink* profile) - (derivation->output-path prof-drv))) - (gc-root -> (assoc-ref opts 'gc-root))) - - ;; First build the inputs. This is necessary even for - ;; --search-paths. Additionally, we might need to build bash for - ;; a container. - (mbegin %store-monad + ;; First build the inputs. This is necessary even for + ;; --search-paths. Additionally, we might need to build bash for + ;; a container. + (mbegin %store-monad + (mwhen store-needed? (built-derivations (append (if prof-drv (list prof-drv) '()) - (if (derivation? bash) (list bash) '()))) - (mwhen gc-root - (register-gc-root profile gc-root)) + (if (derivation? bash) (list bash) '())))) + (mwhen gc-root + (register-gc-root profile gc-root)) - (cond - ((assoc-ref opts 'search-paths) - (show-search-paths profile manifest #:pure? pure?) - (return #t)) - (container? - (let ((bash-binary - (if bootstrap? - (derivation->output-path bash) - (string-append (derivation->output-path bash) - "/bin/sh")))) - (launch-environment/container #:command command - #:bash bash-binary - #:user user - #:user-mappings mappings - #:profile profile - #:manifest manifest - #:white-list white-list - #:link-profile? link-prof? - #:network? network? - #:map-cwd? (not no-cwd?)))) + (cond + ((assoc-ref opts 'search-paths) + (show-search-paths profile manifest #:pure? pure?) + (return #t)) + (container? + (let ((bash-binary + (if bootstrap? + (derivation->output-path bash) + (string-append (derivation->output-path bash) + "/bin/sh")))) + (launch-environment/container #:command command + #:bash bash-binary + #:user user + #:user-mappings mappings + #:profile profile + #:manifest manifest + #:white-list white-list + #:link-profile? link-prof? + #:network? network? + #:map-cwd? (not no-cwd?)))) - (else - (return - (exit/status - (launch-environment/fork command profile manifest - #:white-list white-list - #:pure? pure?))))))))))))))) + (else + (return + (exit/status + (launch-environment/fork command profile manifest + #:white-list white-list + #:pure? pure?)))))))))))))) + +;;; Local Variables: +;;; (put 'with-store/maybe 'scheme-indent-function 1) +;;; End: -- 2.33.0