From 5e0dd4a80e140884e71ebd57b25d2a2c2a1a9e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Ri=C3=9Fe?= Date: Mon, 8 Jan 2024 19:57:16 +0100 Subject: [PATCH] Create GitHub Actions matrix from `nix flake show` --- .github/workflows/build-flake-outputs.yml | 43 +++++++++++++++++++++++ .github/workflows/nix-github-actions.yml | 36 ------------------- 2 files changed, 43 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/build-flake-outputs.yml delete mode 100644 .github/workflows/nix-github-actions.yml diff --git a/.github/workflows/build-flake-outputs.yml b/.github/workflows/build-flake-outputs.yml new file mode 100644 index 0000000..7decb3a --- /dev/null +++ b/.github/workflows/build-flake-outputs.yml @@ -0,0 +1,43 @@ +name: Build flake outputs + +on: + pull_request: + push: + branches: + - main + +jobs: + nix-matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v24 + - id: set-matrix + name: Generate matrix + run: | + matrix=$( + nix flake show --refresh --json "." | + jq '{ 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=$matrix" >> "$GITHUB_OUTPUT" + + nix-build: + needs: nix-matrix + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: ${{fromJSON(needs.nix-matrix.outputs.matrix)}} + 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 }}' diff --git a/.github/workflows/nix-github-actions.yml b/.github/workflows/nix-github-actions.yml deleted file mode 100644 index 3fcd5cb..0000000 --- a/.github/workflows/nix-github-actions.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Nix Flake actions - -on: - pull_request: - push: - branches: - - main - -jobs: - nix-matrix: - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.set-matrix.outputs.matrix }} - steps: - - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@v24 - - 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@v24 - - uses: cachix/cachix-action@v12 - with: - name: matrss - authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' - - run: nix build -L ".#${{ matrix.attr }}"