mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 14:06:16 +02:00
* Rewrote nix-build in Perl, since sh is just too limited (turns out
that arrays are a bash extension, so it didn't work on FreeBSD). Also fixes NIX-8 (readlink(1) dependency).
This commit is contained in:
parent
78d84f5631
commit
2d54312f87
1 changed files with 75 additions and 66 deletions
|
@ -1,78 +1,87 @@
|
||||||
#! @shell@ -e
|
#! @perl@ -w -I@libexecdir@/nix
|
||||||
|
|
||||||
nixExpr=$1
|
use strict;
|
||||||
|
|
||||||
extraArgs=
|
|
||||||
extraInstArgs=
|
|
||||||
addDrvLink=0
|
|
||||||
addOutLink=1
|
|
||||||
|
|
||||||
|
|
||||||
trap 'rm -f ./.nix-build-tmp-*' EXIT
|
my $addDrvLink = 0;
|
||||||
|
my $addOutLink = 1;
|
||||||
|
|
||||||
|
my @instArgs = ();
|
||||||
|
my @buildArgs = ();
|
||||||
|
my @exprs = ();
|
||||||
|
|
||||||
|
|
||||||
# Process the arguments.
|
END {
|
||||||
args=("$@")
|
foreach my $fn (glob ".nix-build-tmp-*") {
|
||||||
for ((i = 0; i < ${#args[*]}; )); do
|
unlink $fn;
|
||||||
arg=${args[$i]}
|
}
|
||||||
i=$((i + 1))
|
}
|
||||||
case "$arg" in
|
|
||||||
|
|
||||||
--help)
|
sub intHandler {
|
||||||
echo "syntax: $0 [NIX-EXPR...]" >&2
|
exit 1;
|
||||||
exit 0
|
}
|
||||||
;;
|
|
||||||
|
|
||||||
--add-drv-link)
|
$SIG{'INT'} = 'intHandler';
|
||||||
addDrvLink=1
|
|
||||||
;;
|
|
||||||
|
|
||||||
--no-link)
|
|
||||||
addOutLink=0
|
|
||||||
;;
|
|
||||||
|
|
||||||
--attr|-A)
|
|
||||||
arg2=${args[$i]}
|
|
||||||
i=$((i + 1))
|
|
||||||
extraInstArgs="$extraInstArgs $arg $arg2"
|
|
||||||
;;
|
|
||||||
|
|
||||||
-*)
|
|
||||||
extraArgs="$extraArgs $arg"
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
exprs="$exprs $arg"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
if test -z "$exprs"; then
|
for (my $n = 0; $n < scalar @ARGV; $n++) {
|
||||||
exprs="./default.nix"
|
my $arg = $ARGV[$n];
|
||||||
fi
|
|
||||||
|
|
||||||
# Process the specified Nix expressions.
|
if ($arg eq "--help") {
|
||||||
for i in $exprs; do
|
print STDERR "Usage: nix-build [OPTION]... [FILE]...\n";
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
# Instantiate the Nix expression.
|
elsif ($arg eq "--add-drv-link") {
|
||||||
prefix=
|
$addDrvLink = 1;
|
||||||
if test "$addDrvLink" = 0; then prefix=.nix-build-tmp-; fi
|
}
|
||||||
storeExprs=$(@bindir@/nix-instantiate \
|
|
||||||
--add-root ./${prefix}derivation --indirect \
|
|
||||||
$extraInstArgs "$i")
|
|
||||||
|
|
||||||
for j in $storeExprs; do
|
|
||||||
echo "store expression is $(readlink "$j")" >&2
|
|
||||||
done
|
|
||||||
|
|
||||||
# Build the resulting store derivation.
|
elsif ($arg eq "--no-out-link" or $arg eq "--no-link") {
|
||||||
prefix=
|
$addOutLink = 1;
|
||||||
if test "$addOutLink" = 0; then prefix=.nix-build-tmp-; fi
|
}
|
||||||
outPaths=$(@bindir@/nix-store \
|
|
||||||
--add-root ./${prefix}result --indirect \
|
elsif ($arg eq "--attr" or $arg eq "-A") {
|
||||||
-rv $extraArgs $storeExprs)
|
$n++;
|
||||||
|
die "$0: `--attr' requires an argument\n" unless $n < scalar @ARGV;
|
||||||
for j in $outPaths; do
|
push @instArgs, ("--attr", $ARGV[$n]);
|
||||||
echo "$(readlink "$j")"
|
}
|
||||||
done
|
|
||||||
done
|
elsif (substr($arg, 0, 1) eq "-") {
|
||||||
|
push @buildArgs, $arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
push @exprs, $arg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@exprs = ("./default.nix") if scalar @exprs == 0;
|
||||||
|
|
||||||
|
|
||||||
|
foreach my $expr (@exprs) {
|
||||||
|
|
||||||
|
# Instantiate.
|
||||||
|
my $prefix = "";
|
||||||
|
$prefix = ".nix-build-tmp-" if !$addDrvLink;
|
||||||
|
|
||||||
|
my $drvPaths = `@bindir@/nix-instantiate --add-root ./${prefix}derivation --indirect @instArgs "$expr"`;
|
||||||
|
my @drvPaths = split ' ', $drvPaths;
|
||||||
|
|
||||||
|
foreach my $drvPath (@drvPaths) {
|
||||||
|
my $target = readlink $drvPath;
|
||||||
|
print STDERR "store derivation is $target\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
# Build.
|
||||||
|
$prefix = "";
|
||||||
|
$prefix = ".nix-build-tmp-" if !$addOutLink;
|
||||||
|
|
||||||
|
my $outPaths = `@bindir@/nix-store --add-root ./${prefix}result --indirect -rv @buildArgs @drvPaths`;
|
||||||
|
my @outPaths = split ' ', $outPaths;
|
||||||
|
|
||||||
|
foreach my $outPath (@outPaths) {
|
||||||
|
my $target = readlink $outPath;
|
||||||
|
print "$target\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue