2012-01-05 21:33:46 +01:00
|
|
|
|
#! @perl@ -w @perlFlags@
|
2006-03-03 15:15:02 +01:00
|
|
|
|
|
2014-08-29 17:48:25 +02:00
|
|
|
|
use utf8;
|
2006-03-03 15:15:02 +01:00
|
|
|
|
use strict;
|
2012-01-03 01:47:27 +01:00
|
|
|
|
use Nix::Config;
|
2012-03-19 04:14:21 +01:00
|
|
|
|
use Nix::Store;
|
2013-07-11 14:32:22 +02:00
|
|
|
|
use Nix::Utils;
|
2015-01-08 14:56:14 +01:00
|
|
|
|
use File::Basename;
|
2015-12-07 01:31:26 +01:00
|
|
|
|
use Text::ParseWords;
|
2015-01-08 14:56:14 +01:00
|
|
|
|
use Cwd;
|
2008-11-20 16:44:59 +01:00
|
|
|
|
|
2014-08-29 17:48:25 +02:00
|
|
|
|
binmode STDERR, ":encoding(utf8)";
|
2006-03-03 15:15:02 +01:00
|
|
|
|
|
2008-08-04 15:46:01 +02:00
|
|
|
|
my $dryRun = 0;
|
2009-12-09 19:08:28 +01:00
|
|
|
|
my $verbose = 0;
|
2013-07-19 12:02:44 +02:00
|
|
|
|
my $runEnv = $0 =~ /nix-shell$/;
|
2013-07-19 11:23:32 +02:00
|
|
|
|
my $pure = 0;
|
2014-02-19 16:30:19 +01:00
|
|
|
|
my $fromArgs = 0;
|
2014-02-19 17:08:01 +01:00
|
|
|
|
my $packages = 0;
|
2015-01-08 15:14:38 +01:00
|
|
|
|
my $interactive = 1;
|
2008-08-04 15:46:01 +02:00
|
|
|
|
|
2006-03-03 15:15:02 +01:00
|
|
|
|
my @instArgs = ();
|
|
|
|
|
my @buildArgs = ();
|
|
|
|
|
my @exprs = ();
|
|
|
|
|
|
2012-04-10 13:52:37 +02:00
|
|
|
|
my $shell = $ENV{SHELL} || "/bin/sh";
|
2013-07-11 14:32:22 +02:00
|
|
|
|
my $envCommand = ""; # interactive shell
|
2012-03-27 11:40:47 +02:00
|
|
|
|
my @envExclude = ();
|
2012-03-27 11:16:43 +02:00
|
|
|
|
|
2013-07-19 12:02:44 +02:00
|
|
|
|
my $myName = $runEnv ? "nix-shell" : "nix-build";
|
2006-03-03 15:15:02 +01:00
|
|
|
|
|
2015-01-08 14:32:45 +01:00
|
|
|
|
my $inShebang = 0;
|
|
|
|
|
my $script;
|
2015-02-18 15:55:18 +01:00
|
|
|
|
my @savedArgs;
|
2013-07-19 12:02:44 +02:00
|
|
|
|
|
2014-08-13 23:12:57 +02:00
|
|
|
|
my $tmpDir = mkTempDir($myName);
|
2006-03-03 15:15:02 +01:00
|
|
|
|
|
2012-01-14 00:35:07 +01:00
|
|
|
|
my $outLink = "./result";
|
|
|
|
|
my $drvLink = "$tmpDir/derivation";
|
2006-03-03 15:15:02 +01:00
|
|
|
|
|
2012-01-14 00:35:07 +01:00
|
|
|
|
# Ensure that the $tmpDir is deleted.
|
|
|
|
|
$SIG{'INT'} = sub { exit 1 };
|
2006-03-03 15:15:02 +01:00
|
|
|
|
|
|
|
|
|
|
2015-01-08 14:32:45 +01:00
|
|
|
|
# Heuristic to see if we're invoked as a shebang script, namely, if we
|
|
|
|
|
# have a single argument, it's the name of an executable file, and it
|
|
|
|
|
# starts with "#!".
|
2015-05-05 14:19:58 +02:00
|
|
|
|
if ($runEnv && defined $ARGV[0] && $ARGV[0] !~ /nix-shell/) {
|
2015-01-08 14:32:45 +01:00
|
|
|
|
$script = $ARGV[0];
|
|
|
|
|
if (-f $script && -x $script) {
|
|
|
|
|
open SCRIPT, "<$script" or die "$0: cannot open ‘$script’: $!\n";
|
|
|
|
|
my $first = <SCRIPT>;
|
|
|
|
|
if ($first =~ /^\#\!/) {
|
|
|
|
|
$inShebang = 1;
|
2015-02-18 15:55:18 +01:00
|
|
|
|
@savedArgs = @ARGV; shift @savedArgs;
|
2015-01-08 14:32:45 +01:00
|
|
|
|
@ARGV = ();
|
|
|
|
|
while (<SCRIPT>) {
|
|
|
|
|
chomp;
|
|
|
|
|
if (/^\#\!\s*nix-shell (.*)$/) {
|
2016-01-20 04:16:42 +01:00
|
|
|
|
push @ARGV, shellwords($1);
|
2015-01-08 14:32:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
close SCRIPT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-03-03 15:15:02 +01:00
|
|
|
|
for (my $n = 0; $n < scalar @ARGV; $n++) {
|
|
|
|
|
my $arg = $ARGV[$n];
|
|
|
|
|
|
|
|
|
|
if ($arg eq "--help") {
|
2013-07-19 12:02:44 +02:00
|
|
|
|
exec "man $myName" or die;
|
2006-03-03 15:15:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-12 00:07:41 +02:00
|
|
|
|
elsif ($arg eq "--version") {
|
2013-07-19 12:02:44 +02:00
|
|
|
|
print "$myName (Nix) $Nix::Config::version\n";
|
2012-07-12 00:07:41 +02:00
|
|
|
|
exit 0;
|
|
|
|
|
}
|
2012-10-03 22:37:06 +02:00
|
|
|
|
|
2006-03-03 15:15:02 +01:00
|
|
|
|
elsif ($arg eq "--add-drv-link") {
|
2012-01-14 00:35:07 +01:00
|
|
|
|
$drvLink = "./derivation";
|
2006-03-03 15:15:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-19 16:30:19 +01:00
|
|
|
|
elsif ($arg eq "--no-out-link" || $arg eq "--no-link") {
|
2012-01-14 00:35:07 +01:00
|
|
|
|
$outLink = "$tmpDir/result";
|
2006-03-03 15:15:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2006-03-14 17:35:01 +01:00
|
|
|
|
elsif ($arg eq "--drv-link") {
|
|
|
|
|
$n++;
|
2014-08-20 17:00:17 +02:00
|
|
|
|
die "$0: ‘$arg’ requires an argument\n" unless $n < scalar @ARGV;
|
2006-03-14 17:35:01 +01:00
|
|
|
|
$drvLink = $ARGV[$n];
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-19 16:30:19 +01:00
|
|
|
|
elsif ($arg eq "--out-link" || $arg eq "-o") {
|
2006-03-14 17:35:01 +01:00
|
|
|
|
$n++;
|
2014-08-20 17:00:17 +02:00
|
|
|
|
die "$0: ‘$arg’ requires an argument\n" unless $n < scalar @ARGV;
|
2006-03-14 17:35:01 +01:00
|
|
|
|
$outLink = $ARGV[$n];
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-19 16:30:19 +01:00
|
|
|
|
elsif ($arg eq "--attr" || $arg eq "-A" || $arg eq "-I") {
|
2006-03-03 15:15:02 +01:00
|
|
|
|
$n++;
|
2014-08-20 17:00:17 +02:00
|
|
|
|
die "$0: ‘$arg’ requires an argument\n" unless $n < scalar @ARGV;
|
2011-08-06 18:05:24 +02:00
|
|
|
|
push @instArgs, ($arg, $ARGV[$n]);
|
2006-03-03 15:15:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-15 17:52:40 +01:00
|
|
|
|
elsif ($arg eq "--arg" || $arg eq "--argstr") {
|
2014-08-20 17:00:17 +02:00
|
|
|
|
die "$0: ‘$arg’ requires two arguments\n" unless $n + 2 < scalar @ARGV;
|
2007-11-15 17:52:40 +01:00
|
|
|
|
push @instArgs, ($arg, $ARGV[$n + 1], $ARGV[$n + 2]);
|
2006-07-28 18:03:28 +02:00
|
|
|
|
$n += 2;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-18 14:15:55 +01:00
|
|
|
|
elsif ($arg eq "--log-type") {
|
|
|
|
|
$n++;
|
2014-08-20 17:00:17 +02:00
|
|
|
|
die "$0: ‘$arg’ requires an argument\n" unless $n < scalar @ARGV;
|
2009-03-18 14:15:55 +01:00
|
|
|
|
push @instArgs, ($arg, $ARGV[$n]);
|
|
|
|
|
push @buildArgs, ($arg, $ARGV[$n]);
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-27 13:09:30 +01:00
|
|
|
|
elsif ($arg eq "--option") {
|
2014-08-20 17:00:17 +02:00
|
|
|
|
die "$0: ‘$arg’ requires two arguments\n" unless $n + 2 < scalar @ARGV;
|
2009-02-27 13:09:30 +01:00
|
|
|
|
push @instArgs, ($arg, $ARGV[$n + 1], $ARGV[$n + 2]);
|
|
|
|
|
push @buildArgs, ($arg, $ARGV[$n + 1], $ARGV[$n + 2]);
|
|
|
|
|
$n += 2;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-04 14:26:41 +02:00
|
|
|
|
elsif ($arg eq "--max-jobs" || $arg eq "-j" || $arg eq "--max-silent-time" || $arg eq "--log-type" || $arg eq "--cores" || $arg eq "--timeout" || $arg eq '--add-root') {
|
2006-12-08 16:44:00 +01:00
|
|
|
|
$n++;
|
2014-08-20 17:00:17 +02:00
|
|
|
|
die "$0: ‘$arg’ requires an argument\n" unless $n < scalar @ARGV;
|
2006-12-08 16:44:00 +01:00
|
|
|
|
push @buildArgs, ($arg, $ARGV[$n]);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-04 15:46:01 +02:00
|
|
|
|
elsif ($arg eq "--dry-run") {
|
|
|
|
|
push @buildArgs, "--dry-run";
|
|
|
|
|
$dryRun = 1;
|
|
|
|
|
}
|
2012-08-24 22:58:11 +02:00
|
|
|
|
|
2009-07-15 11:10:38 +02:00
|
|
|
|
elsif ($arg eq "--show-trace") {
|
|
|
|
|
push @instArgs, $arg;
|
|
|
|
|
}
|
2012-07-23 23:11:12 +02:00
|
|
|
|
|
|
|
|
|
elsif ($arg eq "-") {
|
|
|
|
|
@exprs = ("-");
|
|
|
|
|
}
|
2012-08-24 22:58:11 +02:00
|
|
|
|
|
2014-02-19 16:30:19 +01:00
|
|
|
|
elsif ($arg eq "--verbose" || substr($arg, 0, 2) eq "-v") {
|
2009-12-09 19:08:28 +01:00
|
|
|
|
push @buildArgs, $arg;
|
|
|
|
|
push @instArgs, $arg;
|
|
|
|
|
$verbose = 1;
|
|
|
|
|
}
|
2012-08-24 22:58:11 +02:00
|
|
|
|
|
2012-10-03 21:14:02 +02:00
|
|
|
|
elsif ($arg eq "--quiet" || $arg eq "--repair") {
|
2010-08-30 16:53:03 +02:00
|
|
|
|
push @buildArgs, $arg;
|
|
|
|
|
push @instArgs, $arg;
|
|
|
|
|
}
|
2012-08-24 22:58:11 +02:00
|
|
|
|
|
2014-02-18 01:01:14 +01:00
|
|
|
|
elsif ($arg eq "--check") {
|
|
|
|
|
push @buildArgs, $arg;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 12:02:44 +02:00
|
|
|
|
elsif ($arg eq "--run-env") { # obsolete
|
2012-03-19 04:14:21 +01:00
|
|
|
|
$runEnv = 1;
|
|
|
|
|
}
|
2012-08-24 22:58:11 +02:00
|
|
|
|
|
2015-01-08 15:14:38 +01:00
|
|
|
|
elsif ($arg eq "--command" || $arg eq "--run") {
|
2012-03-27 11:16:43 +02:00
|
|
|
|
$n++;
|
2014-08-20 17:00:17 +02:00
|
|
|
|
die "$0: ‘$arg’ requires an argument\n" unless $n < scalar @ARGV;
|
2015-01-07 16:10:20 +01:00
|
|
|
|
$envCommand = "$ARGV[$n]\nexit";
|
2015-01-08 15:14:38 +01:00
|
|
|
|
$interactive = 0 if $arg eq "--run";
|
2012-03-27 11:16:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-27 11:40:47 +02:00
|
|
|
|
elsif ($arg eq "--exclude") {
|
|
|
|
|
$n++;
|
2014-08-20 17:00:17 +02:00
|
|
|
|
die "$0: ‘$arg’ requires an argument\n" unless $n < scalar @ARGV;
|
2012-03-27 11:40:47 +02:00
|
|
|
|
push @envExclude, $ARGV[$n];
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-23 13:33:00 +01:00
|
|
|
|
elsif ($arg eq "--pure") { $pure = 1; }
|
|
|
|
|
elsif ($arg eq "--impure") { $pure = 0; }
|
2013-07-19 11:23:32 +02:00
|
|
|
|
|
2014-02-19 16:30:19 +01:00
|
|
|
|
elsif ($arg eq "--expr" || $arg eq "-E") {
|
|
|
|
|
$fromArgs = 1;
|
|
|
|
|
push @instArgs, "--expr";
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-19 17:08:01 +01:00
|
|
|
|
elsif ($arg eq "--packages" || $arg eq "-p") {
|
|
|
|
|
$packages = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-08 14:32:45 +01:00
|
|
|
|
elsif ($inShebang && $arg eq "-i") {
|
|
|
|
|
$n++;
|
|
|
|
|
die "$0: ‘$arg’ requires an argument\n" unless $n < scalar @ARGV;
|
|
|
|
|
my $interpreter = $ARGV[$n];
|
|
|
|
|
# Überhack to support Perl. Perl examines the shebang and
|
|
|
|
|
# executes it unless it contains the string "perl" or "indir",
|
|
|
|
|
# or (undocumented) argv[0] does not contain "perl". Exploit
|
|
|
|
|
# the latter by doing "exec -a".
|
|
|
|
|
my $execArgs = $interpreter =~ /perl/ ? "-a PERL" : "";
|
2015-02-18 20:13:53 +01:00
|
|
|
|
sub shellEscape {
|
|
|
|
|
my $s = $_;
|
|
|
|
|
$s =~ s/'/'\\''/g;
|
|
|
|
|
return "'" . $s . "'";
|
|
|
|
|
}
|
|
|
|
|
$envCommand = "exec $execArgs $interpreter $script ${\(join ' ', (map shellEscape, @savedArgs))}";
|
2015-01-08 14:32:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
2006-03-03 15:15:02 +01:00
|
|
|
|
elsif (substr($arg, 0, 1) eq "-") {
|
|
|
|
|
push @buildArgs, $arg;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-09 02:44:05 +01:00
|
|
|
|
elsif ($arg eq "-Q" || $arg eq "--no-build-output") {
|
|
|
|
|
push @buildArgs, $arg;
|
|
|
|
|
push @instArgs, $arg;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-03 15:15:02 +01:00
|
|
|
|
else {
|
|
|
|
|
push @exprs, $arg;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-21 17:04:34 +02:00
|
|
|
|
die "$0: ‘-p’ and ‘-E’ are mutually exclusive\n" if $packages && $fromArgs;
|
|
|
|
|
|
2014-02-19 17:08:01 +01:00
|
|
|
|
if ($packages) {
|
|
|
|
|
push @instArgs, "--expr";
|
|
|
|
|
@exprs = (
|
|
|
|
|
'with import <nixpkgs> { }; runCommand "shell" { buildInputs = [ '
|
|
|
|
|
. (join " ", map { "($_)" } @exprs) . ']; } ""');
|
|
|
|
|
} elsif (!$fromArgs) {
|
2014-02-19 16:30:19 +01:00
|
|
|
|
@exprs = ("shell.nix") if scalar @exprs == 0 && $runEnv && -e "shell.nix";
|
|
|
|
|
@exprs = ("default.nix") if scalar @exprs == 0;
|
|
|
|
|
}
|
2006-03-03 15:15:02 +01:00
|
|
|
|
|
2014-01-13 13:42:29 +01:00
|
|
|
|
$ENV{'IN_NIX_SHELL'} = 1 if $runEnv;
|
|
|
|
|
|
2006-03-03 15:15:02 +01:00
|
|
|
|
|
|
|
|
|
foreach my $expr (@exprs) {
|
|
|
|
|
|
|
|
|
|
# Instantiate.
|
2006-07-28 18:03:28 +02:00
|
|
|
|
my @drvPaths;
|
2013-09-06 14:58:05 +02:00
|
|
|
|
if ($expr !~ /^\/.*\.drv$/) {
|
2015-01-08 14:56:14 +01:00
|
|
|
|
# If we're in a #! script, interpret filenames relative to the
|
|
|
|
|
# script.
|
|
|
|
|
$expr = dirname(Cwd::abs_path($script)) . "/" . $expr
|
2015-02-18 12:40:07 +01:00
|
|
|
|
if $inShebang && !$packages && $expr !~ /^\//;
|
2015-01-08 14:56:14 +01:00
|
|
|
|
|
2013-09-06 14:58:05 +02:00
|
|
|
|
# !!! would prefer the perl 5.8.0 pipe open feature here.
|
|
|
|
|
my $pid = open(DRVPATHS, "-|") || exec "$Nix::Config::binDir/nix-instantiate", "--add-root", $drvLink, "--indirect", @instArgs, $expr;
|
|
|
|
|
while (<DRVPATHS>) {chomp; push @drvPaths, $_;}
|
|
|
|
|
if (!close DRVPATHS) {
|
|
|
|
|
die "nix-instantiate killed by signal " . ($? & 127) . "\n" if ($? & 127);
|
|
|
|
|
exit 1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
push @drvPaths, $expr;
|
2009-06-10 13:30:34 +02:00
|
|
|
|
}
|
2006-03-03 15:15:02 +01:00
|
|
|
|
|
2012-03-19 04:14:21 +01:00
|
|
|
|
if ($runEnv) {
|
2013-07-19 12:02:44 +02:00
|
|
|
|
die "$0: a single derivation is required\n" if scalar @drvPaths != 1;
|
2013-09-06 14:58:05 +02:00
|
|
|
|
my $drvPath = $drvPaths[0];
|
2014-03-29 12:43:11 +01:00
|
|
|
|
$drvPath = (split '!',$drvPath)[0];
|
2014-08-20 17:00:17 +02:00
|
|
|
|
$drvPath = readlink $drvPath or die "cannot read symlink ‘$drvPath’" if -l $drvPath;
|
2012-03-19 04:14:21 +01:00
|
|
|
|
my $drv = derivationFromPath($drvPath);
|
|
|
|
|
|
|
|
|
|
# Build or fetch all dependencies of the derivation.
|
2012-03-27 11:40:47 +02:00
|
|
|
|
my @inputDrvs = grep { my $x = $_; (grep { $x =~ $_ } @envExclude) == 0 } @{$drv->{inputDrvs}};
|
2013-12-20 13:19:10 +01:00
|
|
|
|
system("$Nix::Config::binDir/nix-store", "-r", "--no-output", "--no-gc-warning", @buildArgs, @inputDrvs, @{$drv->{inputSrcs}}) == 0
|
2012-03-19 04:14:21 +01:00
|
|
|
|
or die "$0: failed to build all dependencies\n";
|
|
|
|
|
|
|
|
|
|
# Set the environment.
|
2014-08-13 23:16:08 +02:00
|
|
|
|
my $tmp = $ENV{"TMPDIR"} // $ENV{"XDG_RUNTIME_DIR"} // "/tmp";
|
2013-07-19 11:23:32 +02:00
|
|
|
|
if ($pure) {
|
|
|
|
|
foreach my $name (keys %ENV) {
|
2015-12-07 16:47:31 +01:00
|
|
|
|
next if grep { $_ eq $name } ("HOME", "USER", "LOGNAME", "DISPLAY", "PATH", "TERM", "IN_NIX_SHELL", "TZ", "PAGER", "NIX_BUILD_SHELL");
|
2013-07-19 11:23:32 +02:00
|
|
|
|
delete $ENV{$name};
|
|
|
|
|
}
|
|
|
|
|
# NixOS hack: prevent /etc/bashrc from sourcing /etc/profile.
|
|
|
|
|
$ENV{'__ETC_PROFILE_SOURCED'} = 1;
|
|
|
|
|
}
|
2014-08-13 23:16:08 +02:00
|
|
|
|
$ENV{'NIX_BUILD_TOP'} = $ENV{'TMPDIR'} = $ENV{'TEMPDIR'} = $ENV{'TMP'} = $ENV{'TEMP'} = $tmp;
|
2013-07-19 14:06:58 +02:00
|
|
|
|
$ENV{'NIX_STORE'} = $Nix::Config::storeDir;
|
2013-07-11 14:32:22 +02:00
|
|
|
|
$ENV{$_} = $drv->{env}->{$_} foreach keys %{$drv->{env}};
|
2012-03-19 04:14:21 +01:00
|
|
|
|
|
|
|
|
|
# Run a shell using the derivation's environment. For
|
|
|
|
|
# convenience, source $stdenv/setup to setup additional
|
2013-07-11 14:32:22 +02:00
|
|
|
|
# environment variables and shell functions. Also don't lose
|
|
|
|
|
# the current $PATH directories.
|
|
|
|
|
my $rcfile = "$tmpDir/rc";
|
|
|
|
|
writeFile(
|
|
|
|
|
$rcfile,
|
2014-02-19 15:01:04 +01:00
|
|
|
|
"rm -rf '$tmpDir'; " .
|
2013-10-17 17:07:34 +02:00
|
|
|
|
'unset BASH_ENV; ' .
|
|
|
|
|
'[ -n "$PS1" ] && [ -e ~/.bashrc ] && source ~/.bashrc; ' .
|
2013-07-31 13:17:50 +02:00
|
|
|
|
($pure ? '' : 'p=$PATH; ' ) .
|
|
|
|
|
'dontAddDisableDepTrack=1; ' .
|
2013-07-11 14:32:22 +02:00
|
|
|
|
'[ -e $stdenv/setup ] && source $stdenv/setup; ' .
|
2014-01-23 13:31:29 +01:00
|
|
|
|
($pure ? '' : 'PATH=$PATH:$p; unset p; ') .
|
2013-07-11 14:32:22 +02:00
|
|
|
|
'set +e; ' .
|
2013-10-18 14:51:25 +02:00
|
|
|
|
'[ -n "$PS1" ] && PS1="\n\[\033[1;32m\][nix-shell:\w]$\[\033[0m\] "; ' .
|
2015-01-28 13:09:04 +01:00
|
|
|
|
'if [ "$(type -t runHook)" = function ]; then runHook shellHook; fi; ' .
|
2013-07-19 14:06:58 +02:00
|
|
|
|
'unset NIX_ENFORCE_PURITY; ' .
|
2014-01-13 13:46:44 +01:00
|
|
|
|
'unset NIX_INDENT_MAKE; ' .
|
2013-10-14 15:20:45 +02:00
|
|
|
|
'shopt -u nullglob; ' .
|
2014-01-23 13:31:29 +01:00
|
|
|
|
'unset TZ; ' . (defined $ENV{'TZ'} ? "export TZ='${ENV{'TZ'}}'; " : '') .
|
2013-07-11 14:32:22 +02:00
|
|
|
|
$envCommand);
|
2013-10-17 17:07:34 +02:00
|
|
|
|
$ENV{BASH_ENV} = $rcfile;
|
2015-01-08 15:14:38 +01:00
|
|
|
|
my @args = ($ENV{NIX_BUILD_SHELL} // "bash");
|
|
|
|
|
push @args, "--rcfile" if $interactive;
|
|
|
|
|
push @args, $rcfile;
|
|
|
|
|
exec @args;
|
2012-03-19 04:14:21 +01:00
|
|
|
|
die;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-26 15:39:10 +01:00
|
|
|
|
# Ugly hackery to make "nix-build -A foo.all" produce symlinks
|
|
|
|
|
# ./result, ./result-dev, and so on, rather than ./result,
|
|
|
|
|
# ./result-2-dev, and so on. This combines multiple derivation
|
|
|
|
|
# paths into one "/nix/store/drv-path!out1,out2,..." argument.
|
|
|
|
|
my $prevDrvPath = "";
|
|
|
|
|
my @drvPaths2;
|
2006-03-03 15:15:02 +01:00
|
|
|
|
foreach my $drvPath (@drvPaths) {
|
2012-11-26 15:39:10 +01:00
|
|
|
|
my $p = $drvPath; my $output = "out";
|
|
|
|
|
if ($drvPath =~ /(.*)!(.*)/) {
|
|
|
|
|
$p = $1; $output = $2;
|
|
|
|
|
} else {
|
|
|
|
|
$p = $drvPath;
|
|
|
|
|
}
|
2014-08-20 17:00:17 +02:00
|
|
|
|
my $target = readlink $p or die "cannot read symlink ‘$p’";
|
2009-12-09 19:08:28 +01:00
|
|
|
|
print STDERR "derivation is $target\n" if $verbose;
|
2012-11-26 15:39:10 +01:00
|
|
|
|
if ($target eq $prevDrvPath) {
|
|
|
|
|
push @drvPaths2, (pop @drvPaths2) . "," . $output;
|
|
|
|
|
} else {
|
|
|
|
|
push @drvPaths2, $target . "!" . $output;
|
|
|
|
|
$prevDrvPath = $target;
|
|
|
|
|
}
|
2006-03-03 15:15:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Build.
|
2006-10-19 19:30:09 +02:00
|
|
|
|
my @outPaths;
|
2013-09-06 14:58:05 +02:00
|
|
|
|
my $pid = open(OUTPATHS, "-|") || exec "$Nix::Config::binDir/nix-store", "--add-root", $outLink, "--indirect", "-r",
|
2012-11-26 15:39:10 +01:00
|
|
|
|
@buildArgs, @drvPaths2;
|
2006-10-19 19:30:09 +02:00
|
|
|
|
while (<OUTPATHS>) {chomp; push @outPaths, $_;}
|
2009-06-10 13:30:34 +02:00
|
|
|
|
if (!close OUTPATHS) {
|
|
|
|
|
die "nix-store killed by signal " . ($? & 127) . "\n" if ($? & 127);
|
2014-12-05 19:25:13 +01:00
|
|
|
|
exit ($? >> 8 || 1);
|
2009-06-10 13:30:34 +02:00
|
|
|
|
}
|
2006-10-19 19:30:09 +02:00
|
|
|
|
|
2008-08-04 15:46:01 +02:00
|
|
|
|
next if $dryRun;
|
|
|
|
|
|
2006-03-03 15:15:02 +01:00
|
|
|
|
foreach my $outPath (@outPaths) {
|
2014-08-20 17:00:17 +02:00
|
|
|
|
my $target = readlink $outPath or die "cannot read symlink ‘$outPath’";
|
2006-03-03 15:15:02 +01:00
|
|
|
|
print "$target\n";
|
|
|
|
|
}
|
|
|
|
|
}
|