Skip to content

Commit

Permalink
Build: use nix path-info to test for build output availability
Browse files Browse the repository at this point in the history
When using the Perl bindings, this usually takes the wrong store, i.e.
`auto` even if `store_uri` is a flat-file binary cache.

See also NixOS/nix#9859

Using fork/exec here on purpose to make sure that the output of `nix path-info`
isn't spammed into stderr. This could probably done with
`system("foo &>/dev/null")`, but I didn't want to worry about shell
injection issues then. And finally, I can't seem to silence STDERR for
`system` with a list as argument. Not a Perl dev though, so not sure if
there's a better way.
  • Loading branch information
Ma27 committed Jan 26, 2024
1 parent cfcd6b6 commit 1d1ec0b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/lib/Hydra/Controller/Build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ sub findBuildStepByDrvPath {

sub build :Chained('buildChain') :PathPart('') :Args(0) :ActionClass('REST') { }

sub isValidPathNixCLI {
my $path = shift;
my $pid = fork();
if (!$pid) {
open STDERR, ">", "/dev/null";
exec "nix", "path-info", $path, "--store", getStoreUri();
}
waitpid $pid, 0;
return $? == 0;
}

sub build_GET {
my ($self, $c) = @_;

Expand All @@ -83,7 +94,7 @@ sub build_GET {
$c->stash->{isLocalStore} = isLocalStore();
$c->stash->{available} =
$c->stash->{isLocalStore}
? all { isValidPath($_->path) } $build->buildoutputs->all
? all { isValidPathNixCLI($_->path) } $build->buildoutputs->all
: 1;
$c->stash->{drvAvailable} = isValidPath $build->drvpath;

Expand Down

0 comments on commit 1d1ec0b

Please sign in to comment.