diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-07-11 14:32:22 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-07-11 14:32:22 +0200 |
commit | 656390062a9b612df3238f9e6a0d5ce89c3de21c (patch) | |
tree | 091c7fd804c92d01c8a0a3a90c748d002b04198d /scripts/nix-build.in | |
parent | 212e96f39c5120ef33b363647a58ebfd61fb3f5e (diff) |
nix-build --run-env: Source $stdenv/setup in the interactive shell
This ensures that not just environment variables are set, but also
shell functions such as unpackPhase, configurePhase and so on.
Diffstat (limited to 'scripts/nix-build.in')
-rwxr-xr-x | scripts/nix-build.in | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/scripts/nix-build.in b/scripts/nix-build.in index 76dffd253..4ceec4df6 100755 --- a/scripts/nix-build.in +++ b/scripts/nix-build.in @@ -3,6 +3,7 @@ use strict; use Nix::Config; use Nix::Store; +use Nix::Utils; use File::Temp qw(tempdir); @@ -15,7 +16,7 @@ my @buildArgs = (); my @exprs = (); my $shell = $ENV{SHELL} || "/bin/sh"; -my $envCommand = "p=\$PATH; source \$stdenv/setup; PATH=\$PATH:\$p; exec $shell"; +my $envCommand = ""; # interactive shell my @envExclude = (); @@ -124,7 +125,7 @@ for (my $n = 0; $n < scalar @ARGV; $n++) { elsif ($arg eq "--command") { $n++; die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV; - $envCommand = $ARGV[$n]; + $envCommand = "$ARGV[$n]\nexit $!"; } elsif ($arg eq "--exclude") { @@ -169,15 +170,23 @@ foreach my $expr (@exprs) { # Set the environment. $ENV{'NIX_BUILD_TOP'} = $ENV{'TMPDIR'} || "/tmp"; - foreach (keys %{$drv->{env}}) { - $ENV{$_} = $drv->{env}->{$_}; - } + $ENV{$_} = $drv->{env}->{$_} foreach keys %{$drv->{env}}; # Run a shell using the derivation's environment. For # convenience, source $stdenv/setup to setup additional - # environment variables. Also don't lose the current $PATH - # directories. - exec($ENV{SHELL}, "-c", $envCommand); + # environment variables and shell functions. Also don't lose + # the current $PATH directories. + my $rcfile = "$tmpDir/rc"; + writeFile( + $rcfile, + '[ -e ~/.bashrc ] && source ~/.bashrc; ' . + 'p=$PATH; ' . + '[ -e $stdenv/setup ] && source $stdenv/setup; ' . + 'PATH=$PATH:$p; ' . + 'set +e; ' . + 'PS1="\n\[\033[1;32m\][nix-build:\w]$\[\033[0m\] "; ' . + $envCommand); + exec($ENV{SHELL}, "--rcfile", $rcfile); die; } |