environment: '--link-profile' uses ~/.guix-profile for environment variables.

Before this patch, we had:

  $ guix environment -CP --ad-hoc coreutils
  [env]$ echo $PATH
  /gnu/store/…-profile/bin
  [env]$ echo $GUIX_ENVIRONMENT
  /gnu/store/…-profile

After this patch:

  $ guix environment -CP --ad-hoc coreutils
  [env]$ echo $PATH
  /home/ludo/.guix-profile/bin
  [env]$ echo $GUIX_ENVIRONMENT
  /home/ludo/.guix-profile

* guix/scripts/environment.scm (launch-environment/container): When
LINK-PROFILE? is true, pass ~/.guix-profile as the second argument to
'launch-environment'.
* tests/guix-environment-container.sh: Adjust test accordingly.
* doc/guix.texi (Invoking guix environment): Update accordingly.
This commit is contained in:
Ludovic Courtès 2020-09-14 22:49:06 +02:00
parent a2b25890ee
commit 9b65281de5
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
3 changed files with 15 additions and 6 deletions

View file

@ -5420,8 +5420,9 @@ device.
@item --link-profile @item --link-profile
@itemx -P @itemx -P
For containers, link the environment profile to @file{~/.guix-profile} For containers, link the environment profile to @file{~/.guix-profile}
within the container. This is equivalent to running the command within the container and set @code{GUIX_ENVIRONMENT} to that.
@samp{ln -s $GUIX_ENVIRONMENT ~/.guix-profile} within the container. This is equivalent to making @file{~/.guix-profile} a symlink to the
actual profile within the container.
Linking will fail and abort the environment if the directory already Linking will fail and abort the environment if the directory already
exists, which will certainly be the case if @command{guix environment} exists, which will certainly be the case if @command{guix environment}
was invoked in the user's home directory. was invoked in the user's home directory.

View file

@ -564,7 +564,11 @@ (define (optional-mapping->fs mapping)
(primitive-exit/status (primitive-exit/status
;; A container's environment is already purified, so no need to ;; A container's environment is already purified, so no need to
;; request it be purified again. ;; request it be purified again.
(launch-environment command profile manifest #:pure? #f))) (launch-environment command
(if link-profile?
(string-append home-dir "/.guix-profile")
profile)
manifest #:pure? #f)))
#:guest-uid uid #:guest-uid uid
#:guest-gid gid #:guest-gid gid
#:namespaces (if network? #:namespaces (if network?

View file

@ -127,11 +127,15 @@ grep -e "$NIX_STORE_DIR/.*-bash" $tmpdir/mounts # bootstrap bash
rm $tmpdir/mounts rm $tmpdir/mounts
# Make sure 'GUIX_ENVIRONMENT' is linked to '~/.guix-profile' when requested # Make sure 'GUIX_ENVIRONMENT' is set to '~/.guix-profile' when requested
# within a container. # within a container.
( (
linktest='(exit (string=? (getenv "GUIX_ENVIRONMENT") linktest='
(readlink (string-append (getenv "HOME") "/.guix-profile"))))' (exit (and (string=? (getenv "GUIX_ENVIRONMENT")
(string-append (getenv "HOME") "/.guix-profile"))
(string-prefix? "'"$NIX_STORE_DIR"'"
(readlink (string-append (getenv "HOME")
"/.guix-profile")))))'
cd "$tmpdir" \ cd "$tmpdir" \
&& guix environment --bootstrap --container --link-profile \ && guix environment --bootstrap --container --link-profile \