Skip to content

Commit 6b606c2

Browse files
Ma27rhelmot
authored andcommitted
Use BINARY_CACHE_STORE where appropriate
Replaces / Closes NixOS#1352 Consider the following setup: * `store_uri` points to a "special" store, e.g. `s3://` or `file://`. * Hydra runs inside e.g. an nspawn container and exclusively builds on remote systems. Then, build products are never in the nspawn's `/nix/store`. This in turn means that `$MACHINE_LOCAL_STORE->isValidPath` is always `false` (or `0` 🤷) for output paths and thus Hydra wrongly claims that the output got garbage collected. Instead, use the BINARY_CACHE_STORE to look for the availability in the correct store. Everything touching the `drv` rather than the output paths still uses MACHINE_LOCAL_STORE: this is because `hydra-eval-jobs` does `openStore()` on `auto`, so the derivations end up there rather than on the BINARY_CACHE_STORE.
1 parent 250668a commit 6b606c2

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

src/lib/Hydra/Base/Controller/NixChannel.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ sub getChannelData {
2929
my $outputs = {};
3030
foreach my $output (@outputs) {
3131
my $outPath = $output->get_column("outpath");
32-
next if $checkValidity && !$MACHINE_LOCAL_STORE->isValidPath($outPath);
32+
next if $checkValidity && !$BINARY_CACHE_STORE->isValidPath($outPath);
3333
$outputs->{$output->get_column("outname")} = $outPath;
3434
push @storePaths, $outPath;
3535
# Put the system type in the manifest (for top-level

src/lib/Hydra/Controller/Build.pm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ sub build_GET {
8181
# false because `$_->path` will be empty
8282
$c->stash->{available} =
8383
$c->stash->{isLocalStore}
84-
? all { $_->path && $MACHINE_LOCAL_STORE->isValidPath($_->path) } $build->buildoutputs->all
84+
? all { $_->path && $BINARY_CACHE_STORE->isValidPath($_->path) } $build->buildoutputs->all
8585
: 1;
8686
$c->stash->{drvAvailable} = $MACHINE_LOCAL_STORE->isValidPath($build->drvpath);
8787

@@ -310,7 +310,7 @@ sub output : Chained('buildChain') PathPart Args(1) {
310310
error($c, "This build is not finished yet.") unless $build->finished;
311311
my $output = $build->buildoutputs->find({name => $outputName});
312312
notFound($c, "This build has no output named ‘$outputName") unless defined $output;
313-
gone($c, "Output is no longer available.") unless $MACHINE_LOCAL_STORE->isValidPath($output->path);
313+
gone($c, "Output is no longer available.") unless $BINARY_CACHE_STORE->isValidPath($output->path);
314314

315315
$c->response->header('Content-Disposition', "attachment; filename=\"build-${\$build->id}-${\$outputName}.nar.bz2\"");
316316
$c->stash->{current_view} = 'NixNAR';
@@ -427,15 +427,15 @@ sub getDependencyGraph {
427427
};
428428
$$done{$path} = $node;
429429
my @refs;
430-
foreach my $ref ($MACHINE_LOCAL_STORE->queryReferences($path)) {
430+
foreach my $ref ($BINARY_CACHE_STORE->queryReferences($path)) {
431431
next if $ref eq $path;
432432
next unless $runtime || $ref =~ /\.drv$/;
433433
getDependencyGraph($self, $c, $runtime, $done, $ref);
434434
push @refs, $ref;
435435
}
436436
# Show in reverse topological order to flatten the graph.
437437
# Should probably do a proper BFS.
438-
my @sorted = reverse $MACHINE_LOCAL_STORE->topoSortPaths(@refs);
438+
my @sorted = reverse $BINARY_CACHE_STORE->topoSortPaths(@refs);
439439
$node->{refs} = [map { $$done{$_} } @sorted];
440440
}
441441

@@ -463,7 +463,7 @@ sub runtime_deps : Chained('buildChain') PathPart('runtime-deps') {
463463

464464
requireLocalStore($c);
465465

466-
error($c, "Build outputs no longer available.") unless all { $MACHINE_LOCAL_STORE->isValidPath($_) } @outPaths;
466+
error($c, "Build outputs no longer available.") unless all { $BINARY_CACHE_STORE->isValidPath($_) } @outPaths;
467467

468468
my $done = {};
469469
$c->stash->{runtimeGraph} = [ map { getDependencyGraph($self, $c, 1, $done, $_) } @outPaths ];
@@ -483,7 +483,7 @@ sub nix : Chained('buildChain') PathPart('nix') CaptureArgs(0) {
483483
if (isLocalStore) {
484484
foreach my $out ($build->buildoutputs) {
485485
notFound($c, "Path " . $out->path . " is no longer available.")
486-
unless $MACHINE_LOCAL_STORE->isValidPath($out->path);
486+
unless $BINARY_CACHE_STORE->isValidPath($out->path);
487487
}
488488
}
489489

src/lib/Hydra/Controller/Root.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ sub narinfo :Path :Args(StrMatch[NARINFO_REGEX]) {
397397
my ($hash) = $narinfo =~ NARINFO_REGEX;
398398

399399
die("Hash length was not 32") if length($hash) != 32;
400-
my $path = $MACHINE_LOCAL_STORE->queryPathFromHashPart($hash);
400+
my $path = $BINARY_CACHE_STORE->queryPathFromHashPart($hash);
401401

402402
if (!$path) {
403403
$c->response->status(404);

src/lib/Hydra/Helper/Nix.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ our @EXPORT = qw(
4141
restartBuilds
4242
run
4343
$MACHINE_LOCAL_STORE
44+
$BINARY_CACHE_STORE
4445
);
4546

4647
our $MACHINE_LOCAL_STORE = Nix::Store->new();
48+
our $BINARY_CACHE_STORE = Nix::Store->new(getStoreUri());
4749

4850

4951
sub getHydraHome {

0 commit comments

Comments
 (0)