unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#51285] [PATCH 0/3] Add 'guix shell --check'
@ 2021-10-19 10:03 Ludovic Courtès
  2021-10-19 10:13 ` [bug#51285] [PATCH 1/3] syscalls: Add 'openpty' and 'login-tty' Ludovic Courtès
  2021-10-26 10:48 ` bug#51285: [PATCH 0/3] Add 'guix shell --check' Ludovic Courtès
  0 siblings, 2 replies; 5+ messages in thread
From: Ludovic Courtès @ 2021-10-19 10:03 UTC (permalink / raw)
  To: 51285; +Cc: Ludovic Courtès

Hello Guix!

You may be familiar with the crucial footnote about shell startup files:

  https://guix.gnu.org/manual/en/html_node/Invoking-guix-environment.html#FOOT11

In short, if your shell startup file mess up with environment variables,
‘--pure’ won’t deliver its promise.  That’s a common source of annoyance.

This patch set adds a ‘--check’ option to ‘guix shell’ (and ‘guix environment’
as well, mostly out of simplicity).  Here’s an example:

--8<---------------cut here---------------start------------->8---
$ tail -2 ~/.bashrc
echo "hi from bashrc!"
export PATH=muahahaaa:$PATH
$ ./pre-inst-env guix shell --check coreutils 
guix shell: checking the environment variables visible from shell '/gnu/store/87kif0bpf0anwbsaw0jvg8fyciw4sz67-bash-5.0.16/bin/bash'...
guix shell: warning: variable 'PATH' is clobbered: 'muahahaaa:/gnu/store/cq8sfmm6in0r4nfx0zxjvx1fg5ky6a7r-profile/bin'
hint: One or more environment variables have a different value in the shell than the one we set.
This means that you may find yourself running code in an environment different from the one
you asked Guix to prepare.

This usually indicates that your shell startup files are unexpectedly modifying those
environment variables.  For example, if you are using Bash, make sure that environment
variables are set or modified in `~/.bash_profile' and _not_ in `~/.bashrc'.  For more
information on Bash startup files, run:

     info "(bash) Bash Startup Files"

Alternatively, you can avoid the problem by passing the `--container' or `-C' option.  That
will give you a fully isolated environment running in a "container", immune to the issue
described above.
--8<---------------cut here---------------end--------------->8---

Once I’ve cleaned up ~/.bashrc, I can check again and proceed:

--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env guix shell --check coreutils 
guix shell: checking the environment variables visible from shell '/gnu/store/87kif0bpf0anwbsaw0jvg8fyciw4sz67-bash-5.0.16/bin/bash'...
guix shell: All is good!  The shell gets correct environment variables.
[env]$ uname -o
GNU/Linux
--8<---------------cut here---------------end--------------->8---

This works by launching an interactive shell in a pseudo-terminal, and
running “env” or “set” in that shell to retrieve the list of environment
variables once it has sourced its startup files.

It works well with Bash, Zsh, and presumably any POSIX shell.  It kinda
works with fish, but that’s not entirely clear.

To allow users to learn about this option, the last patch has ‘guix shell’
print a suggest to run ‘--check’ if (1) the hint has never been printed,
(2) the user is doing an interactive session, and (3) the user did not
pass ‘--container’ or ‘--search-paths’.

Thoughts?

Ludo’.

Ludovic Courtès (3):
  syscalls: Add 'openpty' and 'login-tty'.
  environment: Add '--check'.
  shell: Suggest running '--check' once for interactive use.

 doc/guix.texi                |  39 ++++++---
 guix/build/syscalls.scm      |  39 +++++++++
 guix/scripts/environment.scm | 162 ++++++++++++++++++++++++++++++++++-
 guix/scripts/shell.scm       |  41 ++++++++-
 tests/syscalls.scm           |  35 ++++++++
 5 files changed, 303 insertions(+), 13 deletions(-)


base-commit: 467d599bd972f16a958a394827bc925bc497c19a
-- 
2.33.0





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-10-26 11:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-19 10:03 [bug#51285] [PATCH 0/3] Add 'guix shell --check' Ludovic Courtès
2021-10-19 10:13 ` [bug#51285] [PATCH 1/3] syscalls: Add 'openpty' and 'login-tty' Ludovic Courtès
2021-10-19 10:13   ` [bug#51285] [PATCH 2/3] environment: Add '--check' Ludovic Courtès
2021-10-19 10:13   ` [bug#51285] [PATCH 3/3] shell: Suggest running '--check' once for interactive use Ludovic Courtès
2021-10-26 10:48 ` bug#51285: [PATCH 0/3] Add 'guix shell --check' Ludovic Courtès

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).