unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: 51285@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#51285] [PATCH 0/3] Add 'guix shell --check'
Date: Tue, 19 Oct 2021 12:03:51 +0200	[thread overview]
Message-ID: <20211019100351.9726-1-ludo@gnu.org> (raw)

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





             reply	other threads:[~2021-10-19 10:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-19 10:03 Ludovic Courtès [this message]
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

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=20211019100351.9726-1-ludo@gnu.org \
    --to=ludo@gnu.org \
    --cc=51285@debbugs.gnu.org \
    /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).