Allows (advanced) configuration of GitLab CI using Nix. https://nix-gitlab-ci.projects.tf
Find a file
Skryta Istota c8f51c73ed
fix(job) Fixed premature filtering of variables
Fixed excessive deletion of environment variables containing paths to nix store package files,
causing them to not be exported in Giltab's CI environment,
plus removed duplicate tests for moving environment variables.
2025-12-03 17:35:36 +01:00
docs chore: alias original pipeline source & document component issue 2025-10-09 14:04:21 +02:00
examples chore: add examples for flake-parts and rensa-nix 2025-09-02 10:48:39 +02:00
lib fix(job) Fixed premature filtering of variables 2025-12-03 17:35:36 +01:00
nix rollback(jobPatched) Restored some features for patching jobs for ci 2025-12-03 16:35:45 +01:00
templates chore: alias original pipeline source & document component issue 2025-10-09 14:04:21 +02:00
tests fix(job) Fixed premature filtering of variables 2025-12-03 17:35:36 +01:00
.envrc feat: initial v3 rewrite 2025-09-01 15:04:20 +02:00
.gitignore feat: initial v3 rewrite 2025-09-01 15:04:20 +02:00
.gitlab-ci.yml fix(ci) Fixed downloading images from project forks for ci 2025-11-30 14:14:14 +01:00
flake.lock feat: initial v3 rewrite 2025-09-01 15:04:20 +02:00
flake.nix docs: add initial docs setup 2025-09-02 11:00:38 +02:00
LICENSE.md chore: add LICENSE 2025-09-02 10:36:46 +02:00
README.md chore: reformat 2025-09-02 11:34:24 +02:00

Nix GitLab CI

built with nix pipeline status License: MIT Latest Release Support me Docs

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 (with flake-parts)

# flake.nix
{
  ...
  inputs.nix-gitlab-ci.url = "gitlab:TECHNOFAB/nix-gitlab-ci/<version>?dir=lib";  # recommendation: pin to the latest release/version
  
  outputs = {...}: flake-parts.lib.mkFlake {...} {
    imports = [
      inputs.nix-gitlab-ci.flakeModule
    ];
    ...
    
    perSystem = {pkgs, ...}: {
      ci = {
        config = {
          # configure Nix-GitLab-CI here, see docs for options
        };
        pipelines."default" = {
          stages = ["test"];
          jobs = {
            "test" = {
              stage = "test";
              nix.deps = [pkgs.unixtools.ping];
              script = [
                "ping -c 5 8.8.8.8"
              ];
            };
          };
        };
        # runs on a merge request for example
        pipelines."merge_request_event" = {
          stages = ["some_stage"];
          jobs = { ... };
        };
      };
      ...
    }
  }
}

Now either use this in your .gitlab-ci.yml or setup Soonix to auto generate this file for you with the right version (see the docs for more).

# .gitlab-ci.yml
include:
  - component: gitlab.com/TECHNOFAB/nix-gitlab-ci/nix-gitlab-ci@<version>  # recommendation: pin to the latest release/version (don't use "main" etc.)
    inputs:
      version: <version>  # docker image tag, use the same version as a above

Usage (directly)

let
  cilib = inputs.nix-gitlab-ci.lib {inherit pkgs;};
in
  cilib.mkCI {
    config = ...;
    pipelines."default" = ...;
  };
  # exposes `soonix` for the soonix hook and `packages` which contain the configs, jobs etc.

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_FORCE_BUILD (useful if the generated pipeline in the cache is outdated, this will build it again).

Run Jobs locally

You can run any job's script (+ before and after) locally with Nix for easier testing:

#                                /  pipeline name, like "default"
nix run .#gitlab-ci:pipeline:<pipeline name>:job:<name>

There is also .#gitlab-ci:pipeline:<pipeline name>:job-deps:<name> 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

Thanks to

Some parts of this implementation are adapted/inspired from https://gitlab.com/Cynerd/gitlab-ci-nix