# Usage ## Usage (with flake-parts) ```nix # flake.nix { ... inputs.nix-gitlab-ci.url = "gitlab:TECHNOFAB/nix-gitlab-ci/?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][docs-soonix] for more). ```yaml # .gitlab-ci.yml include: - component: gitlab.com/TECHNOFAB/nix-gitlab-ci/nix-gitlab-ci@ # recommendation: pin to the latest release/version (don't use "main" etc.) inputs: version: # docker image tag, use the same version as a above ``` ## Usage (directly) ```nix 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. ``` ## Auto-generate jobs from flake checks You can auto-generate CI jobs from your flake checks with the `autoChecks` option. Each check becomes a job that runs `nix build .#checks..`. Auto-generated jobs are skipped if a user-defined job with the same name exists. ### With flake-parts ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-parts.url = "github:hercules-ci/flake-parts"; systems.url = "github:nix-systems/default-linux"; nix-gitlab-ci.url = "gitlab:TECHNOFAB/nix-gitlab-ci?dir=lib"; }; outputs = { flake-parts, systems, ... } @ inputs: flake-parts.lib.mkFlake { inherit inputs; } { imports = [ inputs.nix-gitlab-ci.flakeModule ]; systems = import systems; perSystem = { pkgs, system, ... }: { checks = { lint = pkgs.runCommand "lint" { } '' ${pkgs.nodePackages.prettier}/bin/prettier --check . touch $out ''; test = pkgs.runCommand "test" { } '' ${pkgs.python3}/bin/python -m pytest touch $out ''; }; ci = { config.autoChecks.enable = true; pipelines.default.stages = [ "test" "build" ]; }; }; }; } ``` ### Without flake-parts ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nix-gitlab-ci.url = "gitlab:TECHNOFAB/nix-gitlab-ci?dir=lib"; }; outputs = { self, nixpkgs, nix-gitlab-ci, ... }: let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; cilib = nix-gitlab-ci.lib { inherit pkgs; }; in { checks.${system} = { lint = pkgs.runCommand "lint" { } '' ${pkgs.nodePackages.prettier}/bin/prettier --check . touch $out ''; test = pkgs.runCommand "test" { } '' ${pkgs.python3}/bin/python -m pytest touch $out ''; }; packages.${system} = (cilib.mkCI { checks = self.checks.${system}; config.autoChecks.enable = true; pipelines.default.stages = [ "test" "build" ]; }).packages; }; } ``` ______________________________________________________________________ Since V2 multiple pipelines are supported. See [Multiple Pipelines](./multi_pipeline.md) for more.