Skip to content

Commit

Permalink
Add realisations to binary cache for ca-derivations
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Dec 4, 2023
1 parent c257abe commit 9e528b2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/lib/Hydra/Controller/Root.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use Net::Prometheus;
use Types::Standard qw/StrMatch/;

use constant NARINFO_REGEX => qr{^([a-z0-9]{32})\.narinfo$};
# e.g.: https://hydra.example.com/realisations/sha256:a62128132508a3a32eef651d6467695944763602f226ac630543e947d9feb140!out.doi
use constant REALISATIONS_REGEX => qr{^(sha256:[a-z0-9]{64}![a-z]+)\.doi$};

# Put this controller at top-level.
__PACKAGE__->config->{namespace} = '';
Expand Down Expand Up @@ -355,6 +357,33 @@ sub nix_cache_info :Path('nix-cache-info') :Args(0) {
}


sub realisations :Path('realisations') :Args(StrMatch[REALISATIONS_REGEX]) {
my ($self, $c, $realisation) = @_;

if (!isLocalStore) {
notFound($c, "There is no binary cache here.");
}

else {
my ($rawDrvOutput) = $realisation =~ REALISATIONS_REGEX;
my $rawRealisation = queryRawRealisation($rawDrvOutput);

if (!$rawRealisation) {
$c->response->status(404);
$c->response->content_type('text/plain');
$c->stash->{plain}->{data} = "does not exist\n";
$c->forward('Hydra::View::Plain');
setCacheHeaders($c, 60 * 60);
return;
}

$c->response->content_type('text/plain');
$c->stash->{plain}->{data} = $rawRealisation;
$c->forward('Hydra::View::Plain');
}
}


sub narinfo :Path :Args(StrMatch[NARINFO_REGEX]) {
my ($self, $c, $narinfo) = @_;

Expand Down

0 comments on commit 9e528b2

Please sign in to comment.