about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2007-08-10T01·42+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2007-08-10T01·42+0000
commit4695f4edd6925147a59befefce1c66d34bb2d0e4 (patch)
treeeacb5518122c0748abe1080109c9fe4a29d4ece7 /scripts
parent911bc01454fba42b531f3f8dd0781845b045be63 (diff)
* nix-pull: support bzipped manifests: when doing a nix-pull on $url,
  try $url.bz2 first.

Diffstat (limited to 'scripts')
-rw-r--r--scripts/nix-pull.in40
1 files changed, 32 insertions, 8 deletions
diff --git a/scripts/nix-pull.in b/scripts/nix-pull.in
index 1a5338af204d..ff83f2857c9d 100644
--- a/scripts/nix-pull.in
+++ b/scripts/nix-pull.in
@@ -7,8 +7,6 @@ use readmanifest;
 my $tmpDir = tempdir("nix-pull.XXXXXX", CLEANUP => 1, TMPDIR => 1)
     or die "cannot create a temporary directory";
 
-#my $manifest = "$tmpDir/manifest";
-
 my $binDir = $ENV{"NIX_BIN_DIR"};
 $binDir = "@bindir@" unless defined $binDir;
 
@@ -33,16 +31,42 @@ my %patches;
 
 my $skipWrongStore = 0;
 
+sub downloadFile {
+    my $url = shift;
+    $ENV{"PRINT_PATH"} = 1;
+    $ENV{"QUIET"} = 1;
+    my ($dummy, $path) = `@bindir@/nix-prefetch-url '$url'`;
+    chomp $path;
+    return $path;
+}
+
 sub processURL {
     my $url = shift;
 
     $url =~ s/\/$//;
-    print "obtaining list of Nix archives at `$url'...\n";
 
-    $ENV{"PRINT_PATH"} = 1;
-    $ENV{"QUIET"} = 1;
-    my ($dummy, $manifest) = `@bindir@/nix-prefetch-url '$url'`;
-    chomp $manifest;
+    my $manifest;
+
+    # First see if a bzipped manifest is available.
+    if (system("@curl@ --fail --silent --head '$url'.bz2 > /dev/null") == 0) {
+        print "obtaining list of Nix archives at `$url.bz2'...\n";
+        my $bzipped = downloadFile "$url.bz2";
+
+        $manifest = "$tmpDir/MANIFEST";
+
+        system("@bunzip2@ < $bzipped > $manifest") == 0
+            or die "cannot decompress manifest";
+
+        $manifest = (`$binDir/nix-store --add $manifest`
+                     or die "cannot copy $manifest to the store");
+        chomp $manifest;
+    }
+
+    # Otherwise, just get the uncompressed manifest.
+    else {
+        print "obtaining list of Nix archives at `$url'...\n";
+        $manifest = downloadFile $url;
+    }
     
     if (readManifest($manifest, \%narFiles, \%localPaths, \%patches) < 3) {
         die "manifest `$url' is too old (i.e., for Nix <= 0.7)\n";
@@ -68,7 +92,7 @@ sub processURL {
     
     my $finalPath = "$stateDir/manifests/$baseName-$hash.nixmanifest";
     
-    system ("@coreutils@/ln", "-sfn", "$manifest", "$finalPath") == 0
+    system("@coreutils@/ln", "-sfn", "$manifest", "$finalPath") == 0
         or die "cannot link `$finalPath to `$manifest'";
 }