mirror of
https://gitlab.com/TECHNOFAB/nix-gitlab-ci.git
synced 2025-12-12 18:20:07 +01:00
Squashed commit of the following: commit 86eadd3ec42b7bce0dc5716d65798af95d0d8cbc Author: technofab <admin@technofab.de> Date: Fri May 2 17:10:33 2025 +0200 docs(README): fix built with nix badge commit f50057da69e89974f17bc37b5e140b2ef9f817f6 Author: technofab <admin@technofab.de> Date: Fri May 2 16:09:00 2025 +0200 ci: change back rule so docs only get deployed on main commit ce02b043f4bd83c36285e5620e71701fc3bcc998 Author: technofab <admin@technofab.de> Date: Fri May 2 16:08:10 2025 +0200 docs: write docs and improve formatter etc. commit e996b23cf877d8021759b782aa5996f5e2bf12ac Author: technofab <admin@technofab.de> Date: Fri May 2 16:07:56 2025 +0200 docs: update README commit 650f97b5608c32cf6cf66cc3fdd0965dc42e4860 Author: technofab <admin@technofab.de> Date: Wed Apr 23 21:05:14 2025 +0200 docs: add favicon commit 67e1bfecbcaf0b8f7dad2eecfaccf774cc560874 Author: technofab <admin@technofab.de> Date: Wed Apr 23 20:53:44 2025 +0200 docs: initial setup
89 lines
3 KiB
Markdown
89 lines
3 KiB
Markdown
# Nix GitLab CI
|
|
|
|
[](https://builtwithnix.org)
|
|
[](https://gitlab.com/TECHNOFAB/nix-gitlab-ci/-/commits/main)
|
|

|
|
[](https://gitlab.com/TECHNOFAB/nix-gitlab-ci/-/releases)
|
|
[](https://tec.tf/#support)
|
|
[](https://nix-gitlab-ci.projects.tf)
|
|
|
|
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/<version>?dir=lib"; # recommendation: pin to the latest release/version
|
|
|
|
outputs = {...}: flake-parts.lib.mkFlake {...} {
|
|
imports = [
|
|
inputs.nix-gitlab-ci.flakeModule
|
|
];
|
|
...
|
|
|
|
perSystem = {pkgs, ...}: {
|
|
# ci is a shortcut and creates a "default" pipeline
|
|
ci = {
|
|
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 = { ... };
|
|
};
|
|
...
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
```yaml
|
|
# .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
|
|
```
|
|
|
|
## 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:
|
|
|
|
```sh
|
|
# / 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
|