forked from lix-project/lix
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.
This commit is contained in:
parent
212e96f39c
commit
656390062a
|
@ -79,8 +79,9 @@ or renamed. So don’t rename the symlink.</para></warning>
|
||||||
the dependencies of the derivation, but not the derivation itself. It
|
the dependencies of the derivation, but not the derivation itself. It
|
||||||
will then start an interactive shell in which all environment
|
will then start an interactive shell in which all environment
|
||||||
variables defined by the derivation have been set to their
|
variables defined by the derivation have been set to their
|
||||||
corresponding values. This is useful for reproducing the environment
|
corresponding values, and the script <literal>$stdenv/setup</literal>
|
||||||
of a derivation for development.</para>
|
has been sourced. This is useful for reproducing the environment of a
|
||||||
|
derivation for development.</para>
|
||||||
|
|
||||||
</refsection>
|
</refsection>
|
||||||
|
|
||||||
|
@ -144,9 +145,9 @@ also <xref linkend="sec-common-options" />.</phrase></para>
|
||||||
|
|
||||||
<varlistentry><term><option>--command</option> <replaceable>cmd</replaceable></term>
|
<varlistentry><term><option>--command</option> <replaceable>cmd</replaceable></term>
|
||||||
|
|
||||||
<listitem><para>In the environment of the derivation, executeq the
|
<listitem><para>In the environment of the derivation, run the
|
||||||
command <replaceable>cmd</replaceable> instead of the default
|
shell command <replaceable>cmd</replaceable> instead of starting
|
||||||
interactive shell.</para></listitem>
|
an interactive shell.</para></listitem>
|
||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
@ -181,10 +182,10 @@ interactive shell in which to build it:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
$ nix-build '<nixpkgs>' --run-env -A pan
|
$ nix-build '<nixpkgs>' --run-env -A pan
|
||||||
$ tar xf $src
|
$ unpackPhase
|
||||||
$ cd pan-*
|
$ cd pan-*
|
||||||
$ ./configure
|
$ configurePhase
|
||||||
$ make
|
$ buildPhase
|
||||||
$ ./pan/gui/pan
|
$ ./pan/gui/pan
|
||||||
</screen>
|
</screen>
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
use strict;
|
use strict;
|
||||||
use Nix::Config;
|
use Nix::Config;
|
||||||
use Nix::Store;
|
use Nix::Store;
|
||||||
|
use Nix::Utils;
|
||||||
use File::Temp qw(tempdir);
|
use File::Temp qw(tempdir);
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ my @buildArgs = ();
|
||||||
my @exprs = ();
|
my @exprs = ();
|
||||||
|
|
||||||
my $shell = $ENV{SHELL} || "/bin/sh";
|
my $shell = $ENV{SHELL} || "/bin/sh";
|
||||||
my $envCommand = "p=\$PATH; source \$stdenv/setup; PATH=\$PATH:\$p; exec $shell";
|
my $envCommand = ""; # interactive shell
|
||||||
my @envExclude = ();
|
my @envExclude = ();
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,7 +125,7 @@ for (my $n = 0; $n < scalar @ARGV; $n++) {
|
||||||
elsif ($arg eq "--command") {
|
elsif ($arg eq "--command") {
|
||||||
$n++;
|
$n++;
|
||||||
die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
|
die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
|
||||||
$envCommand = $ARGV[$n];
|
$envCommand = "$ARGV[$n]\nexit $!";
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ($arg eq "--exclude") {
|
elsif ($arg eq "--exclude") {
|
||||||
|
@ -169,15 +170,23 @@ foreach my $expr (@exprs) {
|
||||||
|
|
||||||
# Set the environment.
|
# Set the environment.
|
||||||
$ENV{'NIX_BUILD_TOP'} = $ENV{'TMPDIR'} || "/tmp";
|
$ENV{'NIX_BUILD_TOP'} = $ENV{'TMPDIR'} || "/tmp";
|
||||||
foreach (keys %{$drv->{env}}) {
|
$ENV{$_} = $drv->{env}->{$_} foreach keys %{$drv->{env}};
|
||||||
$ENV{$_} = $drv->{env}->{$_};
|
|
||||||
}
|
|
||||||
|
|
||||||
# Run a shell using the derivation's environment. For
|
# Run a shell using the derivation's environment. For
|
||||||
# convenience, source $stdenv/setup to setup additional
|
# convenience, source $stdenv/setup to setup additional
|
||||||
# environment variables. Also don't lose the current $PATH
|
# environment variables and shell functions. Also don't lose
|
||||||
# directories.
|
# the current $PATH directories.
|
||||||
exec($ENV{SHELL}, "-c", $envCommand);
|
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;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue