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

@ -6,6 +6,41 @@
}: let
inherit (lib) mkOption types foldr;
in rec {
autoChecksSubmodule = {
options = {
enable = mkOption {
description = ''
Auto-generate CI jobs from [`checks`](#checks).
Each check becomes a job that runs `nix build .#checks.<system>.<name>`.
'';
type = types.bool;
default = false;
};
stage = mkOption {
description = ''
Stage to assign to auto-generated check jobs.
'';
type = types.str;
default = "test";
};
tags = mkOption {
description = ''
Tags to assign to auto-generated check jobs.
'';
type = types.listOf types.str;
default = [];
};
pipeline = mkOption {
description = ''
Name of the pipeline to add auto-generated check jobs to.
'';
type = types.str;
default = "default";
};
};
};
configSubmodule = {
options = {
soonix = mkOption {
@ -24,11 +59,40 @@ in rec {
type = types.bool;
default = true;
};
autoChecks = mkOption {
description = ''
Auto-generate CI jobs from flake checks.
See [`config.autoChecks`](#configautochecks) for configuration options.
'';
type = types.submodule autoChecksSubmodule;
default = {};
};
};
};
nixCiSubmodule = {config, ...}: {
nixCiSubmodule = {config, ...}: let
system = config.system;
in {
options = {
system = mkOption {
description = ''
System identifier (e.g. `"x86_64-linux"`).
Used when building checks with `nix build .#checks.<system>.<name>`.
Set automatically by `flakeModule` or `cilib.mkCI`.
'';
type = types.str;
};
checks = mkOption {
description = ''
Nix flake checks to optionally auto-generate CI jobs from.
Each attribute must be a derivation. The attribute name becomes the CI job name.
Requires [`config.autoChecks.enable`](#configautochecksenable) to take effect.
'';
type = types.attrsOf types.package;
default = {};
};
config = mkOption {
description = ''
Configuration of Nix-GitLab-CI itself.
@ -42,7 +106,12 @@ in rec {
'';
type = types.attrsOf (types.submoduleWith {
modules = [pipelineSubmodule];
specialArgs.rootConfig = config.config;
specialArgs = {
rootConfig = config.config;
rootChecks = config.checks;
rootAutoChecks = config.config.autoChecks;
inherit system;
};
});
default = {};
};