mirror of
https://gitlab.com/TECHNOFAB/nix-gitlab-ci.git
synced 2025-12-12 02:00:13 +01:00
64 lines
2.3 KiB
YAML
64 lines
2.3 KiB
YAML
spec:
|
|
inputs:
|
|
image_tag:
|
|
type: string
|
|
description: "latest | latest-cachix | latest-attic etc."
|
|
default: latest
|
|
cache_files:
|
|
type: array
|
|
description: |
|
|
Files to use as the cache key for the generated pipeline yaml.
|
|
If you use "ci.nix" to define CI, add that here for example
|
|
default: ["flake.nix", "flake.lock"]
|
|
disable_cache:
|
|
type: string
|
|
description: |
|
|
Disables any caching provided by this component. Set to any non-empty value to disable caching.
|
|
default: ""
|
|
---
|
|
stages:
|
|
- build
|
|
- trigger
|
|
variables:
|
|
NIX_CI_DISABLE_CACHE: "$[[ inputs.disable_cache ]]"
|
|
nix-ci:build:
|
|
stage: build
|
|
image: registry.gitlab.com/technofab/nix-gitlab-ci/nix-ci:$[[ inputs.image_tag ]]
|
|
cache:
|
|
- key:
|
|
files: $[[ inputs.cache_files ]]
|
|
paths:
|
|
- generated-gitlab-ci.yml
|
|
- key: nix
|
|
paths:
|
|
- .nix-cache/
|
|
before_script:
|
|
# generated-gitlab-ci.yml exists in the cache
|
|
- '[ -f "generated-gitlab-ci.yml" ] && export CACHED=true && echo "Using cached pipeline file (skip cache with NIX_CI_SKIP_CACHE)" || true'
|
|
# allow the user to manually skip the cache (when the key files are not correctly configured etc.)
|
|
- '[ -n "$NIX_CI_SKIP_CACHE" ] && unset CACHED && echo "Caching skipped for this job (through NIX_CI_SKIP_CACHE)" || true'
|
|
# only setup when we need to generate the pipeline yaml
|
|
- 'if [ -z "$CACHED" ]; then source setup_nix_ci; fi'
|
|
script:
|
|
# build the generated-gitlab-ci.yml if it does not exist in the cache
|
|
- 'if [ -z "$CACHED" ]; then nix build .#gitlab-ci-config && install result generated-gitlab-ci.yml; fi'
|
|
after_script:
|
|
# NOTE: environment variables of before_script and script don't exist here anymore
|
|
#
|
|
# save to binary cache or Gitlab CI cache only if we actually built something
|
|
# check if /tmp/nix-store-before exists as $CACHED never exists here and the file only exists if "setup_nix_ci" is called
|
|
- 'if [ -f "/tmp/nix-store-before" ]; then finalize_nix_ci; fi'
|
|
artifacts:
|
|
paths:
|
|
- generated-gitlab-ci.yml
|
|
nix-ci:trigger:
|
|
stage: trigger
|
|
needs:
|
|
- nix-ci:build
|
|
trigger:
|
|
include:
|
|
- artifact: generated-gitlab-ci.yml
|
|
job: nix-ci:build
|
|
strategy: depend
|
|
forward:
|
|
pipeline_variables: true
|