From 37ee6cef992c1a80e790a294b75db8c116be8bbb Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 21 Jun 2004 09:51:23 +0000 Subject: [PATCH] * Adapted nix-pull to use the new substitute mechanism. --- configure.ac | 1 + corepkgs/Makefile.am | 2 +- corepkgs/nix-pull/Makefile.am | 11 +++++ corepkgs/nix-pull/builder.sh.in | 34 ++++++++++++++ corepkgs/nix-pull/default.nix | 7 +++ scripts/nix-prefetch-url.in | 8 +++- scripts/nix-pull.in | 82 +++++++++++++-------------------- scripts/readmanifest.pm.in | 12 ++--- 8 files changed, 99 insertions(+), 58 deletions(-) create mode 100644 corepkgs/nix-pull/Makefile.am create mode 100644 corepkgs/nix-pull/builder.sh.in create mode 100644 corepkgs/nix-pull/default.nix diff --git a/configure.ac b/configure.ac index 4b221bf31..851375194 100644 --- a/configure.ac +++ b/configure.ac @@ -152,6 +152,7 @@ AC_CONFIG_FILES([Makefile corepkgs/nar/Makefile corepkgs/buildenv/Makefile corepkgs/channels/Makefile + corepkgs/nix-pull/Makefile doc/Makefile doc/manual/Makefile misc/Makefile diff --git a/corepkgs/Makefile.am b/corepkgs/Makefile.am index c9ea11cef..ca4cea2fc 100644 --- a/corepkgs/Makefile.am +++ b/corepkgs/Makefile.am @@ -1 +1 @@ -SUBDIRS = fetchurl nar buildenv channels +SUBDIRS = fetchurl nar buildenv channels nix-pull diff --git a/corepkgs/nix-pull/Makefile.am b/corepkgs/nix-pull/Makefile.am new file mode 100644 index 000000000..91adb4853 --- /dev/null +++ b/corepkgs/nix-pull/Makefile.am @@ -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 diff --git a/corepkgs/nix-pull/builder.sh.in b/corepkgs/nix-pull/builder.sh.in new file mode 100644 index 000000000..cc1a125d8 --- /dev/null +++ b/corepkgs/nix-pull/builder.sh.in @@ -0,0 +1,34 @@ +#! @shell@ -e + +export PATH=/bin:/usr/bin + +mkdir $out + +cat > $out/fetch <&2 rm -rf $tmpPath2 || true echo $hash + +if test -n "$PRINT_PATH"; then + echo $finalPath +fi diff --git a/scripts/nix-pull.in b/scripts/nix-pull.in index 6472c7c64..a802760a5 100644 --- a/scripts/nix-pull.in +++ b/scripts/nix-pull.in @@ -10,18 +10,18 @@ do { $tmpdir = tmpnam(); } until mkdir $tmpdir, 0777; my $manifest = "$tmpdir/manifest"; -my $conffile = "@sysconfdir@/nix/prebuilts.conf"; +my $confFile = "@sysconfdir@/nix/prebuilts.conf"; #END { unlink $manifest; rmdir $tmpdir; } # Obtain URLs either from the command line or from a configuration file. -my %storepaths2urls; +my %storePaths2urls; my %urls2hashes; my %successors; sub doURL { my $url = shift; - processURL $manifest, $url, \%storepaths2urls, \%urls2hashes, \%successors; + processURL $manifest, $url, \%storePaths2urls, \%urls2hashes, \%successors; } if (scalar @ARGV > 0) { while (@ARGV) { @@ -29,7 +29,7 @@ if (scalar @ARGV > 0) { doURL $url; } } else { - open CONFFILE, "<$conffile"; + open CONFFILE, "<$confFile"; while () { chomp; if (/^\s*(\S+)\s*(\#.*)?$/) { @@ -41,60 +41,44 @@ if (scalar @ARGV > 0) { } -# Create a Nix expression for the substitutes. -my $fullexpr = "["; - -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 .= "]"; +my $size = scalar (keys %storePaths2urls); +print "$size store paths in manifest\n"; -# Instantiate store expressions from the Nix expressions we created above. -print STDERR "instantiating store expressions...\n"; -my $pid = open2(\*READ, \*WRITE, "@bindir@/nix-instantiate -") or die "cannot run nix-instantiate"; +# Instantiate a store expression that builds the substitute program +# (the program that fetches URLs and unpacks them into the store). +my $nixExpr = + "(import @datadir@/nix/corepkgs/nix-pull) " . + "{system = \"@system@\";}"; -print WRITE $fullexpr; -close WRITE; -my $i = 0; -my %substitutes; -while () { - chomp; - die unless /^\//; - my $subpath = $_; - die unless ($i < scalar @storepaths); - $substitutes{$storepaths[$i++]} = $subpath; -} - -waitpid $pid, 0; -$? == 0 or die "nix-instantiate failed"; +print STDERR "instantiating store expression...\n"; +my $storeExpr = `echo '$nixExpr' | @bindir@/nix-instantiate -` + or die "cannot instantiate Nix expression"; +chomp $storeExpr; # Register all substitutes. print STDERR "registering substitutes...\n"; -my @subs = %substitutes; -while (scalar @subs > 0) { - my $n = scalar @subs; - if ($n > 256) { $n = 256 }; - my @subs2 = @subs[0..$n - 1]; - @subs = @subs[$n..scalar @subs - 1]; - system "@bindir@/nix-store --substitute @subs2"; - if ($?) { die "`nix-store --substitute' failed"; } + +my $pid = open2(\*READ, \*WRITE, "@bindir@/nix-store --substitute") + or die "cannot run nix-store"; + +close READ; + +foreach my $storePath (keys %storePaths2urls) { + 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. print STDERR "registering successors...\n"; diff --git a/scripts/readmanifest.pm.in b/scripts/readmanifest.pm.in index bca6c4c8a..3bda0f067 100644 --- a/scripts/readmanifest.pm.in +++ b/scripts/readmanifest.pm.in @@ -3,7 +3,7 @@ use strict; sub processURL { my $manifest = shift; my $url = shift; - my $storepaths2urls = shift; + my $storePaths2urls = shift; my $urls2hashes = shift; my $successors = shift; @@ -18,7 +18,7 @@ sub processURL { my $inside = 0; - my $storepath; + my $storePath; my $narurl; my $hash; my @preds; @@ -31,7 +31,7 @@ sub processURL { if (!$inside) { if (/^\{$/) { $inside = 1; - undef $storepath; + undef $storePath; undef $narurl; undef $hash; @preds = (); @@ -41,16 +41,16 @@ sub processURL { if (/^\}$/) { $inside = 0; - $$storepaths2urls{$storepath} = $narurl; + $$storePaths2urls{$storePath} = $narurl; $$urls2hashes{$narurl} = $hash; foreach my $p (@preds) { - $$successors{$p} = $storepath; + $$successors{$p} = $storePath; } } elsif (/^\s*StorePath:\s*(\/\S+)\s*$/) { - $storepath = $1; + $storePath = $1; } elsif (/^\s*NarURL:\s*(\S+)\s*$/) { $narurl = $1;