diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-12-05 11:25:38 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-12-05 11:25:38 +0000 |
commit | 06c5a7075d85636ba1fedce1fc5b131cdcffd5f8 (patch) | |
tree | 971cea7feac8925a55b32ac13663cb70433260ad /scripts/nix-pull.in | |
parent | cff6fd22ebfbfdbbda9b30c68cb61e25db718147 (diff) |
* Refactoring: put the manifest-reading code in a separate file.
Diffstat (limited to 'scripts/nix-pull.in')
-rw-r--r-- | scripts/nix-pull.in | 122 |
1 files changed, 35 insertions, 87 deletions
diff --git a/scripts/nix-pull.in b/scripts/nix-pull.in index 86004102d..040ee54c9 100644 --- a/scripts/nix-pull.in +++ b/scripts/nix-pull.in @@ -1,8 +1,9 @@ -#! /usr/bin/perl -w +#! /usr/bin/perl -w -I@libexecdir@/nix use strict; use IPC::Open2; use POSIX qw(tmpnam); +use readmanifest; my $tmpdir; do { $tmpdir = tmpnam(); } @@ -13,93 +14,19 @@ my $conffile = "@sysconfdir@/nix/prebuilts.conf"; #END { unlink $manifest; rmdir $tmpdir; } -my @srcpaths; -my @subs; -my @sucs; -my $fullexpr = "["; - - -sub processURL { +# Obtain URLs either from the command line or from a configuration file. +my %storepaths2urls; +my %urls2hashes; +my %successors; +sub doURL { my $url = shift; - $url =~ s/\/$//; - print "obtaining list of Nix archives at $url...\n"; - - system "wget --cache=off '$url'/MANIFEST -O '$manifest' 2> /dev/null"; # !!! escape - if ($?) { die "`wget' failed"; } - - open MANIFEST, "<$manifest"; - - my $inside = 0; - - my $storepath; - my $narname; - my $hash; - my @preds; - - while (<MANIFEST>) { - chomp; - s/\#.*$//g; - next if (/^$/); - - if (!$inside) { - if (/^\{$/) { - $inside = 1; - undef $storepath; - undef $narname; - undef $hash; - @preds = (); - } - else { die "bad line: $_"; } - } else { - if (/^\}$/) { - $inside = 0; - my $fullurl = "$url/$narname"; -# print "$storepath\n"; - - # Construct a Nix expression that fetches and unpacks a - # Nix archive from the network. - my $fetch = - "(import @datadir@/nix/corepkgs/fetchurl) " . - "{url = $fullurl; 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 @srcpaths, $storepath; - - foreach my $p (@preds) { - push @sucs, $p; - push @sucs, $storepath; - } - - } - elsif (/^\s*StorePath:\s*(\/\S+)\s*$/) { - $storepath = $1; - } - elsif (/^\s*NarName:\s*(\S+)\s*$/) { - $narname = $1; - } - elsif (/^\s*MD5:\s*(\S+)\s*$/) { - $hash = $1; - } - elsif (/^\s*SuccOf:\s*(\/\S+)\s*$/) { - push @preds, $1; - } - else { die "bad line: $_"; } - } - } - - close MANIFEST; + processURL $manifest, $url, \%storepaths2urls, \%urls2hashes, \%successors; } - - -# Obtain URLs either from the command line or from a configuration file. if (scalar @ARGV > 0) { while (@ARGV) { my $url = shift @ARGV; - processURL $url; + doURL $url; } } else { open CONFFILE, "<$conffile"; @@ -107,12 +34,32 @@ if (scalar @ARGV > 0) { chomp; if (/^\s*(\S+)\s*(\#.*)?$/) { my $url = $1; - processURL $url; + doURL $url; } } close CONFFILE; } + +# 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 .= "]"; @@ -123,14 +70,13 @@ my $pid = open2(\*READ, \*WRITE, "nix-instantiate -") or die "cannot run nix-ins print WRITE $fullexpr; close WRITE; my $i = 0; +my %substitutes; while (<READ>) { chomp; die unless /^\//; my $subpath = $_; - die unless ($i < scalar @srcpaths); - my $srcpath = $srcpaths[$i++]; - push @subs, $srcpath; - push @subs, $subpath; + die unless ($i < scalar @storepaths); + $substitutes{$storepaths[$i++]} = $subpath; } waitpid $pid, 0; @@ -139,6 +85,7 @@ $? == 0 or die "nix-instantiate failed"; # Register all substitutes. print STDERR "registering substitutes...\n"; +my @subs = %substitutes; while (scalar @subs > 0) { my $n = scalar @subs; if ($n > 256) { $n = 256 }; @@ -151,6 +98,7 @@ while (scalar @subs > 0) { # Register all successors. print STDERR "registering successors...\n"; +my @sucs = %successors; while (scalar @sucs > 0) { my $n = scalar @sucs; if ($n > 256) { $n = 256 }; |