Skip to content
Platonic-SystemsPublic

About

Generate gitlab-ci workflows automatically from Nix

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Automatic Flake GitLab CI

Generates .gitlab-ci.yml from your flake outputs with automatic dependency tracking.

Usage

Add the following flake input:

gitlab-ci = {
  url = "gitlab:platonic/gitlab-ci.nix";
  inputs.nixpkgs.follows = "nixpkgs";
};

And include it as an app in your flake outputs:

inputs@{ gitlab-ci, ... }:
{
  apps = {
    inherit (gitlab-ci.apps.x86_64-linux) gitlab-ci;
  };
}

Then generate your CI config:

nix run .#gitlab-ci > .gitlab-ci.yml

What Gets Generated

The generator automatically creates CI jobs for:

  • packages - Built in the build stage
  • checks - Built in the test stage
  • devShells - Built in the build stage
  • apps - Verified in the test stage

Jobs include automatic needs: dependencies based on derivation inputs, so checks that depend on packages will wait for those packages to build first.

Additionally, these jobs are always included:

  • flake:show - Validates flake structure (build stage)
  • flake:check - Runs nix flake check (validate stage)
  • gitlab-ci:check - Verifies .gitlab-ci.yml is up to date (validate stage)

Custom GitLab Configuration

Customize the generated config by adding a gitlab output to your flake. This is an overlay function that receives the fully generated config and returns your modified version:

{
  outputs = inputs: {
    # ... your packages, checks, apps, etc.

    # Overlay function: prev is the generated config
    gitlab = prev: prev // {
      # Add a deploy stage
      stages = prev.stages ++ [ "deploy" ];

      # Add a custom deploy job
      deploy = {
        stage = "deploy";
        script = [ "nix run .#deploy -L" ];
        rules = [{ "if" = "$CI_COMMIT_BRANCH == \"master\""; }];
      };

      # Modify a generated job's needs
      "checks:integration" = prev."checks:integration" // {
        needs = prev."checks:integration".needs ++ [ "deploy" ];
      };

      # Override variables
      variables = prev.variables // {
        CUSTOM_VAR = "value";
      };

      # Remove a job entirely
      "flake:check" = null;
    };
  };
}

The overlay gives you complete control - modify generated jobs, add new ones, change stages, remove jobs. You get the full generated config as prev and return whatever you want.

About

Generate gitlab-ci workflows automatically from Nix

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages