# Nix Gitlab CI Flake module which allows generating a `.gitlab-ci.yml` from Nix. This allows easily using any Nix package in CI. Also makes it possible to split CI parts in a separate module which can be imported in multiple projects. ## Usage ```nix # flake.nix { ... inputs.nix-gitlab-ci.url = "gitlab:TECHNOFAB/nix-gitlab-ci?dir=lib"; outputs = {...}: flake-parts.lib.mkFlake {...} { imports = [ inputs.nix-gitlab-ci.flakeModule ]; ... perSystem = {pkgs, ...}: { ci = { stages = ["test"]; jobs = { "test" = { stage = "test"; nix.deps = [pkgs.unixtools.ping]; script = [ "ping -c 5 8.8.8.8" ]; }; }; }; ... } } } ``` ```yaml # .gitlab-ci.yml include: - component: gitlab.com/TECHNOFAB/nix-gitlab-ci/nix-gitlab-ci@1.1.1 inputs: # specify inputs here, for example: image_tag: latest-cachix ``` ## Utilities ### Disable Caching temporarily To disable any of the provided caches for a pipeline one can set `NIX_CI_DISABLE_CACHE` to anything non-empty (eg. "yes") when triggering the pipeline. The `build:nix-ci` job has a different special environment variable `NIX_CI_SKIP_CACHE` (useful if the generated pipeline is outdated but caching should generally still take place). ### Run Jobs locally You can run any job's script (+ before and after) locally with Nix for easier testing: ```sh nix run .#gitlab-ci-job: ``` There is also `.#gitlab-ci-job-deps:` which generates and exports the required environment variables for each job: - PATH (with all deps) - any custom env variables which contain store paths to not break stuff when switching archs Please see #8 for some issues and further improvements on this. ## Thanks to Some parts of this implementation are adapted/inspired from https://gitlab.com/Cynerd/gitlab-ci-nix