summary refs log tree commit diff
path: root/modules
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-09-25 00:25:22 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-09-25 00:25:22 +0200
commitcfd20debfb0bdd21d9695278350ca8ed4b2d76d0 (patch)
treed55eb9cf049dd866d1b77a6c728e9cccff870d19 /modules
parent78721f57eb96a5fb60e122de67bc72c3c9c528e9 (diff)
downloadnixlib-cfd20debfb0bdd21d9695278350ca8ed4b2d76d0.tar
nixlib-cfd20debfb0bdd21d9695278350ca8ed4b2d76d0.tar.gz
nixlib-cfd20debfb0bdd21d9695278350ca8ed4b2d76d0.tar.bz2
nixlib-cfd20debfb0bdd21d9695278350ca8ed4b2d76d0.tar.lz
nixlib-cfd20debfb0bdd21d9695278350ca8ed4b2d76d0.tar.xz
nixlib-cfd20debfb0bdd21d9695278350ca8ed4b2d76d0.tar.zst
nixlib-cfd20debfb0bdd21d9695278350ca8ed4b2d76d0.zip
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
Diffstat (limited to 'modules')
-rw-r--r--modules/programs/bash/bash.nix15
1 files changed, 8 insertions, 7 deletions
diff --git a/modules/programs/bash/bash.nix b/modules/programs/bash/bash.nix
index 443c6f570c17..c9332c0d9e95 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.