Skip to content

Commit

Permalink
feat: add nix github workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Brian McGee <[email protected]>
  • Loading branch information
brianmcgee committed May 8, 2024
1 parent a3fb127 commit ebfd17b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 21 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
41 changes: 23 additions & 18 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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, ...}:
Expand Down
13 changes: 12 additions & 1 deletion nix/checks.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}

0 comments on commit ebfd17b

Please sign in to comment.