Skip to content

Create GitHub Actions matrix from nix flake show #36

Create GitHub Actions matrix from nix flake show

Create GitHub Actions matrix from nix flake show #36

name: Nix Flake actions
on:
pull_request:
push:
branches:
- main
jobs:
nix-matrix:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
outputs:
ubuntu-latest: ${{ steps.set-matrix.outputs.ubuntu-latest }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v24
- id: set-matrix
name: Generate Nix Matrix
run: |
matrix=$(nix flake show --refresh --json "." | jq '{ os: "${{ matrix.os }}", attr: ((path(.. | select(.type? == "derivation")) | map((if (. | contains(".")) then "\"" + . + "\"" else . end)) | join(".")), (path(.. | select(.type? == "nixos-configuration")) | map((if (. | contains(".")) then "\"" + . + "\"" else . end)) | join(".") | . + ".config.system.build.toplevel")) }' | jq --slurp --compact-output)
echo "${{ matrix.os }}=$matrix" >> "$GITHUB_OUTPUT"
nix-build:
needs: nix-matrix
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include: ${{fromJSON(needs.nix-matrix.outputs.ubuntu-latest)}}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v24
- uses: cachix/cachix-action@v12
with:
name: matrss
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix build -L '.#${{ matrix.attr }}'