From ebfd17b76a9a51b59217bce399138aaa1e85a603 Mon Sep 17 00:00:00 2001 From: Brian McGee Date: Wed, 8 May 2024 08:54:58 +0100 Subject: [PATCH] feat: add nix github workflow Signed-off-by: Brian McGee --- .github/workflows/nix.yml | 36 ++++++++++++++++++++++++++++++++ flake.lock | 43 ++++++++++++++++++++++----------------- flake.nix | 11 ++++++++-- nix/checks.nix | 13 +++++++++++- 4 files changed, 81 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/nix.yml diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 0000000..d6ff466 --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,36 @@ +name: Nix Flake Actions +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +jobs: + nix-matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v26 + - id: set-matrix + name: Generate Nix Matrix + run: | + set -Eeu + matrix="$(nix eval --json '.#githubActions.matrix')" + echo "matrix=$matrix" >> "$GITHUB_OUTPUT" + + nix-build: + needs: nix-matrix + runs-on: ${{ matrix.os }} + strategy: + matrix: ${{fromJSON(needs.nix-matrix.outputs.matrix)}} + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v26 + - uses: cachix/cachix-action@v14 + with: + name: numtide + authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" + - run: nix build -L ".#${{ matrix.attr }}" diff --git a/flake.lock b/flake.lock index 34c5d62..1528488 100644 --- a/flake.lock +++ b/flake.lock @@ -38,7 +38,9 @@ }, "flake-parts": { "inputs": { - "nixpkgs-lib": "nixpkgs-lib" + "nixpkgs-lib": [ + "nixpkgs" + ] }, "locked": { "lastModified": 1712014858, @@ -111,6 +113,26 @@ "type": "github" } }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1703863825, + "narHash": "sha256-rXwqjtwiGKJheXB43ybM8NwWB8rO2dSRrEqes0S7F5Y=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "5163432afc817cf8bd1f031418d1869e4c9d5547", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1714253743, @@ -127,24 +149,6 @@ "type": "github" } }, - "nixpkgs-lib": { - "locked": { - "dir": "lib", - "lastModified": 1711703276, - "narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "d8fe5e6c92d0d190646fb9f1056741a229980089", - "type": "github" - }, - "original": { - "dir": "lib", - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, "root": { "inputs": { "devshell": "devshell", @@ -152,6 +156,7 @@ "flake-parts": "flake-parts", "gomod2nix": "gomod2nix", "nix-filter": "nix-filter", + "nix-github-actions": "nix-github-actions", "nixpkgs": "nixpkgs", "treefmt-nix": "treefmt-nix" } diff --git a/flake.nix b/flake.nix index 8fafef7..35a89b3 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,10 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - flake-parts.url = "github:hercules-ci/flake-parts"; + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; treefmt-nix = { # todo switch back to numtide/treefmt-nix once merged url = "github:brianmcgee/treefmt-nix/feat/pipelines"; @@ -16,10 +19,14 @@ gomod2nix = { url = "github:nix-community/gomod2nix"; inputs.nixpkgs.follows = "nixpkgs"; - inputs.flake-utils.follows ="devshell/flake-utils"; + inputs.flake-utils.follows = "devshell/flake-utils"; }; nix-filter.url = "github:numtide/nix-filter"; flake-compat.url = "github:nix-community/flake-compat"; + nix-github-actions = { + url = "github:nix-community/nix-github-actions"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = inputs @ {flake-parts, ...}: diff --git a/nix/checks.nix b/nix/checks.nix index 8216515..500f224 100644 --- a/nix/checks.nix +++ b/nix/checks.nix @@ -1,5 +1,16 @@ -{lib, ...}: { +{ + lib, + inputs, + self, + ... +}: { + # generate github actions matrix using the flake's checks + flake.githubActions = inputs.nix-github-actions.lib.mkGithubMatrix { + checks = lib.getAttrs ["x86_64-linux" "x86_64-darwin"] self.checks; + }; + perSystem = {self', ...}: { + # mixin every package checks = with lib; mapAttrs' (n: nameValuePair "package-${n}") self'.packages; }; }