diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm index 2bad203f..d608e085 100644 --- a/src/lib/Hydra/Helper/AddBuilds.pm +++ b/src/lib/Hydra/Helper/AddBuilds.pm @@ -68,7 +68,7 @@ sub handleDeclarativeJobsetBuild { my $id = $build->id; die "Declarative jobset build $id failed" unless $build->buildstatus == 0; my $declPath = ($build->buildoutputs)[0]->path; - my $declText = read_file($declPath) + my $declText = readNixFile($declPath) or die "Couldn't read declarative specification file $declPath: $!"; my $declSpec = decode_json($declText); txn_do($db, sub { diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm index 1879ceba..ee06e142 100644 --- a/src/lib/Hydra/Helper/Nix.pm +++ b/src/lib/Hydra/Helper/Nix.pm @@ -23,7 +23,7 @@ our @EXPORT = qw( getEvals getMachines pathIsInsidePrefix captureStdoutStderr run grab - getTotalShares + getTotalShares readNixFile cancelBuilds restartBuilds); @@ -390,7 +390,18 @@ sub run { my @x = ($args{cmd}, \$stdin, \$res->{stdout}); push @x, \$res->{stderr} if $args{grabStderr} // 1; IPC::Run::run(@x, - init => sub { chdir $args{dir} or die "changing to $args{dir}" if defined $args{dir}; }); + init => sub { + chdir $args{dir} or die "changing to $args{dir}" if defined $args{dir}; + if (defined $args{env}) { + foreach my $key (keys %{$args{env}}) { + if (defined $args{env}->{$key}) { + $ENV{$key} = $args{env}->{$key}; + } else { + delete $ENV{$key}; + } + } + } + }); alarm 0; }; @@ -479,4 +490,13 @@ sub restartBuilds($$) { } +# Read a file from the (possibly remote) nix store +sub readNixFile { + my ($path) = @_; + my $config = getHydraConfig(); + my $storeUri = $config->{'store_uri'} // ""; + return grab(cmd => ["nix", "cat-store", "$path"], env => { NIX_REMOTE => "$storeUri" }); +} + + 1;