aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2017-04-30 18:07:48 +0300
committerIgor Pashev <pashev.igor@gmail.com>2017-04-30 18:07:48 +0300
commitc8fe05f1c72412c2f1fd5f1adc9989eab4fc0d50 (patch)
tree475e4589198bcf25b8342e152ba18573937f534e
parent3a3cf815c149878db36e57561f5462b060f2110c (diff)
downloadnixsap-c8fe05f1c72412c2f1fd5f1adc9989eab4fc0d50.tar.gz
nix-serve: do not compress when NAR size < 1 KiB
-rw-r--r--modules/pkgs/nix-serve/nix-serve.psgi26
1 files changed, 22 insertions, 4 deletions
diff --git a/modules/pkgs/nix-serve/nix-serve.psgi b/modules/pkgs/nix-serve/nix-serve.psgi
index ac4071b..696f752 100644
--- a/modules/pkgs/nix-serve/nix-serve.psgi
+++ b/modules/pkgs/nix-serve/nix-serve.psgi
@@ -19,15 +19,24 @@ my $app = sub {
return [200, ['Content-Type' => 'text/plain'], ["StoreDir: $Nix::Config::storeDir\nWantMassQuery: 1\nPriority: 30\n"]];
}
- elsif ($path =~ "/([0-9a-z]+)\.narinfo") {
+ elsif ($path =~ '/([0-9a-z]+)\.narinfo$') {
my $hashPart = $1;
my $storePath = queryPathFromHashPart($hashPart);
return [404, ['Content-Type' => 'text/plain'], ["No such path.\n"]] unless $storePath;
my ($deriver, $narHash, $time, $narSize, $refs) = queryPathInfo($storePath, 1) or die;
+ my $compression;
+ my $ext;
+ if ($narSize < 1024) {
+ $compression = 'none';
+ $ext = '';
+ } else {
+ $compression = 'xz';
+ $ext = '.xz';
+ }
my $res =
"StorePath: $storePath\n" .
- "URL: nar/$hashPart.nar.xz\n" .
- "Compression: xz\n" .
+ "URL: nar/$hashPart.nar$ext\n" .
+ "Compression: $compression\n" .
"NarHash: $narHash\n" .
"NarSize: $narSize\n";
$res .= "References: " . join(" ", map { stripPath($_) } @$refs) . "\n"
@@ -46,7 +55,7 @@ my $app = sub {
return [200, ['Content-Type' => 'text/x-nix-narinfo'], [$res]];
}
- elsif ($path =~ "/nar/([0-9a-z]+)\.nar.xz") {
+ elsif ($path =~ '/nar/([0-9a-z]+)\.nar.xz$') {
my $hashPart = $1;
my $storePath = queryPathFromHashPart($hashPart);
return [404, ['Content-Type' => 'text/plain'], ["No such path.\n"]] unless $storePath;
@@ -55,6 +64,15 @@ my $app = sub {
return [200, ['Content-Type' => 'application/x-xz'], $fh];
}
+ elsif ($path =~ '/nar/([0-9a-z]+)\.nar$') {
+ my $hashPart = $1;
+ my $storePath = queryPathFromHashPart($hashPart);
+ return [404, ['Content-Type' => 'text/plain'], ["No such path.\n"]] unless $storePath;
+ my $fh = new IO::Handle;
+ open $fh, "nix-store --dump '$storePath' |";
+ return [200, ['Content-Type' => 'application/octet-stream'], $fh];
+ }
+
else {
return [404, ['Content-Type' => 'text/plain'], ["File not found.\n"]];
}