forked from lix-project/lix
* Adapted nix-pull to use the new substitute mechanism.
This commit is contained in:
parent
3f3a3ae87b
commit
37ee6cef99
|
@ -152,6 +152,7 @@ AC_CONFIG_FILES([Makefile
|
||||||
corepkgs/nar/Makefile
|
corepkgs/nar/Makefile
|
||||||
corepkgs/buildenv/Makefile
|
corepkgs/buildenv/Makefile
|
||||||
corepkgs/channels/Makefile
|
corepkgs/channels/Makefile
|
||||||
|
corepkgs/nix-pull/Makefile
|
||||||
doc/Makefile
|
doc/Makefile
|
||||||
doc/manual/Makefile
|
doc/manual/Makefile
|
||||||
misc/Makefile
|
misc/Makefile
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
SUBDIRS = fetchurl nar buildenv channels
|
SUBDIRS = fetchurl nar buildenv channels nix-pull
|
||||||
|
|
11
corepkgs/nix-pull/Makefile.am
Normal file
11
corepkgs/nix-pull/Makefile.am
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
all-local: builder.sh
|
||||||
|
|
||||||
|
install-exec-local:
|
||||||
|
$(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs
|
||||||
|
$(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs/nix-pull
|
||||||
|
$(INSTALL_DATA) default.nix $(DESTDIR)$(datadir)/nix/corepkgs/nix-pull
|
||||||
|
$(INSTALL_PROGRAM) builder.sh $(DESTDIR)$(datadir)/nix/corepkgs/nix-pull
|
||||||
|
|
||||||
|
include ../../substitute.mk
|
||||||
|
|
||||||
|
EXTRA_DIST = default.nix builder.sh.in
|
34
corepkgs/nix-pull/builder.sh.in
Normal file
34
corepkgs/nix-pull/builder.sh.in
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#! @shell@ -e
|
||||||
|
|
||||||
|
export PATH=/bin:/usr/bin
|
||||||
|
|
||||||
|
mkdir $out
|
||||||
|
|
||||||
|
cat > $out/fetch <<EOF
|
||||||
|
#! @shell@ -e
|
||||||
|
|
||||||
|
export PATH=/bin:/usr/bin
|
||||||
|
|
||||||
|
echo "downloading \$2..."
|
||||||
|
|
||||||
|
export PRINT_PATH=1
|
||||||
|
result=(\$(@bindir@/nix-prefetch-url \$2))
|
||||||
|
|
||||||
|
hash=\${result[0]}
|
||||||
|
path=\${result[1]}
|
||||||
|
|
||||||
|
if test "\$hash" != "\$3"; then
|
||||||
|
echo "hash is \$hash, expected \$3"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "unpacking into \$1..."
|
||||||
|
|
||||||
|
if ! @bunzip2@ < "\$path" | @bindir@/nix-store --restore "\$1"; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
EOF
|
||||||
|
|
||||||
|
chmod +x $out/fetch
|
7
corepkgs/nix-pull/default.nix
Normal file
7
corepkgs/nix-pull/default.nix
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{system}:
|
||||||
|
|
||||||
|
derivation {
|
||||||
|
name = "nix-pull";
|
||||||
|
builder = ./builder.sh;
|
||||||
|
inherit system;
|
||||||
|
}
|
|
@ -25,13 +25,17 @@ test -e $tmpPath2 || mv $tmpPath1 $tmpPath2 # !!! race
|
||||||
storeExpr=$( \
|
storeExpr=$( \
|
||||||
echo "(import @datadir@/nix/corepkgs/fetchurl) \
|
echo "(import @datadir@/nix/corepkgs/fetchurl) \
|
||||||
{url = $url; md5 = \"$hash\"; system = \"@system@\";}" \
|
{url = $url; md5 = \"$hash\"; system = \"@system@\";}" \
|
||||||
| nix-instantiate -)
|
| @bindir@/nix-instantiate -)
|
||||||
|
|
||||||
# Realise it.
|
# Realise it.
|
||||||
finalPath=$(nix-store -qnB --force-realise $storeExpr)
|
finalPath=$(@bindir@/nix-store -qnB --force-realise $storeExpr)
|
||||||
|
|
||||||
echo "path is $finalPath" >&2
|
echo "path is $finalPath" >&2
|
||||||
|
|
||||||
rm -rf $tmpPath2 || true
|
rm -rf $tmpPath2 || true
|
||||||
|
|
||||||
echo $hash
|
echo $hash
|
||||||
|
|
||||||
|
if test -n "$PRINT_PATH"; then
|
||||||
|
echo $finalPath
|
||||||
|
fi
|
||||||
|
|
|
@ -10,18 +10,18 @@ do { $tmpdir = tmpnam(); }
|
||||||
until mkdir $tmpdir, 0777;
|
until mkdir $tmpdir, 0777;
|
||||||
|
|
||||||
my $manifest = "$tmpdir/manifest";
|
my $manifest = "$tmpdir/manifest";
|
||||||
my $conffile = "@sysconfdir@/nix/prebuilts.conf";
|
my $confFile = "@sysconfdir@/nix/prebuilts.conf";
|
||||||
|
|
||||||
#END { unlink $manifest; rmdir $tmpdir; }
|
#END { unlink $manifest; rmdir $tmpdir; }
|
||||||
|
|
||||||
|
|
||||||
# Obtain URLs either from the command line or from a configuration file.
|
# Obtain URLs either from the command line or from a configuration file.
|
||||||
my %storepaths2urls;
|
my %storePaths2urls;
|
||||||
my %urls2hashes;
|
my %urls2hashes;
|
||||||
my %successors;
|
my %successors;
|
||||||
sub doURL {
|
sub doURL {
|
||||||
my $url = shift;
|
my $url = shift;
|
||||||
processURL $manifest, $url, \%storepaths2urls, \%urls2hashes, \%successors;
|
processURL $manifest, $url, \%storePaths2urls, \%urls2hashes, \%successors;
|
||||||
}
|
}
|
||||||
if (scalar @ARGV > 0) {
|
if (scalar @ARGV > 0) {
|
||||||
while (@ARGV) {
|
while (@ARGV) {
|
||||||
|
@ -29,7 +29,7 @@ if (scalar @ARGV > 0) {
|
||||||
doURL $url;
|
doURL $url;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
open CONFFILE, "<$conffile";
|
open CONFFILE, "<$confFile";
|
||||||
while (<CONFFILE>) {
|
while (<CONFFILE>) {
|
||||||
chomp;
|
chomp;
|
||||||
if (/^\s*(\S+)\s*(\#.*)?$/) {
|
if (/^\s*(\S+)\s*(\#.*)?$/) {
|
||||||
|
@ -41,60 +41,44 @@ if (scalar @ARGV > 0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Create a Nix expression for the substitutes.
|
my $size = scalar (keys %storePaths2urls);
|
||||||
my $fullexpr = "[";
|
print "$size store paths in manifest\n";
|
||||||
|
|
||||||
my @storepaths;
|
|
||||||
foreach my $storepath (keys %storepaths2urls) {
|
|
||||||
# Construct a Nix expression that fetches and unpacks a
|
|
||||||
# Nix archive from the network.
|
|
||||||
my $url = $storepaths2urls{$storepath};
|
|
||||||
my $hash = $urls2hashes{$url};
|
|
||||||
my $fetch =
|
|
||||||
"(import @datadir@/nix/corepkgs/fetchurl) " .
|
|
||||||
"{url = $url; md5 = \"$hash\"; system = \"@system@\";}";
|
|
||||||
my $nixexpr =
|
|
||||||
"((import @datadir@/nix/corepkgs/nar/unnar.nix) " .
|
|
||||||
"{narFile = ($fetch); outPath = \"$storepath\"; system = \"@system@\";}) ";
|
|
||||||
$fullexpr .= $nixexpr; # !!! O(n^2)?
|
|
||||||
push @storepaths, $storepath;
|
|
||||||
}
|
|
||||||
|
|
||||||
$fullexpr .= "]";
|
|
||||||
|
|
||||||
|
|
||||||
# Instantiate store expressions from the Nix expressions we created above.
|
# Instantiate a store expression that builds the substitute program
|
||||||
print STDERR "instantiating store expressions...\n";
|
# (the program that fetches URLs and unpacks them into the store).
|
||||||
my $pid = open2(\*READ, \*WRITE, "@bindir@/nix-instantiate -") or die "cannot run nix-instantiate";
|
my $nixExpr =
|
||||||
|
"(import @datadir@/nix/corepkgs/nix-pull) " .
|
||||||
|
"{system = \"@system@\";}";
|
||||||
|
|
||||||
print WRITE $fullexpr;
|
print STDERR "instantiating store expression...\n";
|
||||||
close WRITE;
|
my $storeExpr = `echo '$nixExpr' | @bindir@/nix-instantiate -`
|
||||||
my $i = 0;
|
or die "cannot instantiate Nix expression";
|
||||||
my %substitutes;
|
chomp $storeExpr;
|
||||||
while (<READ>) {
|
|
||||||
chomp;
|
|
||||||
die unless /^\//;
|
|
||||||
my $subpath = $_;
|
|
||||||
die unless ($i < scalar @storepaths);
|
|
||||||
$substitutes{$storepaths[$i++]} = $subpath;
|
|
||||||
}
|
|
||||||
|
|
||||||
waitpid $pid, 0;
|
|
||||||
$? == 0 or die "nix-instantiate failed";
|
|
||||||
|
|
||||||
|
|
||||||
# Register all substitutes.
|
# Register all substitutes.
|
||||||
print STDERR "registering substitutes...\n";
|
print STDERR "registering substitutes...\n";
|
||||||
my @subs = %substitutes;
|
|
||||||
while (scalar @subs > 0) {
|
my $pid = open2(\*READ, \*WRITE, "@bindir@/nix-store --substitute")
|
||||||
my $n = scalar @subs;
|
or die "cannot run nix-store";
|
||||||
if ($n > 256) { $n = 256 };
|
|
||||||
my @subs2 = @subs[0..$n - 1];
|
close READ;
|
||||||
@subs = @subs[$n..scalar @subs - 1];
|
|
||||||
system "@bindir@/nix-store --substitute @subs2";
|
foreach my $storePath (keys %storePaths2urls) {
|
||||||
if ($?) { die "`nix-store --substitute' failed"; }
|
print WRITE "$storePath\n";
|
||||||
|
print WRITE "$storeExpr\n";
|
||||||
|
print WRITE "/fetch\n";
|
||||||
|
print WRITE "2\n";
|
||||||
|
print WRITE "$storePaths2urls{$storePath}\n";
|
||||||
|
print WRITE "$urls2hashes{$storePaths2urls{$storePath}}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close WRITE;
|
||||||
|
|
||||||
|
waitpid $pid, 0;
|
||||||
|
$? == 0 or die "nix-store failed";
|
||||||
|
|
||||||
|
|
||||||
# Register all successors.
|
# Register all successors.
|
||||||
print STDERR "registering successors...\n";
|
print STDERR "registering successors...\n";
|
||||||
|
|
|
@ -3,7 +3,7 @@ use strict;
|
||||||
sub processURL {
|
sub processURL {
|
||||||
my $manifest = shift;
|
my $manifest = shift;
|
||||||
my $url = shift;
|
my $url = shift;
|
||||||
my $storepaths2urls = shift;
|
my $storePaths2urls = shift;
|
||||||
my $urls2hashes = shift;
|
my $urls2hashes = shift;
|
||||||
my $successors = shift;
|
my $successors = shift;
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ sub processURL {
|
||||||
|
|
||||||
my $inside = 0;
|
my $inside = 0;
|
||||||
|
|
||||||
my $storepath;
|
my $storePath;
|
||||||
my $narurl;
|
my $narurl;
|
||||||
my $hash;
|
my $hash;
|
||||||
my @preds;
|
my @preds;
|
||||||
|
@ -31,7 +31,7 @@ sub processURL {
|
||||||
if (!$inside) {
|
if (!$inside) {
|
||||||
if (/^\{$/) {
|
if (/^\{$/) {
|
||||||
$inside = 1;
|
$inside = 1;
|
||||||
undef $storepath;
|
undef $storePath;
|
||||||
undef $narurl;
|
undef $narurl;
|
||||||
undef $hash;
|
undef $hash;
|
||||||
@preds = ();
|
@preds = ();
|
||||||
|
@ -41,16 +41,16 @@ sub processURL {
|
||||||
if (/^\}$/) {
|
if (/^\}$/) {
|
||||||
$inside = 0;
|
$inside = 0;
|
||||||
|
|
||||||
$$storepaths2urls{$storepath} = $narurl;
|
$$storePaths2urls{$storePath} = $narurl;
|
||||||
$$urls2hashes{$narurl} = $hash;
|
$$urls2hashes{$narurl} = $hash;
|
||||||
|
|
||||||
foreach my $p (@preds) {
|
foreach my $p (@preds) {
|
||||||
$$successors{$p} = $storepath;
|
$$successors{$p} = $storePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
elsif (/^\s*StorePath:\s*(\/\S+)\s*$/) {
|
elsif (/^\s*StorePath:\s*(\/\S+)\s*$/) {
|
||||||
$storepath = $1;
|
$storePath = $1;
|
||||||
}
|
}
|
||||||
elsif (/^\s*NarURL:\s*(\S+)\s*$/) {
|
elsif (/^\s*NarURL:\s*(\S+)\s*$/) {
|
||||||
$narurl = $1;
|
$narurl = $1;
|
||||||
|
|
Loading…
Reference in a new issue