NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.05k stars 14.1k forks source link

services.gitlab-runner.services.<name>.preBuildScript not usable for container runners #214323

Open zagy opened 1 year ago

zagy commented 1 year ago

The option services.gitlab-runner.services.<name>.preBuildScript is defined as null or path.

The option defines the commands to be executed before the build itself, not a path to a script. From the gitlab-runner docs:

pre_build_script: Commands to be executed on the runner before executing the build. To insert multiple commands, use a (triple-quoted) multi-line string or \n character.

The problem becomes clear when the build is run in a container (e.g. docker): the commands are run inside the container which has no access to the nix store where the preBuildScript is written to. The error is e.g.

/bin/bash: line 129: /nix/store/13is9j57jrc177rb9268lyaaigmsq2bx-gitlab-runner-docker-dind-pre-build: No such file or directory

FTR: A workaround is registrationFlags = [ "--pre-build-script 'my; commands; go ; here'" ];.

@zimbatm @bachp @globin

mvnetbiz commented 9 months ago

A path to a script should be valid as a "command." I think the problem is your script path is not available inside the container. You could try mounting the host's nix store in your runner service.

dockerVolumes = [
   "/nix/store:/nix/store:ro"
]