mirror of
https://gitlab.com/TECHNOFAB/nix-gitlab-ci.git
synced 2025-12-12 02:00:13 +01:00
104 lines
2.9 KiB
Nix
104 lines
2.9 KiB
Nix
{
|
|
lib,
|
|
cilib,
|
|
jobSubmodule,
|
|
...
|
|
}: let
|
|
inherit (lib) mkOption types filterAttrs mergeAttrsList mapAttrs;
|
|
inherit (cilib.helpers) filterUnset mkUnsetOption toYaml toYamlPretty;
|
|
|
|
pipelineConfigSubmodule = {rootConfig, ...}: {
|
|
options = {
|
|
nixJobsByDefault = mkOption {
|
|
description = ''
|
|
Whether to transform all jobs to nix-configured jobs by default.
|
|
If false, you need to set `nix.enable` for each job you want to be transformed.
|
|
'';
|
|
type = types.bool;
|
|
default = rootConfig.nixJobsByDefault;
|
|
};
|
|
};
|
|
};
|
|
|
|
pipelineSubmodule = {
|
|
name,
|
|
config,
|
|
rootConfig,
|
|
...
|
|
}: let
|
|
#
|
|
# GITLAB OPTIONS
|
|
#
|
|
gitlabOptions = {
|
|
stages = mkOption {
|
|
type = types.listOf types.str;
|
|
default = [];
|
|
# .pre and .post always exist
|
|
apply = val: [".pre"] ++ val ++ [".post"];
|
|
};
|
|
variables = mkUnsetOption {
|
|
type = types.attrsOf types.str;
|
|
description = '''';
|
|
};
|
|
};
|
|
in {
|
|
_file = ./pipeline.nix;
|
|
options =
|
|
{
|
|
nix = mkOption {
|
|
description = ''
|
|
Nix-GitLab-CI config options for this pipeline.
|
|
'';
|
|
type = types.submoduleWith {
|
|
modules = [pipelineConfigSubmodule];
|
|
specialArgs.rootConfig = rootConfig;
|
|
};
|
|
default = {};
|
|
};
|
|
finalConfig = mkOption {
|
|
description = ''
|
|
Final config of the pipeline. (readonly)
|
|
'';
|
|
readOnly = true;
|
|
type = types.attrs;
|
|
};
|
|
packages = mkOption {
|
|
description = ''
|
|
Final packages for use in CI. (readonly)
|
|
'';
|
|
readOnly = true;
|
|
type = types.attrsOf types.package;
|
|
};
|
|
# jobs are nested to make distinguishing them from other keys in the ci config easier
|
|
jobs = mkOption {
|
|
description = ''
|
|
Jobs for this pipeline.
|
|
'';
|
|
type = types.attrsOf (types.submoduleWith {
|
|
modules = [jobSubmodule];
|
|
specialArgs = {
|
|
pipelineName = name;
|
|
pipelineConfig = config.nix;
|
|
};
|
|
});
|
|
default = {};
|
|
};
|
|
}
|
|
// gitlabOptions;
|
|
config = let
|
|
attrsToKeep = builtins.attrNames gitlabOptions;
|
|
in {
|
|
finalConfig =
|
|
(filterUnset (filterAttrs (n: _v: builtins.elem n attrsToKeep) config))
|
|
// mapAttrs (_name: value: value.finalConfig) config.jobs;
|
|
packages =
|
|
{
|
|
"gitlab-ci:pipeline:${name}" = toYaml "gitlab-ci-config.json" config.finalConfig;
|
|
"gitlab-ci:pipeline:${name}:pretty" = toYamlPretty "gitlab-ci-config.yml" config.finalConfig;
|
|
}
|
|
// mergeAttrsList (map (job: job.packages) (builtins.attrValues config.jobs));
|
|
};
|
|
};
|
|
in {
|
|
inherit pipelineSubmodule pipelineConfigSubmodule;
|
|
}
|