forked from lix-project/lix
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>
This commit is contained in:
parent
792fd51f41
commit
4ea034a5c5
|
@ -202,7 +202,8 @@ foreach my $expr (@exprs) {
|
||||||
my $rcfile = "$tmpDir/rc";
|
my $rcfile = "$tmpDir/rc";
|
||||||
writeFile(
|
writeFile(
|
||||||
$rcfile,
|
$rcfile,
|
||||||
'[ -e ~/.bashrc ] && source ~/.bashrc; ' .
|
'unset BASH_ENV; ' .
|
||||||
|
'[ -n "$PS1" ] && [ -e ~/.bashrc ] && source ~/.bashrc; ' .
|
||||||
($pure ? '' : 'p=$PATH; ' ) .
|
($pure ? '' : 'p=$PATH; ' ) .
|
||||||
'dontAddDisableDepTrack=1; ' .
|
'dontAddDisableDepTrack=1; ' .
|
||||||
'[ -e $stdenv/setup ] && source $stdenv/setup; ' .
|
'[ -e $stdenv/setup ] && source $stdenv/setup; ' .
|
||||||
|
@ -212,6 +213,7 @@ foreach my $expr (@exprs) {
|
||||||
'unset NIX_ENFORCE_PURITY; ' .
|
'unset NIX_ENFORCE_PURITY; ' .
|
||||||
'shopt -u nullglob; ' .
|
'shopt -u nullglob; ' .
|
||||||
$envCommand);
|
$envCommand);
|
||||||
|
$ENV{BASH_ENV} = $rcfile;
|
||||||
exec($ENV{NIX_BUILD_SHELL} // "bash", "--rcfile", $rcfile);
|
exec($ENV{NIX_BUILD_SHELL} // "bash", "--rcfile", $rcfile);
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue