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 (
variables = (let
(filterJobVariables false job) variables =
// optionalAttrs nixConfig.enableRunnerCache { (filterJobVariables false job)
NIX_CI_CACHE_STRATEGY = "runner"; // optionalAttrs nixConfig.enableRunnerCache {
}; NIX_CI_CACHE_STRATEGY = "runner";
cache = };
(toList (job.cache or [])) in
++ (optional nixConfig.enableRunnerCache { # filter empty variables
key = nixConfig.runnerCacheKey; optionalAttrs (variables != {}) {
paths = [".nix-cache/"]; inherit variables;
}); })
} // (let
cache =
(toList (job.cache or []))
++ (optional nixConfig.enableRunnerCache {
key = nixConfig.runnerCacheKey;
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 {