2006-03-03 15:15:02 +01:00
|
|
|
#! @perl@ -w -I@libexecdir@/nix
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
2008-11-20 16:44:59 +01:00
|
|
|
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
|
|
|
|
|
2006-03-03 15:15:02 +01:00
|
|
|
|
|
|
|
my $addDrvLink = 0;
|
|
|
|
my $addOutLink = 1;
|
|
|
|
|
2006-03-14 17:35:01 +01:00
|
|
|
my $outLink;
|
|
|
|
my $drvLink;
|
|
|
|
|
2008-08-04 15:46:01 +02:00
|
|
|
my $dryRun = 0;
|
2009-12-09 19:08:28 +01:00
|
|
|
my $verbose = 0;
|
2008-08-04 15:46:01 +02:00
|
|
|
|
2006-03-03 15:15:02 +01:00
|
|
|
my @instArgs = ();
|
|
|
|
my @buildArgs = ();
|
|
|
|
my @exprs = ();
|
|
|
|
|
|
|
|
|
|
|
|
END {
|
|
|
|
foreach my $fn (glob ".nix-build-tmp-*") {
|
|
|
|
unlink $fn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub intHandler {
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$SIG{'INT'} = 'intHandler';
|
|
|
|
|
|
|
|
|
|
|
|
for (my $n = 0; $n < scalar @ARGV; $n++) {
|
|
|
|
my $arg = $ARGV[$n];
|
|
|
|
|
|
|
|
if ($arg eq "--help") {
|
2006-03-03 15:25:07 +01:00
|
|
|
print STDERR <<EOF;
|
|
|
|
Usage: nix-build [OPTION]... [FILE]...
|
|
|
|
|
|
|
|
`nix-build' builds the given Nix expressions (which
|
|
|
|
default to ./default.nix if none are given). A symlink called
|
|
|
|
`result' is placed in the current directory.
|
|
|
|
|
|
|
|
Flags:
|
|
|
|
--add-drv-link: create a symlink `derivation' to the store derivation
|
2006-03-14 17:35:01 +01:00
|
|
|
--drv-link NAME: create symlink NAME instead of `derivation'
|
2006-03-03 15:25:07 +01:00
|
|
|
--no-out-link: do not create the `result' symlink
|
2006-03-14 17:35:01 +01:00
|
|
|
--out-link / -o NAME: create symlink NAME instead of `result'
|
2006-03-03 15:25:07 +01:00
|
|
|
--attr ATTR: select a specific attribution from the Nix expression
|
|
|
|
|
|
|
|
Any additional flags are passed to `nix-store'.
|
|
|
|
EOF
|
2006-03-03 15:15:02 +01:00
|
|
|
exit 0;
|
2006-03-14 17:35:01 +01:00
|
|
|
# '` hack
|
2006-03-03 15:15:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
elsif ($arg eq "--add-drv-link") {
|
|
|
|
$addDrvLink = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
elsif ($arg eq "--no-out-link" or $arg eq "--no-link") {
|
2006-10-31 19:45:17 +01:00
|
|
|
$addOutLink = 0;
|
2006-03-03 15:15:02 +01:00
|
|
|
}
|
|
|
|
|
2006-03-14 17:35:01 +01:00
|
|
|
elsif ($arg eq "--drv-link") {
|
|
|
|
$n++;
|
|
|
|
die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
|
|
|
|
$drvLink = $ARGV[$n];
|
|
|
|
}
|
|
|
|
|
|
|
|
elsif ($arg eq "--out-link" or $arg eq "-o") {
|
|
|
|
$n++;
|
|
|
|
die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
|
|
|
|
$outLink = $ARGV[$n];
|
|
|
|
}
|
|
|
|
|
2006-03-03 15:15:02 +01:00
|
|
|
elsif ($arg eq "--attr" or $arg eq "-A") {
|
|
|
|
$n++;
|
2009-03-18 14:15:55 +01:00
|
|
|
die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
|
2006-03-03 15:15:02 +01:00
|
|
|
push @instArgs, ("--attr", $ARGV[$n]);
|
|
|
|
}
|
|
|
|
|
2007-11-15 17:52:40 +01:00
|
|
|
elsif ($arg eq "--arg" || $arg eq "--argstr") {
|
|
|
|
die "$0: `$arg' requires two arguments\n" unless $n + 2 < scalar @ARGV;
|
|
|
|
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++;
|
|
|
|
die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
|
|
|
|
push @instArgs, ($arg, $ARGV[$n]);
|
|
|
|
push @buildArgs, ($arg, $ARGV[$n]);
|
|
|
|
}
|
|
|
|
|
2009-02-27 13:09:30 +01:00
|
|
|
elsif ($arg eq "--option") {
|
|
|
|
die "$0: `$arg' requires two arguments\n" unless $n + 2 < scalar @ARGV;
|
|
|
|
push @instArgs, ($arg, $ARGV[$n + 1], $ARGV[$n + 2]);
|
|
|
|
push @buildArgs, ($arg, $ARGV[$n + 1], $ARGV[$n + 2]);
|
|
|
|
$n += 2;
|
|
|
|
}
|
|
|
|
|
2010-08-24 11:21:59 +02:00
|
|
|
elsif ($arg eq "--max-jobs" or $arg eq "-j" or $arg eq "--max-silent-time" or $arg eq "--log-type" or $arg eq "--cores") {
|
2006-12-08 16:44:00 +01:00
|
|
|
$n++;
|
|
|
|
die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
|
|
|
|
push @buildArgs, ($arg, $ARGV[$n]);
|
|
|
|
}
|
|
|
|
|
2008-08-04 15:46:01 +02:00
|
|
|
elsif ($arg eq "--dry-run") {
|
|
|
|
push @buildArgs, "--dry-run";
|
|
|
|
$dryRun = 1;
|
|
|
|
}
|
|
|
|
|
2009-07-15 11:10:38 +02:00
|
|
|
elsif ($arg eq "--show-trace") {
|
|
|
|
push @instArgs, $arg;
|
|
|
|
}
|
|
|
|
|
2009-12-09 19:08:28 +01:00
|
|
|
elsif ($arg eq "--verbose" or substr($arg, 0, 2) eq "-v") {
|
|
|
|
push @buildArgs, $arg;
|
|
|
|
push @instArgs, $arg;
|
|
|
|
$verbose = 1;
|
|
|
|
}
|
|
|
|
|
2006-03-03 15:15:02 +01:00
|
|
|
elsif (substr($arg, 0, 1) eq "-") {
|
|
|
|
push @buildArgs, $arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
push @exprs, $arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@exprs = ("./default.nix") if scalar @exprs == 0;
|
|
|
|
|
|
|
|
|
2006-03-14 17:35:01 +01:00
|
|
|
if (!defined $drvLink) {
|
|
|
|
$drvLink = "derivation";
|
|
|
|
$drvLink = ".nix-build-tmp-" . $drvLink if !$addDrvLink;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!defined $outLink) {
|
|
|
|
$outLink = "result";
|
|
|
|
$outLink = ".nix-build-tmp-" . $outLink if !$addOutLink;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-03 15:15:02 +01:00
|
|
|
foreach my $expr (@exprs) {
|
|
|
|
|
|
|
|
# Instantiate.
|
2006-07-28 18:03:28 +02:00
|
|
|
my @drvPaths;
|
2006-08-04 13:51:46 +02:00
|
|
|
# !!! would prefer the perl 5.8.0 pipe open feature here.
|
2008-11-20 16:44:59 +01:00
|
|
|
my $pid = open(DRVPATHS, "-|") || exec "$binDir/nix-instantiate", "--add-root", $drvLink, "--indirect", @instArgs, $expr;
|
2006-07-28 18:03:28 +02:00
|
|
|
while (<DRVPATHS>) {chomp; push @drvPaths, $_;}
|
2009-06-10 13:30:34 +02:00
|
|
|
if (!close DRVPATHS) {
|
|
|
|
die "nix-instantiate killed by signal " . ($? & 127) . "\n" if ($? & 127);
|
|
|
|
exit 1;
|
|
|
|
}
|
2006-03-03 15:15:02 +01:00
|
|
|
|
|
|
|
foreach my $drvPath (@drvPaths) {
|
2007-06-11 13:36:22 +02:00
|
|
|
my $target = readlink $drvPath or die "cannot read symlink `$drvPath'";
|
2009-12-09 19:08:28 +01:00
|
|
|
print STDERR "derivation is $target\n" if $verbose;
|
2006-03-03 15:15:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Build.
|
2006-10-19 19:30:09 +02:00
|
|
|
my @outPaths;
|
2008-11-20 16:44:59 +01:00
|
|
|
$pid = open(OUTPATHS, "-|") || exec "$binDir/nix-store", "--add-root", $outLink, "--indirect", "-rv",
|
2006-10-19 19:30:09 +02:00
|
|
|
@buildArgs, @drvPaths;
|
|
|
|
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);
|
|
|
|
exit 1;
|
|
|
|
}
|
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) {
|
2007-06-11 13:36:22 +02:00
|
|
|
my $target = readlink $outPath or die "cannot read symlink `$outPath'";
|
2006-03-03 15:15:02 +01:00
|
|
|
print "$target\n";
|
|
|
|
}
|
|
|
|
}
|