Something went wrong. Try again.
NixOS / Nix-darwin / Home Manager dotfiles for my devices
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129name: Flake Check
'on': push: branches: - master pull_request: branches: [master] workflow_dispatch: inputs: force-rebuild: description: Build every package, ignoring previous success records type: boolean default: false
permissions: contents: read
jobs: ci-passed: name: CI passed runs-on: ubuntu-latest needs: [check, discover, builds] # Run even if a prerequisite fails or is skipped; a skipped gate must not # accidentally satisfy the branch ruleset's required status check. if: ${{ always() }} steps: - name: Require every CI job to succeed env: CHECK_RESULT: ${{ needs.check.result }} DISCOVER_RESULT: ${{ needs.discover.result }} BUILD_RESULT: ${{ needs.builds.result }} BUILD_COUNT: ${{ needs.discover.outputs.count }} run: | [[ "$CHECK_RESULT" == success && "$DISCOVER_RESULT" == success ]] if [[ "$BUILD_COUNT" == 0 ]]; then [[ "$BUILD_RESULT" == skipped ]] else [[ "$BUILD_RESULT" == success ]] fi
check: strategy: matrix: runner: [ ubuntu-latest, macos-latest ] runs-on: ${{ matrix.runner }} steps: - uses: actions/checkout@v6.1.0 - uses: DeterminateSystems/nix-installer-action@v22 with: extra-conf: experimental-features = flakes nix-command pipe-operators
- name: Check flake run: nix -Lv flake check
discover: runs-on: ubuntu-latest permissions: contents: read actions: read outputs: matrix: ${{ steps.set.outputs.matrix }} count: ${{ steps.set.outputs.count }} steps: - uses: actions/checkout@v6.1.0 - uses: DeterminateSystems/nix-installer-action@v22 with: extra-conf: experimental-features = flakes nix-command pipe-operators - id: set env: GH_TOKEN: ${{ github.token }} FORCE_REBUILD: ${{ inputs.force-rebuild || false }} run: | records='[]' if [[ "$FORCE_REBUILD" != true ]]; then if ! records=$(gh api --paginate --slurp --method GET \ "repos/$GITHUB_REPOSITORY/actions/caches" \ -f ref=refs/heads/master -f key=package-build-success-v2- -f per_page=100 \ | jq '[.[].actions_caches[] | select(.ref == "refs/heads/master") | .key]'); then echo '::warning::Cannot read build records; building all packages' records='[]' fi fi # Evaluate a locked source with explicit arguments, without ambient files or environment. flake_ref=$(bash .github/workflows/flake-ref.sh) # Evaluation may build imported sources, so their derivations must be written. matrix=$(nix-instantiate --eval --strict --json --pure-eval --read-write-mode \ --argstr flakeRef "$flake_ref" --argstr successfulBuilds "$records" \ - < .github/workflows/package-runner-matrix.nix) echo "matrix=$matrix" >> "$GITHUB_OUTPUT" echo "count=$(jq length <<< "$matrix")" >> "$GITHUB_OUTPUT"
builds: needs: discover if: ${{ needs.discover.outputs.count != '0' }} strategy: matrix: build: ${{ fromJson(needs.discover.outputs.matrix) }} runs-on: ${{ matrix.build.runner }}
steps: - uses: actions/checkout@v6.1.0 - uses: DeterminateSystems/nix-installer-action@v22 with: extra-conf: experimental-features = flakes nix-command pipe-operators
- name: Build package env: PACKAGE: ${{ matrix.build.package }} SYSTEM: ${{ matrix.build.system }} DRV: ${{ matrix.build.drvPath }} run: | flake_ref=$(bash .github/workflows/flake-ref.sh) nix-build --pure-eval --argstr flakeRef "$flake_ref" \ --argstr system "$SYSTEM" --argstr package "$PACKAGE" \ - < .github/workflows/build-package.nix mkdir -p .ci-package-success printf '%s\n' "$DRV" > .ci-package-success/record
# Only successful builds on master may publish trusted evidence. The cache # contains a tiny marker, not Nix outputs; eviction merely causes rebuilds. - name: Record successful master build if: ${{ success() && github.ref == 'refs/heads/master' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }} continue-on-error: true uses: actions/cache/save@v4.3.0 with: path: .ci-package-success/record key: ${{ matrix.build.cacheKey }}