nix-gitlab-ci/lib/impl/modules/root.nix
Jairo Llopis ab41bc24ec
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
2026-05-11 08:02:44 +01:00

143 lines
3.9 KiB
Nix

{
lib,
soonixSubmodule,
pipelineSubmodule,
...
}: 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 {
description = ''
Configure the soonix `.gitlab-ci.yml` generation.
'';
type = types.submodule soonixSubmodule;
default = {};
};
nixJobsByDefault = mkOption {
description = ''
Whether to transform all jobs to nix-configured jobs by default.
If false, you need to set [`nix.enable`](#pipelinesnamejobsnamenixenable)
for each job you want to be transformed.
'';
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, ...}: 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.
'';
type = types.submodule configSubmodule;
default = {};
};
pipelines = mkOption {
description = ''
Defines all pipelines.
'';
type = types.attrsOf (types.submoduleWith {
modules = [pipelineSubmodule];
specialArgs = {
rootConfig = config.config;
rootChecks = config.checks;
rootAutoChecks = config.config.autoChecks;
inherit system;
};
});
default = {};
};
packages = mkOption {
description = ''
Final packages for use in CI. (readonly)
'';
readOnly = true;
type = types.attrsOf types.package;
};
soonix = mkOption {
description = ''
Soonix config for generating `.gitlab-ci.yml`. (readonly)
See [`config.soonix`](#configsoonix) for configuring this.
'';
readOnly = true;
type = types.attrs;
};
};
config = {
packages = foldr (pipeline: acc: acc // pipeline) {} (
map (pipeline: pipeline.packages) (builtins.attrValues config.pipelines)
);
soonix = config.config.soonix.finalConfig;
};
};
}