about summary refs log tree commit diff
path: root/scripts/nix-push.in
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-27T22·16-0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-27T22·16-0400
commit66a3ac6a56cfa70e2ffeb911c1286ba84c2fa048 (patch)
tree9a2d43a70dd358e70f0a7b3dd8c3e51893eef409 /scripts/nix-push.in
parent6ecf4f13f6a71701f77018a852db2bd4bde0bb67 (diff)
Allow a binary cache to declare that it doesn't support "nix-env -qas"
Querying all substitutable paths via "nix-env -qas" is potentially
hard on a server, since it involves sending thousands of HEAD
requests.  So a binary cache must now have a meta-info file named
"nix-cache-info" that specifies whether the server wants this.  It
also specifies the store prefix so that we don't send useless queries
to a binary cache for a different store prefix.
Diffstat (limited to 'scripts/nix-push.in')
-rwxr-xr-xscripts/nix-push.in32
1 files changed, 20 insertions, 12 deletions
diff --git a/scripts/nix-push.in b/scripts/nix-push.in
index 39fdd6da9e39..1edd8e77314b 100755
--- a/scripts/nix-push.in
+++ b/scripts/nix-push.in
@@ -61,7 +61,7 @@ for (my $n = 0; $n < scalar @ARGV; $n++) {
         push @roots, $arg;
     }
 }
-        
+
 showSyntax if !defined $destDir;
 
 $archivesURL = "file://$destDir" unless defined $archivesURL;
@@ -74,12 +74,12 @@ my %storePaths;
 foreach my $path (@roots) {
     die unless $path =~ /^\//;
 
-    # Get all paths referenced by the normalisation of the given 
+    # Get all paths referenced by the normalisation of the given
     # Nix expression.
     my $pid = open(READ,
         "$Nix::Config::binDir/nix-store --query --requisites --force-realise " .
         "--include-outputs '$path'|") or die;
-    
+
     while (<READ>) {
         chomp;
         die "bad: $_" unless /^\//;
@@ -101,10 +101,10 @@ foreach my $storePath (@storePaths) {
     die unless ($storePath =~ /\/[0-9a-z]{32}[^\"\\\$]*$/);
 
     # Construct a Nix expression that creates a Nix archive.
-    my $nixexpr = 
+    my $nixexpr =
         "(import <nix/nar.nix> " .
         "{ storePath = builtins.storePath \"$storePath\"; hashAlgo = \"sha256\"; compressionType = \"$compressionType\"; }) ";
-    
+
     print NIX $nixexpr;
 }
 
@@ -125,7 +125,17 @@ while (<READ>) {
 close READ or die "nix-build failed: $?";
 
 
-# Copy the archives and the corresponding info files.
+# Write the cache info file.
+my $cacheInfoFile = "$destDir/nix-cache-info";
+if (! -e $cacheInfoFile) {
+    open FILE, ">$cacheInfoFile" or die "cannot create $cacheInfoFile: $!";
+    print FILE "StoreDir: $Nix::Config::storeDir\n";
+    print FILE "WantMassQuery: 0\n"; # by default, don't hit this cache for "nix-env -qas"
+    close FILE;
+}
+
+
+# Copy the archives and the corresponding NAR info files.
 print STDERR "copying archives...\n";
 
 my $totalNarSize = 0;
@@ -157,7 +167,7 @@ for (my $n = 0; $n < scalar @storePaths; $n++) {
     }
 
     $totalNarSize += $narSize;
-    
+
     # Get info about the compressed NAR.
     open HASH, "$narDir/nar-compressed-hash" or die "cannot open nar-compressed-hash";
     my $compressedHash = <HASH>;
@@ -170,7 +180,7 @@ for (my $n = 0; $n < scalar @storePaths; $n++) {
     my $narFile = "$narDir/$narName";
     (-f $narFile) or die "NAR file for $storePath not found";
 
-    my $compressedSize = stat($narFile)->size;    
+    my $compressedSize = stat($narFile)->size;
     $totalCompressedSize += $compressedSize;
 
     printf STDERR "%s [%.2f MiB, %.1f%%]\n", $storePath,
@@ -203,7 +213,7 @@ for (my $n = 0; $n < scalar @storePaths; $n++) {
     }
 
     my $pathHash = substr(basename($storePath), 0, 32);
-    
+
     $dst = "$destDir/$pathHash.narinfo";
     if ($force || ! -f $dst) {
         my $tmp = "$destDir/.tmp.$$.$pathHash.narinfo";
@@ -230,6 +240,4 @@ printf STDERR "total compressed size %.2f MiB, %.1f%%\n",
 
 
 # Optionally write a manifest.
-if ($writeManifest) {
-    writeManifest "$destDir/MANIFEST", \%narFiles, \();
-}
+writeManifest "$destDir/MANIFEST", \%narFiles, \() if $writeManifest;