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
131
lib/impl/modules/job.nix
Normal file
131
lib/impl/modules/job.nix
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
{
|
||||
lib,
|
||||
cilib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkOption types filterAttrs;
|
||||
inherit (cilib.helpers) filterUnset mkUnsetOption;
|
||||
in rec {
|
||||
jobConfigSubmodule = {pipelineConfig, ...}: {
|
||||
options = {
|
||||
enable = mkOption {
|
||||
description = "Transform this job to a nix-configured one";
|
||||
type = types.bool;
|
||||
default = pipelineConfig.nixJobsByDefault;
|
||||
};
|
||||
deps = mkOption {
|
||||
description = "Dependencies to inject into the job before running it";
|
||||
type = types.listOf types.package;
|
||||
default = [];
|
||||
};
|
||||
enableRunnerCache = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Cache this job using the GitLab Runner cache.
|
||||
Warning: useful for tiny jobs, but most of the time it just takes an eternity.
|
||||
'';
|
||||
};
|
||||
runnerCacheKey = mkOption {
|
||||
type = types.str;
|
||||
default = "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG";
|
||||
description = "Cache key to use for the runner nix cache. Requires enableRunnerCache = true";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
jobSubmodule = {
|
||||
name,
|
||||
config,
|
||||
pipelineName,
|
||||
pipelineConfig,
|
||||
...
|
||||
}: let
|
||||
#
|
||||
# GITLAB OPTIONS
|
||||
#
|
||||
gitlabOptions = {
|
||||
stage = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
image = mkUnsetOption {
|
||||
type = types.str;
|
||||
};
|
||||
variables = mkUnsetOption {
|
||||
type = types.attrsOf types.str;
|
||||
};
|
||||
before_script = mkUnsetOption {
|
||||
type = types.listOf types.str;
|
||||
};
|
||||
script = mkOption {
|
||||
type = types.listOf types.str;
|
||||
};
|
||||
after_script = mkUnsetOption {
|
||||
type = types.listOf types.str;
|
||||
};
|
||||
artifacts = mkUnsetOption {
|
||||
type = types.attrs; # TODO: more granular
|
||||
description = '''';
|
||||
};
|
||||
rules = mkUnsetOption {
|
||||
type = types.listOf types.attrs;
|
||||
};
|
||||
allow_failure = mkUnsetOption {
|
||||
type = types.bool;
|
||||
};
|
||||
};
|
||||
in {
|
||||
options =
|
||||
{
|
||||
nix = mkOption {
|
||||
description = "Nix-GitLab-CI config options for this job";
|
||||
type = types.submoduleWith {
|
||||
modules = [jobConfigSubmodule];
|
||||
specialArgs.pipelineConfig = pipelineConfig;
|
||||
};
|
||||
default = {};
|
||||
};
|
||||
finalConfig = mkOption {
|
||||
internal = true;
|
||||
type = types.attrs;
|
||||
};
|
||||
depsDrv = mkOption {
|
||||
internal = true;
|
||||
type = types.package;
|
||||
};
|
||||
runnerDrv = mkOption {
|
||||
internal = true;
|
||||
type = types.package;
|
||||
};
|
||||
packages = mkOption {
|
||||
internal = true;
|
||||
type = types.attrsOf types.package;
|
||||
};
|
||||
}
|
||||
// gitlabOptions;
|
||||
config = let
|
||||
attrsToKeep = builtins.attrNames gitlabOptions;
|
||||
in {
|
||||
finalConfig = cilib.mkJobPatched {
|
||||
key = name;
|
||||
job = filterUnset (filterAttrs (n: _v: builtins.elem n attrsToKeep) config);
|
||||
nixConfig = config.nix;
|
||||
inherit pipelineName;
|
||||
};
|
||||
depsDrv = cilib.mkJobDeps {
|
||||
key = name;
|
||||
job = config.finalConfig;
|
||||
nixConfig = config.nix;
|
||||
};
|
||||
runnerDrv = cilib.mkJobRun {
|
||||
key = name;
|
||||
job = config.finalConfig;
|
||||
jobDeps = config.depsDrv;
|
||||
};
|
||||
packages = {
|
||||
"gitlab-ci:pipeline:${pipelineName}:job-deps:${name}" = config.depsDrv;
|
||||
"gitlab-ci:pipeline:${pipelineName}:job:${name}" = config.runnerDrv;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue