about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2013-10-17T15·07-0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-10-18T12·34+0200
commit4ea034a5c56a60ae0ceedf18a066c428a963c836 (patch)
tree938709e8fc741cc0b494df7b1dd870f41d78a819 /scripts
parent792fd51f41212b0bf1d8a121a4f228a92fec3906 (diff)
nix-shell: Play nicely with non-interactive shells
nix-shell with the --command flag might be used non-interactively, but
if bash starts non-interactively (i.e. with stdin or stderr not a
terminal), it won't source the script given in --rcfile. However, in
that case it *will* source the script found in $BASH_ENV, so we can use
that instead.

Also, don't source ~/.bashrc in a non-interactive shell (detectable by
checking the PS1 env var)

Signed-off-by: Shea Levy <shea@shealevy.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/nix-build.in4
1 files changed, 3 insertions, 1 deletions
diff --git a/scripts/nix-build.in b/scripts/nix-build.in
index 3b5b8413c823..4bf85ae138d8 100755
--- a/scripts/nix-build.in
+++ b/scripts/nix-build.in
@@ -202,7 +202,8 @@ foreach my $expr (@exprs) {
         my $rcfile = "$tmpDir/rc";
         writeFile(
             $rcfile,
-            '[ -e ~/.bashrc ] && source ~/.bashrc; ' .
+            'unset BASH_ENV; ' .
+            '[ -n "$PS1" ] && [ -e ~/.bashrc ] && source ~/.bashrc; ' .
             ($pure ? '' : 'p=$PATH; ' ) .
             'dontAddDisableDepTrack=1; ' .
             '[ -e $stdenv/setup ] && source $stdenv/setup; ' .
@@ -212,6 +213,7 @@ foreach my $expr (@exprs) {
             'unset NIX_ENFORCE_PURITY; ' .
             'shopt -u nullglob; ' .
             $envCommand);
+        $ENV{BASH_ENV} = $rcfile;
         exec($ENV{NIX_BUILD_SHELL} // "bash", "--rcfile", $rcfile);
         die;
     }