diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml index d99b0f1b75..e81b1af029 100644 --- a/.github/workflows/nix-build.yml +++ b/.github/workflows/nix-build.yml @@ -1,21 +1,38 @@ name: Nix package on: - # Run on every PR so nix-build can be required without skipped-check deadlocks. + # Run on every PR so required checks are never skipped by path filters. pull_request: branches: [main] push: branches: [main] + tags: ["v[0-9]*"] workflow_dispatch: +concurrency: + group: nix-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + jobs: - nix-build: + build: + name: Nix package (${{ matrix.system }}) timeout-minutes: 60 - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - system: x86_64-linux + runner: ubuntu-24.04 + - system: aarch64-linux + runner: ubuntu-24.04-arm + runs-on: ${{ matrix.runner }} permissions: contents: read + env: + # Manual runs on feature branches and all PRs only read the public cache. + CACHIX_PUBLISH: ${{ github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) }} steps: - name: Checkout uses: actions/checkout@v5 @@ -26,10 +43,27 @@ jobs: with: extra_nix_config: | experimental-features = nix-command flakes + - name: Check Cachix publishing credentials + if: vars.CACHIX_CACHE != '' && env.CACHIX_PUBLISH == 'true' + env: + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} + run: | + if [ -z "$CACHIX_AUTH_TOKEN" ]; then + echo "::error::Set the CACHIX_AUTH_TOKEN repository secret before enabling CACHIX_CACHE." + exit 1 + fi + - name: Set up Cachix + # Leave the variable unset until the public cache has been created. + if: vars.CACHIX_CACHE != '' + uses: cachix/cachix-action@v17 + with: + name: ${{ vars.CACHIX_CACHE }} + authToken: ${{ env.CACHIX_PUBLISH == 'true' && secrets.CACHIX_AUTH_TOKEN || '' }} + skipPush: ${{ env.CACHIX_PUBLISH != 'true' }} - name: Check the flake evaluates - run: nix flake check --no-build --all-systems + run: nix flake check --no-build --all-systems --no-update-lock-file - name: Build the desktop package - run: nix build .#fantasy-map-generator -L + run: nix build .#packages.${{ matrix.system }}.fantasy-map-generator --no-update-lock-file -L - name: Check the built app is complete run: | set -euo pipefail @@ -41,3 +75,15 @@ jobs: cmp package.json result/share/fantasy-map-generator/package.json version=$(jq -r .version result/share/fantasy-map-generator/package.json) echo "built fantasy-map-generator $version" + + nix-build: + if: always() + needs: build + runs-on: ubuntu-24.04 + permissions: + contents: read + steps: + - name: Check both architectures succeeded + env: + BUILD_RESULT: ${{ needs.build.result }} + run: test "$BUILD_RESULT" = success diff --git a/docs/nix.md b/docs/nix.md index 7e12f2d924..b9f76e9d03 100644 --- a/docs/nix.md +++ b/docs/nix.md @@ -87,6 +87,48 @@ nix build # result/ symlinks the built app working on the source, not a way to run the packaged app. See the Development section of the [README](../README.md). +## CI and the binary cache + +The [Nix package workflow](../.github/workflows/nix-build.yml) builds the Electron +desktop package on native `x86_64-linux` and `aarch64-linux` runners. It runs for +all pull requests targeting `main` and pushes to `main`, for release tags +matching `v[0-9]*`, and from **Actions → Nix package → Run workflow**. + +Builds work without Cachix configured. To enable publishing: + +1. Create a **public** cache in the [Cachix dashboard](https://app.cachix.org/), + using Cachix-managed signing keys. Choose any available cache name. +2. In that cache's settings, generate a token with write access to this cache. +3. In the GitHub repository's **Settings → Secrets and variables → Actions**, + add the token as a repository **secret** named `CACHIX_AUTH_TOKEN`, then add + the cache name as a repository **variable** named `CACHIX_CACHE`. +4. Once the workflow is on `main`, run **Nix package** manually against `main` + to populate the cache. Check both architecture jobs, including their Cachix + post-job upload steps. + +Pushes and manual runs on `main` or release tags publish newly built store +paths, including the app and its built dependencies. Pull requests (including +forks) and manual runs on feature branches can download from the public cache, +but receive no Cachix token and cannot upload. If `CACHIX_CACHE` is unset, +the Cachix steps are skipped; if it is set but the token is missing, publishing +runs fail with a setup error. See the +[Cachix action documentation](https://github.com/cachix/cachix-action) for its +upload behavior. + +To use the public `bazgaars-fmg` cache locally: + +```sh +nix run nixpkgs#cachix -- use bazgaars-fmg +nix run github:barrulus/Fantasy-Map-Generator +``` + +On NixOS, follow the configuration instructions printed by `cachix use` and +rebuild your system. The cache's public signing key and URL are also available +in its dashboard. Consumers of a public cache do not need the upload token. + +Cache hits require the same package inputs and architecture as CI. Overriding +the flake's nixpkgs input or changing the source may require a local build. + ## What you get A wrapper around nixpkgs' `electron_43` running the renderer built from this @@ -106,8 +148,9 @@ electron-builder, which means: ## Platform support -Linux only. `x86_64-linux` is what the package is built and tested on; -`aarch64-linux` is exposed and evaluates, but has not been run. +Linux only. CI builds and checks the package contents for `x86_64-linux` and +`aarch64-linux`; it does not launch the graphical app. Interactive testing has +been done on `x86_64-linux`, not on `aarch64-linux`. macOS is deliberately excluded. The package wraps a bare Electron binary, which is not a macOS `.app` bundle — the dock, the menu bar and file associations all