unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Charles via Guix-patches via <guix-patches@gnu.org>
To: 54375@debbugs.gnu.org
Subject: [bug#54375] Mutable guix shell environments
Date: Sun, 13 Mar 2022 18:21:16 +0000	[thread overview]
Message-ID: <Zycszoymk_U1ui1Ek6NODmj1rphro1ZjtzltZf6rnv7wtFAxmj0DW8IRWerZaW3PkR80EmJ6Fru8R7pp9dzDpPoh-FFzqeGAsB_Ivs4Ipr4=@protonmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 518 bytes --]

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.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-guix-shell-Implicitly-use-a-.guix-profile-as-profile.patch --]
[-- Type: text/x-patch; name=0002-guix-shell-Implicitly-use-a-.guix-profile-as-profile.patch, Size: 1688 bytes --]

From 47c4c6f9896c2b4b884ff11063d33f5458cbecf7 Mon Sep 17 00:00:00 2001
From: Charles <charles.b.jackson@protonmail.com>
Date: Sun, 13 Mar 2022 12:58:25 -0500
Subject: [PATCH 2/2] guix: shell: Implicitly use a .guix-profile as --profile
 option.

* guix/scripts/shell.scm (auto-detect-manifest): Add ".guix-profile" to
matches as --profile option
---
 guix/scripts/shell.scm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/guix/scripts/shell.scm b/guix/scripts/shell.scm
index 1eab05d737..fca41cc2d4 100644
--- a/guix/scripts/shell.scm
+++ b/guix/scripts/shell.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2021-2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2022 Charles Jackson <charles.b.jackson@protonmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -256,7 +257,7 @@ (define disallow-implicit-load?
           disallow-implicit-load?
           (options-contain-payload? opts))
       opts
-      (match (find-file-in-parent-directories '("manifest.scm" "guix.scm"))
+      (match (find-file-in-parent-directories '(".guix-profile" "manifest.scm" "guix.scm"))
         (#f
          (warning (G_ "no packages specified; creating an empty environment~%"))
          opts)
@@ -265,6 +266,7 @@ (define disallow-implicit-load?
              (begin
                (info (G_ "loading environment from '~a'...~%") file)
                (match (basename file)
+                 (".guix-profile" (alist-cons 'profile file opts))
                  ("guix.scm" (alist-cons 'load `(package ,file) opts))
                  ("manifest.scm" (alist-cons 'manifest file opts))))
              (begin
-- 
2.34.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-guix-environment-Enable-mutable-environments.patch --]
[-- Type: text/x-patch; name=0001-guix-environment-Enable-mutable-environments.patch, Size: 7584 bytes --]

From f3c86193a75b3b45740bb930847f508377cf546a Mon Sep 17 00:00:00 2001
From: Charles <charles.b.jackson@protonmail.com>
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 <davet@gnu.org>
 ;;; Copyright © 2015-2022 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2018 Mike Gerwitz <mtg@gnu.org>
+;;; Copyright © 2022 Charles Jackson <charles.b.jackson@protonmail.com>
 ;;;
 ;;; 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


             reply	other threads:[~2022-03-13 18:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-13 18:21 Charles via Guix-patches via [this message]
2022-03-13 19:51 ` [bug#54375] Mutable guix shell environments Liliana Marie Prikler
2022-03-13 23:38   ` Charles via Guix-patches via
2022-03-14  5:19     ` Liliana Marie Prikler
2022-03-14  6:24       ` Charles via Guix-patches via
2022-03-14 17:43 ` Maxime Devos
2022-03-14 17:54 ` Maxime Devos
2022-03-14 19:41   ` Charles via Guix-patches via
2022-03-14 22:18   ` Ludovic Courtès
2022-03-15  9:49     ` zimoun
2022-03-15 23:52       ` Charles via Guix-patches via

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='Zycszoymk_U1ui1Ek6NODmj1rphro1ZjtzltZf6rnv7wtFAxmj0DW8IRWerZaW3PkR80EmJ6Fru8R7pp9dzDpPoh-FFzqeGAsB_Ivs4Ipr4=@protonmail.com' \
    --to=guix-patches@gnu.org \
    --cc=54375@debbugs.gnu.org \
    --cc=charles.b.jackson@protonmail.com \
    /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).