feat: auto-generate CI jobs from flake checks

Add `checks` option and `config.autoChecks` to auto-generate a CI job
for each flake check derivation. Auto-generated jobs go through
`mkJobPatched` for proper Nix setup, cache, and environment handling.

The `checks` option is automatically wired to `config.checks` in
flake-parts. System is inferred from `pkgs.system` and set via the new
`system` option. User-defined jobs with the same name always take
precedence.

New tests cover both flake-parts and direct API entry points.

MT-14138
This commit is contained in:
Jairo Llopis 2026-05-11 08:02:44 +01:00
parent 097f775cff
commit ab41bc24ec
No known key found for this signature in database
GPG key ID: B24A1D10508180D8
8 changed files with 388 additions and 5 deletions

View file

@ -24,6 +24,9 @@
name,
config,
rootConfig,
rootChecks ? {},
rootAutoChecks ? {},
system,
...
}: let
#
@ -211,10 +214,31 @@
// gitlabOptions;
config = let
attrsToKeep = builtins.attrNames gitlabOptions;
autoNixConfig = {
enable = config.nix.nixJobsByDefault;
enableRunnerCache = false;
};
autoJobs = lib.optionalAttrs (rootAutoChecks.enable && name == rootAutoChecks.pipeline) (
builtins.mapAttrs (checkName: _:
cilib.mkJobPatched {
key = "auto:${checkName}";
pipelineName = name;
nixConfig = autoNixConfig;
job = {
image = "$NIX_CI_IMAGE";
stage = rootAutoChecks.stage;
script = ["nix build .#checks.\"${system}\".${checkName}"];
} // lib.optionalAttrs (rootAutoChecks.tags != []) {tags = rootAutoChecks.tags;};
}
) (
builtins.removeAttrs rootChecks (builtins.attrNames config.jobs)
)
);
in {
finalConfig =
(filterUnset (filterAttrs (n: _v: builtins.elem n attrsToKeep) config))
// mapAttrs (_name: value: value.finalConfig) config.jobs;
// mapAttrs (_name: value: value.finalConfig) config.jobs
// autoJobs;
packages =
{
"gitlab-ci:pipeline:${name}" = toYaml "gitlab-ci-config.json" config.finalConfig;