2006-03-03 16:15:02 +02:00
|
|
|
#! @perl@ -w -I@libexecdir@/nix
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
|
|
|
|
my $addDrvLink = 0;
|
|
|
|
my $addOutLink = 1;
|
|
|
|
|
2006-03-14 18:35:01 +02:00
|
|
|
my $outLink;
|
|
|
|
my $drvLink;
|
|
|
|
|
2006-03-03 16:15:02 +02: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 16:25:07 +02: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 18:35:01 +02:00
|
|
|
--drv-link NAME: create symlink NAME instead of `derivation'
|
2006-03-03 16:25:07 +02:00
|
|
|
--no-out-link: do not create the `result' symlink
|
2006-03-14 18:35:01 +02:00
|
|
|
--out-link / -o NAME: create symlink NAME instead of `result'
|
2006-03-03 16:25:07 +02:00
|
|
|
--attr ATTR: select a specific attribution from the Nix expression
|
|
|
|
|
|
|
|
Any additional flags are passed to `nix-store'.
|
|
|
|
EOF
|
2006-03-03 16:15:02 +02:00
|
|
|
exit 0;
|
2006-03-14 18:35:01 +02:00
|
|
|
# '` hack
|
2006-03-03 16:15:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
elsif ($arg eq "--add-drv-link") {
|
|
|
|
$addDrvLink = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
elsif ($arg eq "--no-out-link" or $arg eq "--no-link") {
|
|
|
|
$addOutLink = 1;
|
|
|
|
}
|
|
|
|
|
2006-03-14 18:35:01 +02: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 16:15:02 +02:00
|
|
|
elsif ($arg eq "--attr" or $arg eq "-A") {
|
|
|
|
$n++;
|
|
|
|
die "$0: `--attr' requires an argument\n" unless $n < scalar @ARGV;
|
|
|
|
push @instArgs, ("--attr", $ARGV[$n]);
|
|
|
|
}
|
|
|
|
|
|
|
|
elsif (substr($arg, 0, 1) eq "-") {
|
|
|
|
push @buildArgs, $arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
push @exprs, $arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@exprs = ("./default.nix") if scalar @exprs == 0;
|
|
|
|
|
|
|
|
|
2006-03-14 18:35:01 +02: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 16:15:02 +02:00
|
|
|
foreach my $expr (@exprs) {
|
|
|
|
|
|
|
|
# Instantiate.
|
2006-03-14 18:35:01 +02:00
|
|
|
my $drvPaths = `@bindir@/nix-instantiate --add-root "$drvLink" --indirect @instArgs "$expr"`;
|
2006-03-03 16:15:02 +02:00
|
|
|
my @drvPaths = split ' ', $drvPaths;
|
|
|
|
|
|
|
|
foreach my $drvPath (@drvPaths) {
|
|
|
|
my $target = readlink $drvPath;
|
|
|
|
print STDERR "store derivation is $target\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Build.
|
2006-03-14 18:35:01 +02:00
|
|
|
my $outPaths = `@bindir@/nix-store --add-root "$outLink" --indirect -rv @buildArgs @drvPaths`;
|
2006-03-03 16:15:02 +02:00
|
|
|
my @outPaths = split ' ', $outPaths;
|
|
|
|
|
|
|
|
foreach my $outPath (@outPaths) {
|
|
|
|
my $target = readlink $outPath;
|
|
|
|
print "$target\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|