mirror of
https://gitlab.com/TECHNOFAB/nix-gitlab-ci.git
synced 2025-12-12 02:00:13 +01:00
feat: initial v3 rewrite
This commit is contained in:
commit
0952ab4145
32 changed files with 1457 additions and 0 deletions
101
lib/impl/modules/pipeline.nix
Normal file
101
lib/impl/modules/pipeline.nix
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
{
|
||||
lib,
|
||||
cilib,
|
||||
jobSubmodule,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkOption types filterAttrs mergeAttrsList pipe 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-CI config options for this pipeline";
|
||||
type = types.submoduleWith {
|
||||
modules = [pipelineConfigSubmodule];
|
||||
specialArgs.rootConfig = rootConfig;
|
||||
};
|
||||
default = {};
|
||||
};
|
||||
finalConfig = mkOption {
|
||||
description = "Final config of the pipeline";
|
||||
internal = true;
|
||||
type = types.attrs;
|
||||
};
|
||||
packages = mkOption {
|
||||
description = "Final packages for use in CI";
|
||||
internal = 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}" = pipe config.finalConfig [
|
||||
builtins.toJSON
|
||||
builtins.unsafeDiscardOutputDependency
|
||||
builtins.unsafeDiscardStringContext
|
||||
(toYaml "gitlab-ci-config.json")
|
||||
];
|
||||
"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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue