diff --git a/lib/impl/jobPatched.nix b/lib/impl/jobPatched.nix index 9997caa..c7134fb 100644 --- a/lib/impl/jobPatched.nix +++ b/lib/impl/jobPatched.nix @@ -11,21 +11,33 @@ in pipelineName, nixConfig, }: - job + (builtins.removeAttrs job ["variables" "cache"]) // (optionalAttrs nixConfig.enable ( (prependToBeforeScript ["source setup_nix_ci \"gitlab-ci:pipeline:${pipelineName}:job-deps:${key}\""] job) // (appendToAfterScript ["finalize_nix_ci"] job) )) - // optionalAttrs nixConfig.enable { - variables = - (filterJobVariables false job) - // optionalAttrs nixConfig.enableRunnerCache { - NIX_CI_CACHE_STRATEGY = "runner"; - }; - cache = - (toList (job.cache or [])) - ++ (optional nixConfig.enableRunnerCache { - key = nixConfig.runnerCacheKey; - paths = [".nix-cache/"]; - }); - } + // optionalAttrs nixConfig.enable ( + (let + variables = + (filterJobVariables false job) + // optionalAttrs nixConfig.enableRunnerCache { + NIX_CI_CACHE_STRATEGY = "runner"; + }; + in + # filter empty variables + optionalAttrs (variables != {}) { + 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; + }) + ) diff --git a/tests/cilib_test.nix b/tests/cilib_test.nix index d37da49..78e99a3 100644 --- a/tests/cilib_test.nix +++ b/tests/cilib_test.nix @@ -148,10 +148,7 @@ name = "handle store paths in variables"; expected = { stages = ["test"]; - test = { - stage = "test"; - variables."TEST" = "${pkgs.hello}"; - }; + test.stage = "test"; }; actual = (mkPipeline {