/nix-github-actions

A library to turn Nix Flake attribute sets into Github Actions matrices [maintainer=@adisbladis]

Primary LanguageNixMIT LicenseMIT

nix-github-actions

This is a library to turn Nix Flake attribute sets into Github Actions matrices.

Features:

  • Unopinionated

Install Nix using any method you like

  • Flexible

Nix-github-actions is not an action in itself but a series of templates and a Nix library to build your own CI.

  • Parallel job execution

Use one Github Actions runner per package attribute

Usage

Quickstart

nix-github-actions comes with a quickstart script that interactively guides you through integrating it:

$ nix run github:nix-community/nix-github-actions

Manual

  1. Find a CI template in ./.github/workflows and copy it to your project

  2. Integrate into your project

Using Flake atttribute packages

  • flake.nix
{
  inputs.nix-github-actions.url = "github:nix-community/nix-github-actions";
  inputs.nix-github-actions.inputs.nixpkgs.follows = "nixpkgs";

  outputs = { self, nixpkgs, nix-github-actions }: {
    githubActions = nix-github-actions.lib.mkGithubMatrix { checks = self.packages; };
    packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
    packages.x86_64-linux.default = self.packages.x86_64-linux.hello;
  };
}

Using Flake attribute checks

  • flake.nix
{
  inputs.nix-github-actions.url = "github:nix-community/nix-github-actions";
  inputs.nix-github-actions.inputs.nixpkgs.follows = "nixpkgs";

  outputs = { self, nixpkgs, nix-github-actions }: {
    githubActions = nix-github-actions.lib.mkGithubMatrix { inherit (self) checks; };
    checks.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
    checks.x86_64-linux.default = self.packages.x86_64-linux.hello;
  };
}

When your Flake supports systems that GitHub Actions does not

If your Flake contains checks for platforms unsupported by Actions, e.g. aarch64-darwin, you can restrict the systems for which the matrix will be generated:

githubActions = nix-github-actions.lib.mkGithubMatrix {
  checks = nixpkgs.lib.getAttrs [ "x86_64-linux" "x86_64-darwin" ] self.checks;
};