forked from lix-project/hydra
Proxy local binary caches via hydra-server
This commit is contained in:
parent
b9afaadfb3
commit
9de336de7c
|
@ -257,21 +257,48 @@ sub serialize : ActionClass('Serialize') { }
|
||||||
sub nar :Local :Args(1) {
|
sub nar :Local :Args(1) {
|
||||||
my ($self, $c, $path) = @_;
|
my ($self, $c, $path) = @_;
|
||||||
|
|
||||||
$path = ($ENV{NIX_STORE_DIR} || "/nix/store")."/$path";
|
die if $path =~ /\//;
|
||||||
|
|
||||||
|
my $storeMode = $c->config->{store_mode} // "direct";
|
||||||
|
|
||||||
|
if ($storeMode eq "s3-binary-cache") {
|
||||||
|
notFound($c, "There is no binary cache here.");
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif ($storeMode eq "local-binary-cache") {
|
||||||
|
my $dir = $c->config->{binary_cache_dir};
|
||||||
|
$c->serve_static_file($dir . "/nar/" . $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
$path = $Nix::Config::storeDir . "/$path";
|
||||||
|
|
||||||
gone($c, "Path " . $path . " is no longer available.") unless isValidPath($path);
|
gone($c, "Path " . $path . " is no longer available.") unless isValidPath($path);
|
||||||
|
|
||||||
$c->stash->{current_view} = 'NixNAR';
|
$c->stash->{current_view} = 'NixNAR';
|
||||||
$c->stash->{storePath} = $path;
|
$c->stash->{storePath} = $path;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sub nix_cache_info :Path('nix-cache-info') :Args(0) {
|
sub nix_cache_info :Path('nix-cache-info') :Args(0) {
|
||||||
my ($self, $c) = @_;
|
my ($self, $c) = @_;
|
||||||
|
|
||||||
|
my $storeMode = $c->config->{store_mode} // "direct";
|
||||||
|
|
||||||
|
if ($storeMode eq "s3-binary-cache") {
|
||||||
|
notFound($c, "There is no binary cache here.");
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif ($storeMode eq "local-binary-cache") {
|
||||||
|
my $dir = $c->config->{binary_cache_dir};
|
||||||
|
$c->serve_static_file($dir . "/nix-cache-info");
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
$c->response->content_type('text/plain');
|
$c->response->content_type('text/plain');
|
||||||
$c->stash->{plain}->{data} =
|
$c->stash->{plain}->{data} =
|
||||||
#"StoreDir: $Nix::Config::storeDir\n" . # FIXME
|
"StoreDir: $Nix::Config::storeDir\n" .
|
||||||
"StoreDir: " . ($ENV{NIX_STORE_DIR} || "/nix/store") . "\n" .
|
|
||||||
"WantMassQuery: 0\n" .
|
"WantMassQuery: 0\n" .
|
||||||
# Give Hydra binary caches a very low priority (lower than the
|
# Give Hydra binary caches a very low priority (lower than the
|
||||||
# static binary cache http://nixos.org/binary-cache).
|
# static binary cache http://nixos.org/binary-cache).
|
||||||
|
@ -279,10 +306,24 @@ sub nix_cache_info :Path('nix-cache-info') :Args(0) {
|
||||||
setCacheHeaders($c, 24 * 60 * 60);
|
setCacheHeaders($c, 24 * 60 * 60);
|
||||||
$c->forward('Hydra::View::Plain');
|
$c->forward('Hydra::View::Plain');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sub narinfo :LocalRegex('^([a-z0-9]+).narinfo$') :Args(0) {
|
sub narinfo :LocalRegex('^([a-z0-9]+).narinfo$') :Args(0) {
|
||||||
my ($self, $c) = @_;
|
my ($self, $c) = @_;
|
||||||
|
|
||||||
|
my $storeMode = $c->config->{store_mode} // "direct";
|
||||||
|
|
||||||
|
if ($storeMode eq "s3-binary-cache") {
|
||||||
|
notFound($c, "There is no binary cache here.");
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif ($storeMode eq "local-binary-cache") {
|
||||||
|
my $dir = $c->config->{binary_cache_dir};
|
||||||
|
$c->serve_static_file($dir . "/" . $c->req->captures->[0] . ".narinfo");
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
my $hash = $c->req->captures->[0];
|
my $hash = $c->req->captures->[0];
|
||||||
|
|
||||||
die if length($hash) != 32;
|
die if length($hash) != 32;
|
||||||
|
@ -300,6 +341,7 @@ sub narinfo :LocalRegex('^([a-z0-9]+).narinfo$') :Args(0) {
|
||||||
$c->stash->{storePath} = $path;
|
$c->stash->{storePath} = $path;
|
||||||
$c->forward('Hydra::View::NARInfo');
|
$c->forward('Hydra::View::NARInfo');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sub logo :Local {
|
sub logo :Local {
|
||||||
|
|
Loading…
Reference in a new issue