From patchwork Sun Mar 13 18:21:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Charles X-Patchwork-Id: 37779 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 E6D1427BBEA; Sun, 13 Mar 2022 18:23:00 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 2861227BBE9 for ; Sun, 13 Mar 2022 18:23:00 +0000 (GMT) Received: from localhost ([::1]:51290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nTSrr-0006JN-7s for patchwork@mira.cbaines.net; Sun, 13 Mar 2022 14:22:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nTSqw-0005YZ-7B for guix-patches@gnu.org; Sun, 13 Mar 2022 14:22:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:49376) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nTSqv-0002qV-Ug for guix-patches@gnu.org; Sun, 13 Mar 2022 14:22:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nTSqv-000075-N1 for guix-patches@gnu.org; Sun, 13 Mar 2022 14:22:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54375] Mutable guix shell environments Resent-From: Charles Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 13 Mar 2022 18:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 54375 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 54375@debbugs.gnu.org X-Debbugs-Original-To: "guix-patches@gnu.org" Received: via spool by submit@debbugs.gnu.org id=B.1647195692376 (code B ref -1); Sun, 13 Mar 2022 18:22:01 +0000 Received: (at submit) by debbugs.gnu.org; 13 Mar 2022 18:21:32 +0000 Received: from localhost ([127.0.0.1]:43272 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nTSqR-00005y-P7 for submit@debbugs.gnu.org; Sun, 13 Mar 2022 14:21:32 -0400 Received: from lists.gnu.org ([209.51.188.17]:39966) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nTSqQ-00005r-MY for submit@debbugs.gnu.org; Sun, 13 Mar 2022 14:21:31 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nTSqN-00054U-V9 for guix-patches@gnu.org; Sun, 13 Mar 2022 14:21:30 -0400 Received: from mail-40132.protonmail.ch ([185.70.40.132]:27237) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nTSqK-0002by-Py for guix-patches@gnu.org; Sun, 13 Mar 2022 14:21:27 -0400 Date: Sun, 13 Mar 2022 18:21:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1647195680; bh=3PW80QDk1rFV/b6Zu+Og3n3S/BVk7aSq4SbX4BBuUZQ=; h=Date:To:From:Reply-To:Subject:Message-ID:From:To:Cc:Date:Subject: Reply-To:Feedback-ID:Message-ID; b=PUbr6K1dfGI/oKuVZfQA+3J2dgx109IPe2UKora+5MF57qpH/S5B6Fm1mRJBP79Rq tEQ1yoeqS/Y6pWp0mDvAUJATAOuaIhZAYIBpQ7fZiElfAX1HeMbxwKRd5cGhruD/+1 JF7Sc7+r+k1i5pLpuhdA1lRgAh59gw8FzAcrFLag4JeT4iqV7ZoS0RICKzCIetiFl3 anlaVSrIbjzZjNiw2YJQ1tVYPqv32Xd+nM9FkFhcR02DoKGF+DRVbBovq3JyndH7aa cEE/AHqiroguO1YowxTqFkEtOA9sty2GMDX5xXs1hNp9E+sHjj2UIdN+vCFIJGiAqv C8kESQ7cr41BA== Message-ID: MIME-Version: 1.0 Received-SPF: pass client-ip=185.70.40.132; envelope-from=charles.b.jackson@protonmail.com; helo=mail-40132.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" Reply-to: Charles X-ACL-Warn: , Charles via Guix-patches X-Patchwork-Original-From: Charles via Guix-patches via From: Charles X-getmail-retrieved-from-mailbox: Patches sample useage: $ cd project $ guix package --manifest=manifest.scm --profile=.guix-profile $ guix shell # --profile=.guix-profile is implicit do some stuff. realize that you want to bring in another package. $ guix install --profile=.guix-profile additional-package Then additional package is instantly available. This is especially useful to lisp programmers because, currently, bringing in an additional library involves restarting shell, lisp process, reloading source files, regenerating process state. From f3c86193a75b3b45740bb930847f508377cf546a Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 13 Mar 2022 12:58:19 -0500 Subject: [PATCH 1/2] guix: environment: Enable mutable environments. * guix/scripts/environment.scm (launch-environment launch-environment/fork launch-environment/container guix-environment*): Add #:set-profile? parameter set GUIX_PROFILE when --profile option is used. * guix/scripts/environment.scm (guix-environment*): Profile could point to a profile directory instead of a store directory. --- guix/scripts/environment.scm | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index ec071402f4..3dd425eac0 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2014, 2015, 2018 David Thompson ;;; Copyright © 2015-2022 Ludovic Courtès ;;; Copyright © 2018 Mike Gerwitz +;;; Copyright © 2022 Charles Jackson ;;; ;;; This file is part of GNU Guix. ;;; @@ -384,7 +385,7 @@ (define exit/status (compose exit status->exit-code)) (define primitive-exit/status (compose primitive-exit status->exit-code)) (define* (launch-environment command profile manifest - #:key pure? (white-list '())) + #:key pure? (white-list '()) (set-profile? #f)) "Run COMMAND in a new environment containing INPUTS, using the native search paths defined by the list PATHS. When PURE?, pre-existing environment variables are cleared before setting the new ones, except those matching the @@ -399,6 +400,8 @@ (define* (launch-environment command profile manifest ;; adjust 'PS1' accordingly, for instance. Set it to PROFILE so users can ;; conveniently access its contents. (setenv "GUIX_ENVIRONMENT" profile) + (when set-profile? + (setenv "GUIX_PROFILE" profile)) (match command ((program . args) @@ -591,7 +594,7 @@ (define (validate-exit-status profile command status) status) (define* (launch-environment/fork command profile manifest - #:key pure? (white-list '())) + #:key pure? (white-list '()) (set-profile? #f)) "Run COMMAND in a new process with an environment containing PROFILE, with the search paths specified by MANIFEST. When PURE?, pre-existing environment variables are cleared before setting the new ones, except those matching the @@ -599,14 +602,16 @@ (define* (launch-environment/fork command profile manifest (match (primitive-fork) (0 (launch-environment command profile manifest #:pure? pure? - #:white-list white-list)) + #:white-list white-list + #:set-profile? set-profile?)) (pid (match (waitpid pid) ((_ . status) (validate-exit-status profile command status)))))) (define* (launch-environment/container #:key command bash user user-mappings profile manifest link-profile? network? - map-cwd? (white-list '())) + map-cwd? (white-list '()) + (set-profile? #f)) "Run COMMAND within a container that features the software in PROFILE. Environment variables are set according to the search paths of MANIFEST. The global shell is BASH, a file name for a GNU Bash binary in the @@ -748,7 +753,7 @@ (define (exit/status* status) (if link-profile? (string-append home-dir "/.guix-profile") profile) - manifest #:pure? #f))) + manifest #:pure? #f #:set-profile? set-profile?))) #:guest-uid uid #:guest-gid gid #:namespaces (if network? @@ -880,7 +885,7 @@ (define (guix-environment* opts) (user (assoc-ref opts 'user)) (bootstrap? (assoc-ref opts 'bootstrap?)) (system (assoc-ref opts 'system)) - (profile (assoc-ref opts 'profile)) + (profile-option (assoc-ref opts 'profile)) (command (or (assoc-ref opts 'exec) ;; Spawn a shell if the user didn't specify ;; anything in particular. @@ -894,7 +899,7 @@ (define (guix-environment* opts) (define store-needed? ;; Whether connecting to the daemon is needed. - (or container? (not profile))) + (or container? (not profile-option))) (define-syntax-rule (with-store/maybe store exp ...) ;; Evaluate EXP... with STORE bound to a connection, unless @@ -928,11 +933,11 @@ (define manifest-from-opts (options/resolve-packages store opts)) (define manifest - (if profile - (profile-manifest profile) + (if profile-option + (profile-manifest profile-option) manifest-from-opts)) - (when (and profile + (when (and profile-option (> (length (manifest-entries manifest-from-opts)) 0)) (leave (G_ "'--profile' cannot be used with package options~%"))) @@ -953,12 +958,11 @@ (define manifest (mlet* %store-monad ((bash (environment-bash container? bootstrap? system)) - (prof-drv (if profile + (prof-drv (if profile-option (return #f) (manifest->derivation manifest system bootstrap?))) - (profile -> (if profile - (readlink* profile) + (profile -> (or profile-option (derivation->output-path prof-drv))) (gc-root -> (assoc-ref opts 'gc-root))) @@ -999,14 +1003,16 @@ (define manifest #:white-list white-list #:link-profile? link-prof? #:network? network? - #:map-cwd? (not no-cwd?)))) + #:map-cwd? (not no-cwd?) + #:set-profile? profile-option))) (else (return (exit/status (launch-environment/fork command profile manifest #:white-list white-list - #:pure? pure?)))))))))))))) + #:pure? pure? + #:set-profile? profile-option)))))))))))))) ;;; Local Variables: ;;; eval: (put 'with-store/maybe 'scheme-indent-function 1) -- 2.34.0