chore: better solution for handling store paths in variables

This commit is contained in:
technofab 2025-09-04 08:34:25 +02:00
parent 31f0e4ea13
commit 5e2ae29660
No known key found for this signature in database
2 changed files with 27 additions and 18 deletions

View file

@ -11,21 +11,33 @@ in
pipelineName, pipelineName,
nixConfig, nixConfig,
}: }:
job (builtins.removeAttrs job ["variables" "cache"])
// (optionalAttrs nixConfig.enable ( // (optionalAttrs nixConfig.enable (
(prependToBeforeScript ["source setup_nix_ci \"gitlab-ci:pipeline:${pipelineName}:job-deps:${key}\""] job) (prependToBeforeScript ["source setup_nix_ci \"gitlab-ci:pipeline:${pipelineName}:job-deps:${key}\""] job)
// (appendToAfterScript ["finalize_nix_ci"] job) // (appendToAfterScript ["finalize_nix_ci"] job)
)) ))
// optionalAttrs nixConfig.enable { // optionalAttrs nixConfig.enable (
(let
variables = variables =
(filterJobVariables false job) (filterJobVariables false job)
// optionalAttrs nixConfig.enableRunnerCache { // optionalAttrs nixConfig.enableRunnerCache {
NIX_CI_CACHE_STRATEGY = "runner"; NIX_CI_CACHE_STRATEGY = "runner";
}; };
in
# filter empty variables
optionalAttrs (variables != {}) {
inherit variables;
})
// (let
cache = cache =
(toList (job.cache or [])) (toList (job.cache or []))
++ (optional nixConfig.enableRunnerCache { ++ (optional nixConfig.enableRunnerCache {
key = nixConfig.runnerCacheKey; key = nixConfig.runnerCacheKey;
paths = [".nix-cache/"]; paths = [".nix-cache/"];
}); });
} in
# filter empty cache
optionalAttrs (cache != []) {
inherit cache;
})
)

View file

@ -148,10 +148,7 @@
name = "handle store paths in variables"; name = "handle store paths in variables";
expected = { expected = {
stages = ["test"]; stages = ["test"];
test = { test.stage = "test";
stage = "test";
variables."TEST" = "${pkgs.hello}";
};
}; };
actual = actual =
(mkPipeline { (mkPipeline {