Skip to content

Commit 278dcd2

Browse files
committed
hydra-eval-jobset: allow attributes other than checks/hydraJobs
1 parent 8481acd commit 278dcd2

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

src/script/hydra-eval-jobset

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,24 @@ sub evalJobs {
358358
my @cmd;
359359

360360
if (defined $flakeRef) {
361-
my $nix_expr =
362-
"let " .
363-
"flake = builtins.getFlake (toString \"$flakeRef\"); " .
364-
"in " .
365-
"flake.hydraJobs " .
366-
"or flake.checks " .
367-
"or (throw \"flake '$flakeRef' does not provide any Hydra jobs or checks\")";
361+
my $nix_expr;
362+
my ($ref, $attr) = split '#', $flakeRef, 2;
363+
if (defined $attr) {
364+
$nix_expr =
365+
"let " .
366+
"flake = builtins.getFlake (toString \"$ref\"); " .
367+
"in " .
368+
"flake.${attr} " .
369+
"or (throw \"flake '$ref' does not provide attribute '$attr'\")";
370+
} else {
371+
$nix_expr =
372+
"let " .
373+
"flake = builtins.getFlake (toString \"$flakeRef\"); " .
374+
"in " .
375+
"flake.hydraJobs " .
376+
"or flake.checks " .
377+
"or (throw \"flake '$flakeRef' does not provide any Hydra jobs or checks\")";
378+
}
368379

369380
@cmd = ("nix-eval-jobs",
370381
# Disable the eval cache to prevent SQLite database contention.
@@ -713,12 +724,13 @@ sub checkJobsetWrapped {
713724

714725
my $flakeRef = $jobset->flake;
715726
if (defined $flakeRef) {
727+
my ($ref, $attr) = split '#', $flakeRef, 2;
716728
(my $res, my $json, my $stderr) = captureStdoutStderr(
717-
600, "nix", "flake", "metadata", "--refresh", "--json", "--", $flakeRef);
729+
600, "nix", "flake", "metadata", "--refresh", "--json", "--", $ref);
718730
die "'nix flake metadata' returned " . ($res & 127 ? "signal $res" : "exit code " . ($res >> 8))
719731
. ":\n" . ($stderr ? decode("utf-8", $stderr) : "(no output)\n")
720732
if $res;
721-
$flakeRef = decode_json($json)->{'url'};
733+
$ref = decode_json($json)->{'url'};
722734
}
723735

724736
Net::Statsd::increment("hydra.evaluator.checkouts");

t/evaluator/evaluate-flake.t

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ my $ctx = test_context(
1717
);
1818

1919
sub checkFlake {
20-
my ($flake) = @_;
20+
my ($input) = @_;
21+
my ($flake, $attr) = split '#', $input, 2;
2122

2223
cp($ctx->jobsdir . "/basic.nix", $ctx->jobsdir . "/" . $flake);
2324
cp($ctx->jobsdir . "/config.nix", $ctx->jobsdir . "/" . $flake);
@@ -30,7 +31,7 @@ sub checkFlake {
3031
chmod 0755, $ctx->jobsdir . "/" . $flake . "/succeed-with-failed.sh";
3132

3233
my $builds = $ctx->makeAndEvaluateJobset(
33-
flake => 'path:' . $ctx->jobsdir . "/" . $flake,
34+
flake => 'path:' . $ctx->jobsdir . "/" . $input,
3435
build => 1
3536
);
3637

@@ -64,4 +65,12 @@ subtest "Flake using `hydraJobs`" => sub {
6465
checkFlake 'flake-hydraJobs'
6566
};
6667

68+
subtest "Flake using explict `hydraJobs`" => sub {
69+
checkFlake 'flake-hydraJobs#hydraJobs'
70+
};
71+
72+
subtest "Flake using explict `attr`" => sub {
73+
checkFlake 'flake-attr#attr'
74+
};
75+
6776
done_testing;

t/jobs/flake-attr/flake.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
outputs = { ... }: {
3+
attr =
4+
import ./basic.nix;
5+
};
6+
}

0 commit comments

Comments
 (0)