diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e8c146c..bff742c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -55,5 +55,3 @@ stages: - build-images - build - trigger -variables: - NIX_CI_IMAGE: $CI_REGISTRY_IMAGE/nix-ci:$CI_COMMIT_SHORT_SHA diff --git a/docs/index.md b/docs/index.md index 14f7da3..214fbf3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -9,14 +9,3 @@ This project provides a Nix flake module that allows you to generate your `.gitl - **Modularity:** Define and manage your CI configurations in a structured and modular way using Nix modules, making it easier to share and reuse CI logic across multiple projects. This documentation will guide you through setting up and using Nix GitLab CI for your projects. - -## Warnings - -To save you from frantically searching these docs if something doesn't work as expected, here are the most important warnings ;) - -!!! warning - - Do not put Nix store paths into global/pipeline variables. They will simply be passed through, - resulting in bad portability (if two runners have different archs for example, one cannot find the path). - If you need any Nix store path in env variables, always do it on the job level, there - it will automatically be computed at runtime, thus will always work no matter which runner it runs on. diff --git a/lib/VERSION b/lib/VERSION index fd2a018..cb2b00e 100644 --- a/lib/VERSION +++ b/lib/VERSION @@ -1 +1 @@ -3.1.0 +3.0.1 diff --git a/lib/impl/helpers.nix b/lib/impl/helpers.nix index 754cead..48a79fc 100644 --- a/lib/impl/helpers.nix +++ b/lib/impl/helpers.nix @@ -50,7 +50,7 @@ in rec { filterJobVariables = shouldContain: job: concatMapAttrs ( name: value: - optionalAttrs ((hasInfix builtins.storeDir value) == shouldContain) { + optionalAttrs ((hasInfix "/nix/store/" value) == shouldContain) { ${name} = value; } ) diff --git a/lib/impl/jobPatched.nix b/lib/impl/jobPatched.nix index 367a374..c7134fb 100644 --- a/lib/impl/jobPatched.nix +++ b/lib/impl/jobPatched.nix @@ -11,13 +11,13 @@ in pipelineName, nixConfig, }: - if ! nixConfig.enable - then job - else - (builtins.removeAttrs job ["variables" "cache"]) - // (prependToBeforeScript ["source setup_nix_ci \"gitlab-ci:pipeline:${pipelineName}:job-deps:${key}\""] 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) - // (let + )) + // optionalAttrs nixConfig.enable ( + (let variables = (filterJobVariables false job) // optionalAttrs nixConfig.enableRunnerCache { @@ -40,3 +40,4 @@ in optionalAttrs (cache != []) { inherit cache; }) + ) diff --git a/nix/repo/ci.nix b/nix/repo/ci.nix index 157ede7..a76c0d8 100644 --- a/nix/repo/ci.nix +++ b/nix/repo/ci.nix @@ -10,7 +10,6 @@ in # the child pipeline can then use the built images to test them extraData = { stages = ["build-images" "build" "trigger"]; - variables.NIX_CI_IMAGE = "$CI_REGISTRY_IMAGE/nix-ci:$CI_COMMIT_SHORT_SHA"; "build:image" = { stage = "build-images"; parallel.matrix = [ diff --git a/tests/cilib_test.nix b/tests/cilib_test.nix index 3b76fb8..78e99a3 100644 --- a/tests/cilib_test.nix +++ b/tests/cilib_test.nix @@ -64,22 +64,6 @@ nixConfig.enable = false; }; } - { - name = "jobPatched nix disabled with variables and cache"; - expected = { - variables."HELLO" = "world"; - cache = [{key = "example";}]; - }; - actual = mkJobPatched { - key = "test"; - pipelineName = "test"; - job = { - variables."HELLO" = "world"; - cache = [{key = "example";}]; - }; - nixConfig.enable = false; - }; - } { name = "jobPatched without runner cache"; expected = { @@ -145,7 +129,7 @@ # sh '' set -euo pipefail - ${ntlib.helpers.path (with pkgs; [jq gnugrep coreutils])} + ${ntlib.helpers.path [pkgs.jq pkgs.gnugrep pkgs.coreutils]} echo "two keys, one json one pretty" jq 'keys | length == 2' "${pipeline}" | grep -q true echo "key[0] is exactly 'gitlab-ci:pipeline:test'" @@ -161,13 +145,10 @@ ''; } { - name = "ignore store paths in variables with nix disabled"; + name = "handle store paths in variables"; expected = { stages = ["test"]; - test = { - stage = "test"; - variables."TEST" = "${pkgs.hello}"; - }; + test.stage = "test"; }; actual = (mkPipeline { @@ -182,28 +163,6 @@ }; }).finalConfig; } - { - # it doesn't make much sense to have any nix store path in variables, but we ignore it for global variables - name = "ignore store paths in global variables"; - expected = { - variables = { - HELLO = "world"; - CURL = toString pkgs.curl; - }; - }; - actual = - (mkPipeline { - name = "test"; - nixConfig.enable = true; - pipeline = { - variables = { - HELLO = "world"; - CURL = toString pkgs.curl; - }; - jobs = {}; - }; - }).finalConfig; - } ]; }; }