From cfd20debfb0bdd21d9695278350ca8ed4b2d76d0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 25 Sep 2013 00:25:22 +0200 Subject: [PATCH] Fix bashrc regression Interactive non-login shells should not source /etc/profile, otherwise environment variables set by the user will get clobbered. For example: $ export PERL5LIB=/foo $ bash $ echo $PERL5LIB /home/eelco/.nix-profile/lib/perl5/site_perl:/nix/var/nix/profiles/default/lib/perl5/site_perl:/run/current-system/sw/lib/perl5/site_perl:/home/eelco/.nix-profile/lib/perl5/site_perl:/nix/var/nix/profiles/default/lib/perl5/site_perl:/run/current-system/sw/lib/perl5/site_perl --- modules/programs/bash/bash.nix | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/programs/bash/bash.nix b/modules/programs/bash/bash.nix index 443c6f570c1..c9332c0d9e9 100644 --- a/modules/programs/bash/bash.nix +++ b/modules/programs/bash/bash.nix @@ -151,11 +151,10 @@ in if [ -n "$__ETC_PROFILE_SOURCED" ]; then return; fi __ETC_PROFILE_SOURCED=1 - if [ -z "$__BASH_SHELL_INIT_DONE" ]; then - __BASH_SHELL_INIT_DONE=1 - ${cfg.shellInit} - fi + # Prevent this file from being sourced by interactive non-login child shells. + export __ETC_PROFILE_DONE=1 + ${cfg.shellInit} ${cfg.loginShellInit} # Read system-wide modifications. @@ -176,9 +175,11 @@ in if [ -n "$__ETC_BASHRC_SOURCED" -o -n "$NOSYSBASHRC" ]; then return; fi __ETC_BASHRC_SOURCED=1 - if [ -z "$__BASH_SHELL_INIT_DONE" ]; then - __BASH_SHELL_INIT_DONE=1 - ${cfg.shellInit} + # If the profile was not loaded in a parent process, source + # it. But otherwise don't do it because we don't want to + # clobber overridden values of $PATH, etc. + if [ -z "$__ETC_PROFILE_DONE" ]; then + . /etc/profile fi # We are not always an interactive shell.