mirror of
https://gitlab.com/TECHNOFAB/nix-gitlab-ci.git
synced 2025-12-11 17:50:08 +01:00
61 lines
2.2 KiB
Nix
61 lines
2.2 KiB
Nix
{
|
|
lib,
|
|
helpers,
|
|
mkJobDeps,
|
|
mkJobRun,
|
|
mkJobPatched,
|
|
}: let
|
|
inherit (lib) assertMsg;
|
|
inherit (helpers) filterAttrsRec customMapAttrs toYaml toYamlPretty;
|
|
in
|
|
{
|
|
name,
|
|
pipeline,
|
|
nixConfig,
|
|
}: let
|
|
jobs = filterAttrsRec (_n: v: v != null) pipeline.jobs;
|
|
rest = filterAttrsRec (_n: v: v != null) (builtins.removeAttrs pipeline ["jobs"]);
|
|
# this allows us to nix build this to get all the mentioned dependencies from the binary cache
|
|
# pro: we don't have to download everything, just the deps for the current job
|
|
# before, we just allowed pkgs inside the script string directly, but now with the ability to source this file
|
|
# we can support different architectures between runners (eg. the arch of the initial runner does not matter)
|
|
jobsMappedForDeps =
|
|
customMapAttrs (key: job: {
|
|
name = "gitlab-ci:pipeline:${name}:job-deps:${key}";
|
|
value = mkJobDeps {inherit key job nixConfig;};
|
|
})
|
|
jobs;
|
|
# allows the user to directly run the script
|
|
jobsMappedForScript =
|
|
customMapAttrs (key: job: {
|
|
name = "gitlab-ci:pipeline:${name}:job:${key}";
|
|
value = mkJobRun {
|
|
inherit key job nixConfig;
|
|
jobDeps = jobsMappedForDeps."gitlab-ci:pipeline:${name}:job-deps:${key}";
|
|
};
|
|
})
|
|
jobs;
|
|
# build the deps specific for this job before anything, this way the deps should be fetched from the cache
|
|
jobsPatched =
|
|
customMapAttrs (key: job: {
|
|
name = key;
|
|
value = assert assertMsg (builtins.elem job.stage (rest.stages or [])) "stage '${job.stage}' of job '${key}' does not exist";
|
|
mkJobPatched {
|
|
inherit key job nixConfig;
|
|
pipelineName = name;
|
|
};
|
|
})
|
|
jobs;
|
|
in {
|
|
packages =
|
|
# gitlab-ci:pipeline:<name>
|
|
# gitlab-ci:pipeline:<name>:job:<name>
|
|
# gitlab-ci:pipeline:<name>:job-deps:<name>
|
|
{
|
|
"gitlab-ci:pipeline:${name}" = toYaml "gitlab-ci-${name}.yml" (rest // jobsPatched);
|
|
"gitlab-ci:pipeline:${name}:pretty" = toYamlPretty "gitlab-ci-${name}.yml" (rest // jobsPatched);
|
|
}
|
|
// jobsMappedForDeps
|
|
// jobsMappedForScript;
|
|
finalConfig = rest // jobsPatched;
|
|
}
|