1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-06 21:41:48 +02:00

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.
This commit is contained in:
Eelco Dolstra 2012-07-27 18:16:05 -04:00
parent 6ecf4f13f6
commit 66a3ac6a56
3 changed files with 135 additions and 86 deletions

View file

@ -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;