diff --git a/flake.nix b/flake.nix index 946a165..973b4ff 100644 --- a/flake.nix +++ b/flake.nix @@ -42,9 +42,14 @@ when = "delayed"; start_in = "1 hour"; deps = [pkgs.hello pkgs.curl]; + variables = { + TEST = "test"; + TEST_WITH_DERIVATION = "${pkgs.hello}/test"; + }; script = [ "hello" "curl google.de" + "echo $TEST $TEST_WITH_DERIVATION" ]; }; "test-non-nix" = { diff --git a/lib/flakeModule.nix b/lib/flakeModule.nix index 292df6c..8d6f4a9 100644 --- a/lib/flakeModule.nix +++ b/lib/flakeModule.nix @@ -138,10 +138,25 @@ # 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 = - mapAttrs (key: job: { + mapAttrs (key: job: let + variablesWithStorePaths = + lib.concatMapAttrs ( + name: value: + if lib.hasInfix "/nix/store/" value + then { + ${name} = value; + } + else {} + ) + (job.variables or {}); + variableExports = lib.concatMapStrings (x: "${x}\n") ( + lib.mapAttrsToList (name: value: "export ${name}=\"${value}\"") variablesWithStorePaths + ); + in { name = "gitlab-ci-job-deps:${key}"; value = pkgs.writeShellScript "gitlab-ci-job-deps:${key}" '' export PATH="${lib.makeBinPath job.deps}:$PATH"; + ${variableExports} ''; }) jobs; @@ -166,6 +181,13 @@ job)) // lib.optionalAttrs job.nix { image = job.image; + variables = lib.concatMapAttrs (name: value: + if lib.hasInfix "/nix/store/" value + then {} + else { + ${name} = value; + }) + (job.variables or {}); } ) ["nix" "deps"]; })