Use "nix cat-store" to serve files from the Nix store

This makes downloading/viewing build results work with binary cache
stores. For good performance, this should be used in conjunction with
ca580bec35,
i.e. you should set store_uri to something like

  s3://my-cache?local-nar-cache=/tmp/nar-cache

to cache NARs between requests.
This commit is contained in:
Eelco Dolstra 2017-10-18 12:48:31 +02:00
parent bc60fccf78
commit 42fbde0383
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -204,8 +204,6 @@ sub download : Chained('buildChain') PathPart {
}
my $storePath = $1;
notFound($c, "File " . $product->path . " does not exist.") unless -e $product->path;
return $c->res->redirect(defaultUriForProduct($self, $c, $product, @path))
if scalar @path == 0 && ($product->name || $product->defaultpath);
@ -221,6 +219,10 @@ sub download : Chained('buildChain') PathPart {
my $path = $product->path;
$path .= "/" . join("/", @path) if scalar @path > 0;
if (isLocalStore) {
notFound($c, "File " . $product->path . " does not exist.") unless -e $product->path;
# Make sure the file is in the Nix store.
$path = checkPath($self, $c, $path);
@ -237,6 +239,12 @@ sub download : Chained('buildChain') PathPart {
$c->serve_static_file($path);
$c->response->headers->last_modified($c->stash->{build}->stoptime);
} else {
$c->stash->{'plain'} = { data => readNixFile($path) };
$c->response->content_type('application/octet-stream');
$c->forward('Hydra::View::Plain');
}
}