feat: add support for nix store paths in variables

by exporting them at runtime and removing them from the pipeline
definition itself
closes #3
This commit is contained in:
technofab 2024-09-10 12:46:13 +00:00
parent ed80957884
commit e3b35ec8ae
2 changed files with 28 additions and 1 deletions

View file

@ -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" = {

View file

@ -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"];
})