From patchwork Tue Oct 19 10:03:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 400 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 EEAD627BBE3; Tue, 19 Oct 2021 11:13:33 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id AEE2527BBE1 for ; Tue, 19 Oct 2021 11:13:33 +0100 (BST) Received: from localhost ([::1]:47006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcm7g-0002Sd-HS for patchwork@mira.cbaines.net; Tue, 19 Oct 2021 06:13:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mclzS-0007u5-Qw for guix-patches@gnu.org; Tue, 19 Oct 2021 06:05:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37889) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mclzS-00008i-HY for guix-patches@gnu.org; Tue, 19 Oct 2021 06:05:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mclzS-00073n-8n for guix-patches@gnu.org; Tue, 19 Oct 2021 06:05:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51285] [PATCH 0/3] Add 'guix shell --check' Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 19 Oct 2021 10:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 51285 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51285@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.163463784727068 (code B ref -1); Tue, 19 Oct 2021 10:05:02 +0000 Received: (at submit) by debbugs.gnu.org; 19 Oct 2021 10:04:07 +0000 Received: from localhost ([127.0.0.1]:49435 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mclyY-00072W-PM for submit@debbugs.gnu.org; Tue, 19 Oct 2021 06:04:07 -0400 Received: from lists.gnu.org ([209.51.188.17]:59126) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mclyT-000724-AF for submit@debbugs.gnu.org; Tue, 19 Oct 2021 06:04:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33054) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mclyS-00069B-Q3 for guix-patches@gnu.org; Tue, 19 Oct 2021 06:04:01 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:47766) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mclyS-0007iX-Hg; Tue, 19 Oct 2021 06:04:00 -0400 Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:54291 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mclyS-0003y1-89; Tue, 19 Oct 2021 06:04:00 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Tue, 19 Oct 2021 12:03:51 +0200 Message-Id: <20211019100351.9726-1-ludo@gnu.org> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 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" X-getmail-retrieved-from-mailbox: Patches 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