From 08d126feca13573f74accda7dcf961197591cc0c Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Mon, 9 Nov 2026 12:46:49 -0800 Subject: [PATCH 1/7] Add a setup-nix composite action for CI Consumers currently copy a setup-nix composite action into each repository. The three copies in wormhole, handoff and exosphere-zig have already drifted: different determinate-nix-action pins, different cache options, and copies that carry unrelated Zig cache steps. This action installs Nix and restores the devShell closure through nix-community/cache-nix-action. Measured on Depot runners, the restore takes 4 to 9 seconds against 24 to 31 seconds cold. DeterminateSystems/magic-nix-cache saves nothing there: the store uploads fail against the Actions cache API, and with Determinate Nix it subscribes to build events and caches nothing for substitution-only work. CI runs the action on both installer paths, and lints .github/ with zizmor and pinact. zizmor comes from its upstream action because nixpkgs carries 1.32.0, which does not build on either architecture. --- .github/actions/setup-nix/action.yml | 106 +++++++++++++++++++++++++++ .github/workflows/ci.yml | 82 +++++++++++++++++++++ AGENTS.md | 28 ++++++- README.md | 53 ++++++++++++++ flake.nix | 10 ++- 5 files changed, 277 insertions(+), 2 deletions(-) create mode 100644 .github/actions/setup-nix/action.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/actions/setup-nix/action.yml b/.github/actions/setup-nix/action.yml new file mode 100644 index 0000000..06c61b4 --- /dev/null +++ b/.github/actions/setup-nix/action.yml @@ -0,0 +1,106 @@ +name: Setup Nix +description: >- + Install Nix and restore the devShell closure from the Actions cache. + +inputs: + installer: + description: >- + Nix distribution to install: `determinate` (Determinate Nix) or + `upstream` (plain Nix). + default: determinate + cache: + description: >- + Restore and save the Nix store through the Actions cache. On Depot + runners the Actions cache is Depot Cache. + default: 'true' + primary-key: + description: >- + Cache key base. Empty derives one from the installer, runner OS and + architecture, and the digest of flake.lock. + default: '' + github-token: + description: >- + Token the Nix daemon uses for `github:` flake inputs (access-tokens in + nix.conf). The workflow token cannot read private sibling repositories, + so pass a bot token when the flake does. + default: ${{ github.token }} + git-auth-token: + description: >- + Token written into a global git `insteadOf` rewrite, for `git+https` + flake inputs from private repositories. Empty disables the rewrite. + default: '' + +outputs: + cache-hit: + description: >- + 'true' when the Nix store came from any cache entry, including a + partial match restored through the prefix. + value: ${{ steps.cache.outputs.hit }} + cache-key: + description: Cache key the store was saved under. + value: ${{ steps.cache.outputs.primary-key }} + +runs: + using: composite + steps: + - name: Validate installer + shell: bash + env: + INSTALLER: ${{ inputs.installer }} + run: | + set -euo pipefail + case "$INSTALLER" in + determinate | upstream) ;; + *) + echo "setup-nix: unsupported installer '$INSTALLER', expected determinate or upstream" >&2 + exit 1 + ;; + esac + + - name: Install Determinate Nix + if: ${{ inputs.installer == 'determinate' }} + uses: DeterminateSystems/determinate-nix-action@16f94ba7aae399b9f9077c254b6719ec6de7e3e3 # v3.24.2 + with: + summarize: false + github-token: ${{ inputs.github-token }} + + - name: Install upstream Nix + if: ${{ inputs.installer == 'upstream' }} + uses: DeterminateSystems/nix-installer-action@3138316df39ed29be04236d7ffc686fa525866aa # v23 + with: + summarize: false + determinate: false + github-token: ${{ inputs.github-token }} + + # Nix's git fetcher shells out to git, so it honours this rewrite. The + # daemon's `access-tokens` from the installer covers `github:` inputs and + # does not cover `git+https` inputs. + - name: Authenticate git for private flake inputs + if: ${{ inputs.git-auth-token != '' }} + shell: bash + env: + GIT_AUTH_TOKEN: ${{ inputs.git-auth-token }} + run: >- + git config --global + url."https://${GIT_AUTH_TOKEN}@github.com/".insteadOf + "https://github.com/" + + - name: Restore Nix store + id: cache + if: ${{ inputs.cache == 'true' }} + uses: nix-community/cache-nix-action@7df957e333c1e5da7721f60227dbba6d06080569 # v7.0.2 + with: + primary-key: >- + ${{ inputs.primary-key != '' && + inputs.primary-key || + format('nix-{0}-{1}-{2}-{3}', runner.os, runner.arch, inputs.installer, + hashFiles('**/flake.lock')) }} + # A cache miss after a flake.lock change still restores the previous + # store, so only the changed paths download. The entry is then saved + # under the new primary key. + restore-prefixes-first-match: >- + ${{ format('nix-{0}-{1}-{2}-', runner.os, runner.arch, + inputs.installer) }} + paths: | + ~/.cache/nix + /nix diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..38c752f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,82 @@ +name: CI + +on: + pull_request: + push: + branches: + - main + +permissions: {} + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + setup-nix: + name: setup-nix (${{ matrix.installer }}) + runs-on: ubuntu-latest + timeout-minutes: 20 + permissions: + contents: read + strategy: + fail-fast: false + matrix: + installer: + - determinate + - upstream + steps: + - name: Check out repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Setup Nix + id: nix + uses: $/.github/actions/setup-nix + with: + installer: ${{ matrix.installer }} + + - name: Check the devshell evaluates + run: nix develop .#dev --command nix --version + + - name: Report cache + env: + CACHE_HIT: ${{ steps.nix.outputs.cache-hit }} + CACHE_KEY: ${{ steps.nix.outputs.cache-key }} + run: echo "cache-hit=$CACHE_HIT key=$CACHE_KEY" + + actions-lint: + name: zizmor and pinact + runs-on: ubuntu-latest + timeout-minutes: 20 + permissions: + contents: read + steps: + - name: Check out repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + # The action, not the devshell: nixpkgs carries zizmor 1.32.0 and that + # package does not build on either architecture. Move this into the + # devshell once nixpkgs fixes it. + - name: zizmor + uses: zizmorcore/zizmor-action@45d7276c9ca790aabd705e31ca99c6185c3e76dd # v0.8.1 + with: + advanced-security: false + min-confidence: medium + version: 1.32.0 + + - name: Setup Nix + uses: $/.github/actions/setup-nix + + # --verify resolves every SHA back to its tag, and --min-age holds back + # releases younger than three days. Both read the GitHub API, so pass a + # token to stay clear of the anonymous rate limit. + - name: pinact + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + mapfile -t files < <(find .github -name '*.yml' -o -name '*.yaml') + nix develop .#dev --command pinact run --check --verify --min-age 3 "${files[@]}" diff --git a/AGENTS.md b/AGENTS.md index 2a09128..cdba5bb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,6 +6,7 @@ This repo (`planetscale/nix-devshell`) exports shared flake-parts modules consum ``` flake.nix # exports flakeModules, owns the dev shell for this repo +.github/actions/setup-nix/ # composite action consumers use in CI: install Nix + Actions cache modules/ base.nix # company-wide tools, sets systems via lib.mkDefault go.nix # Go toolchain, parameterized by version (mattware + version args) @@ -106,10 +107,35 @@ A module that only uses nixpkgs (no nix-devshell inputs needed) skips the first - **`x86_64-darwin` is not supported** — base sets `lib.mkDefault` to the three supported systems; consumers can restrict further for Linux-only projects - **`inputsFrom` does not propagate env vars or shellHook** — consumers needing shared config across multiple shells must use a `let mkDevShell = ...` pattern +## The setup-nix Action + +`.github/actions/setup-nix` installs Nix and restores the Nix store through +`nix-community/cache-nix-action`. Consumers pin it by SHA: + +```yaml +- uses: planetscale/nix-devshell/.github/actions/setup-nix@ # vX.Y.Z +``` + +Constraints that must not regress: + +- `magic-nix-cache-action` does not work on Depot runners. The store uploads + return 405 against the Actions cache API, and with Determinate Nix it + subscribes to build events and caches nothing for substitution-only work. + Every job stayed cold with it installed. Do not add it back. +- Every `run:` step in the composite takes its inputs through `env:`, never + through `${{ }}` interpolation, so zizmor's template-injection audit stays + quiet. +- All `uses:` in `.github/` stay SHA-pinned with a version comment. + `.github/workflows/ci.yml` enforces this with `pinact run --check --verify`. +- `pinact` comes from `devShells.dev`. `zizmor` does not: nixpkgs 1.32.0 fails + to build on both architectures (aws-lc-sys packaging), so CI runs + `zizmorcore/zizmor-action` instead. Move zizmor into `devShells.dev` once + nixpkgs fixes the package. + ## Dev Shell for This Repo ```bash nix develop # enters the base shell (default = devShells.base) -nix develop .#dev # treefmt wrapper (nixfmt, statix, deadnix) +nix develop .#dev # treefmt wrapper (nixfmt, statix, deadnix) plus pinact and zizmor nix flake check # runs treefmt check + validates all devShells ``` diff --git a/README.md b/README.md index 77fe45a..4519d49 100644 --- a/README.md +++ b/README.md @@ -75,3 +75,56 @@ leaves that file alone and the shell follows it as-is. The imported version provides `devShells.zig` (zig, matching zls, ziglint, zigdoc). - `nix` — Nix linting and formatting (nixfmt, statix, deadnix) - `queryPath` — Query Path team module + +## GitHub Actions + +The repository ships a composite action at `.github/actions/setup-nix`. It +installs Nix and restores the devShell closure from the Actions cache. On Depot +runners the Actions cache is Depot Cache. + +```yaml +jobs: + test: + runs-on: depot-ubuntu-24.04 + permissions: + contents: read + steps: + - uses: actions/checkout@ # v7.0.1 + with: + persist-credentials: false + + - uses: planetscale/nix-devshell/.github/actions/setup-nix@ # v0.1.0 + + - run: nix develop .#dev --command just test +``` + +Pin the action by SHA and keep the version in a comment. Renovate and pinact +update both. A job that uses the action needs no other Nix setup. + +### Inputs + +| Input | Default | Description | +| --- | --- | --- | +| `installer` | `determinate` | `determinate` installs Determinate Nix. `upstream` installs plain Nix. | +| `cache` | `true` | Restore and save the Nix store through the Actions cache. | +| `primary-key` | derived | Cache key. The default uses the installer, the runner OS and architecture, and the digest of `flake.lock`. | +| `github-token` | workflow token | Token for `github:` flake inputs. Pass a bot token when the flake reads private sibling repositories, because the workflow token cannot. | +| `git-auth-token` | empty | Token for a global git `insteadOf` rewrite. This covers `git+https` flake inputs from private repositories. | + +### Outputs + +| Output | Description | +| --- | --- | +| `cache-hit` | `true` when the Nix store came from a cache entry, including a partial match. | +| `cache-key` | Cache key the store was saved under. | + +### Cache behaviour + +The key contains the `flake.lock` digest. When the lock file changes, the action +restores the previous store through the key prefix and downloads only the paths +that changed. The job then saves a new entry under the new key. + +Measured on Depot runners, restoring one project devShell closure (3.3 GiB over +149 paths) takes 4 to 9 seconds. A cold download from cache.nixos.org takes 24 to +31 seconds. `DeterminateSystems/magic-nix-cache-action` gives no speedup on +Depot runners: the store uploads fail or never happen, so every job stays cold. diff --git a/flake.nix b/flake.nix index fc00932..ba6b446 100644 --- a/flake.nix +++ b/flake.nix @@ -70,7 +70,15 @@ devShells.dev = pkgs.mkShell { inputsFrom = [ config.devShells.nix ]; - packages = [ config.treefmt.build.wrapper ]; + packages = [ + config.treefmt.build.wrapper + # GitHub Actions auditing for this repo's .github/. Consumers do + # not need it, so it stays out of the shared modules. + # zizmor is absent on purpose: nixpkgs 1.32.0 fails to build on + # both architectures (aws-lc-sys packaging), so CI runs the + # upstream action instead. See AGENTS.md. + pkgs.pinact + ]; }; devShells.default = config.devShells.base; From b7cb20e9f5a760099e76b886c47fb619bc710b86 Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Mon, 9 Nov 2026 12:50:52 -0800 Subject: [PATCH 2/7] Disable store dedup and compute the cache key in a step The upstream-installer job restored a store where 58707 files were missing: Nix's store dedup turns duplicate files into hardlinks under /nix/store/.links, the Actions cache saves them as hardlink entries, and tar cannot restore an entry before its target. The restore dropped flake.nix along with the rest. Set `auto-optimise-store = false` on both installers so the store has no hardlinks to lose, and bump the key namespace to retire entries saved with dedup on. `nix-community/cache-nix-action` also leaves its own `primary-key` output empty, so compute the key and prefix in a step and read them from there. --- .github/actions/setup-nix/action.yml | 36 +++++++++++++++++++++------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/.github/actions/setup-nix/action.yml b/.github/actions/setup-nix/action.yml index 06c61b4..6f33433 100644 --- a/.github/actions/setup-nix/action.yml +++ b/.github/actions/setup-nix/action.yml @@ -38,7 +38,7 @@ outputs: value: ${{ steps.cache.outputs.hit }} cache-key: description: Cache key the store was saved under. - value: ${{ steps.cache.outputs.primary-key }} + value: ${{ steps.key.outputs.primary }} runs: using: composite @@ -63,6 +63,13 @@ runs: with: summarize: false github-token: ${{ inputs.github-token }} + # Nix's store dedup replaces duplicate files with hardlinks into + # /nix/store/.links. The Actions cache saves those as hardlink entries + # and tar cannot restore an entry before its target, so the restore + # drops the file. One upstream job lost 58707 files that way, flake.nix + # among them. Trade the store size for a restore that cannot lose data. + extra-conf: | + auto-optimise-store = false - name: Install upstream Nix if: ${{ inputs.installer == 'upstream' }} @@ -71,6 +78,8 @@ runs: summarize: false determinate: false github-token: ${{ inputs.github-token }} + extra-conf: | + auto-optimise-store = false # Nix's git fetcher shells out to git, so it honours this rewrite. The # daemon's `access-tokens` from the installer covers `github:` inputs and @@ -85,22 +94,31 @@ runs: url."https://${GIT_AUTH_TOKEN}@github.com/".insteadOf "https://github.com/" + - name: Compute cache key + id: key + if: ${{ inputs.cache == 'true' }} + shell: bash + env: + PRIMARY_KEY: ${{ inputs.primary-key }} + # The version segment retires entries saved with store dedup enabled; + # those restore hardlinks that tar drops on the floor. + PREFIX: ${{ format('nix-v2-{0}-{1}-{2}-', runner.os, runner.arch, inputs.installer) }} + LOCK: ${{ hashFiles('**/flake.lock') }} + run: | + set -euo pipefail + primary="${PRIMARY_KEY:-${PREFIX}${LOCK}}" + printf 'primary=%s\nprefix=%s\n' "$primary" "$PREFIX" >> "$GITHUB_OUTPUT" + - name: Restore Nix store id: cache if: ${{ inputs.cache == 'true' }} uses: nix-community/cache-nix-action@7df957e333c1e5da7721f60227dbba6d06080569 # v7.0.2 with: - primary-key: >- - ${{ inputs.primary-key != '' && - inputs.primary-key || - format('nix-{0}-{1}-{2}-{3}', runner.os, runner.arch, inputs.installer, - hashFiles('**/flake.lock')) }} + primary-key: ${{ steps.key.outputs.primary }} # A cache miss after a flake.lock change still restores the previous # store, so only the changed paths download. The entry is then saved # under the new primary key. - restore-prefixes-first-match: >- - ${{ format('nix-{0}-{1}-{2}-', runner.os, runner.arch, - inputs.installer) }} + restore-prefixes-first-match: ${{ steps.key.outputs.prefix }} paths: | ~/.cache/nix /nix From 134447d4c85c171af52de934de942dca0d29084a Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Mon, 9 Nov 2026 12:52:49 -0800 Subject: [PATCH 3/7] Pin nixpkgs to the last revision with a buildable zizmor zizmor 1.32.0 does not build on either architecture: aws-lc-sys asks for a system AWS-LC and the nixpkgs package does not provide one. Pin nixpkgs to 40c7d8751ffb, the last revision with 1.31.1, which builds and is in cache.nixos.org for x86_64-linux and aarch64-linux. That lets zizmor live in devShells.dev with pinact, so CI audits .github/ with the same tools a developer runs locally, and drops the zizmor action. A full revision in the URL, rather than the nixos-unstable branch, keeps the scheduled `nix flake update` from moving the pin. --- .github/workflows/ci.yml | 13 +++---------- AGENTS.md | 10 ++++++---- flake.lock | 8 ++++---- flake.nix | 16 +++++++++++----- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38c752f..b25a25b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,19 +58,12 @@ jobs: with: persist-credentials: false - # The action, not the devshell: nixpkgs carries zizmor 1.32.0 and that - # package does not build on either architecture. Move this into the - # devshell once nixpkgs fixes it. - - name: zizmor - uses: zizmorcore/zizmor-action@45d7276c9ca790aabd705e31ca99c6185c3e76dd # v0.8.1 - with: - advanced-security: false - min-confidence: medium - version: 1.32.0 - - name: Setup Nix uses: $/.github/actions/setup-nix + - name: zizmor + run: nix develop .#dev --command zizmor --format=plain --min-confidence=medium . + # --verify resolves every SHA back to its tag, and --min-age holds back # releases younger than three days. Both read the GitHub API, so pass a # token to stay clear of the anonymous rate limit. diff --git a/AGENTS.md b/AGENTS.md index cdba5bb..23ffc95 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -127,10 +127,12 @@ Constraints that must not regress: quiet. - All `uses:` in `.github/` stay SHA-pinned with a version comment. `.github/workflows/ci.yml` enforces this with `pinact run --check --verify`. -- `pinact` comes from `devShells.dev`. `zizmor` does not: nixpkgs 1.32.0 fails - to build on both architectures (aws-lc-sys packaging), so CI runs - `zizmorcore/zizmor-action` instead. Move zizmor into `devShells.dev` once - nixpkgs fixes the package. +- `pinact` and `zizmor` come from `devShells.dev`. zizmor only builds because + the `nixpkgs` input is pinned to a revision: 1.32.0 fails to build on both + architectures (aws-lc-sys wants a system AWS-LC that nixpkgs does not + provide). The pin is a full revision, not `nixos-unstable`, so `nix flake + update` leaves it alone. Move the pin forward only after checking that + zizmor builds and is in cache.nixos.org for both architectures. ## Dev Shell for This Repo diff --git a/flake.lock b/flake.lock index bd8eb0f..ee3b47d 100644 --- a/flake.lock +++ b/flake.lock @@ -41,17 +41,17 @@ }, "nixpkgs": { "locked": { - "lastModified": 1794042290, - "narHash": "sha256-ziZn2PvCJE5JEEpqTdxXwJpPB+L3YqoCpTAMCzyaP3U=", + "lastModified": 1793750615, + "narHash": "sha256-KgigjFBOYHIMiRavePsh6zp8L0DzEl7wT51v6GfY7hA=", "owner": "nixos", "repo": "nixpkgs", - "rev": "f4a03c008967841f2a0b3cb7c436fc6fc31671f6", + "rev": "40c7d8751ffb8d9faad086757b83d9ba7669a7b3", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixos-unstable", "repo": "nixpkgs", + "rev": "40c7d8751ffb8d9faad086757b83d9ba7669a7b3", "type": "github" } }, diff --git a/flake.nix b/flake.nix index ba6b446..011c4a7 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,12 @@ { inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + # Pinned to a revision, not nixos-unstable: zizmor 1.32.0 (the next + # nixpkgs bump) does not build on either architecture, because aws-lc-sys + # asks for a system AWS-LC that the nixpkgs package does not provide. This + # is the last revision with zizmor 1.31.1, which builds and is in + # cache.nixos.org for x86_64-linux and aarch64-linux. A revision pin also + # keeps `nix flake update` from moving it. + nixpkgs.url = "github:nixos/nixpkgs/40c7d8751ffb8d9faad086757b83d9ba7669a7b3"; flake-parts.url = "github:hercules-ci/flake-parts"; mattware = { url = "github:mattrobenolt/nixpkgs"; @@ -73,11 +79,11 @@ packages = [ config.treefmt.build.wrapper # GitHub Actions auditing for this repo's .github/. Consumers do - # not need it, so it stays out of the shared modules. - # zizmor is absent on purpose: nixpkgs 1.32.0 fails to build on - # both architectures (aws-lc-sys packaging), so CI runs the - # upstream action instead. See AGENTS.md. + # not need these, so they stay out of the shared modules. zizmor + # builds because the nixpkgs input is pinned to the last + # revision before 1.32.0. pkgs.pinact + pkgs.zizmor ]; }; From 447350dc7f9cf04013457fbef80fe5764f3b5e6f Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Mon, 9 Nov 2026 13:20:01 -0800 Subject: [PATCH 4/7] Use cachix/install-nix-action and drop the installer choice The action had an `installer` input choosing between Determinate Nix and plain Nix. That was the wrong shape: the point is one way to set up Nix, and the measurement picked the winner. cachix/install-nix-action installs in 2-4s on Depot against 4-8s for determinate-nix-action. It also pins `install_url` to nix-2.35.4, so every repository runs the same Nix instead of following the latest release. pinact and Renovate do not track that line, so a bump is deliberate. The `auto-optimise-store = false` setting moves to `extra_nix_config`, which is where cachix/install-nix-action takes it. --- .github/actions/setup-nix/action.yml | 56 +++++++--------------------- .github/workflows/ci.yml | 10 +---- README.md | 7 +++- 3 files changed, 19 insertions(+), 54 deletions(-) diff --git a/.github/actions/setup-nix/action.yml b/.github/actions/setup-nix/action.yml index 6f33433..d0b8f24 100644 --- a/.github/actions/setup-nix/action.yml +++ b/.github/actions/setup-nix/action.yml @@ -3,11 +3,6 @@ description: >- Install Nix and restore the devShell closure from the Actions cache. inputs: - installer: - description: >- - Nix distribution to install: `determinate` (Determinate Nix) or - `upstream` (plain Nix). - default: determinate cache: description: >- Restore and save the Nix store through the Actions cache. On Depot @@ -15,8 +10,8 @@ inputs: default: 'true' primary-key: description: >- - Cache key base. Empty derives one from the installer, runner OS and - architecture, and the digest of flake.lock. + Cache key base. Empty derives one from the runner OS and architecture + and the digest of flake.lock. default: '' github-token: description: >- @@ -43,42 +38,19 @@ outputs: runs: using: composite steps: - - name: Validate installer - shell: bash - env: - INSTALLER: ${{ inputs.installer }} - run: | - set -euo pipefail - case "$INSTALLER" in - determinate | upstream) ;; - *) - echo "setup-nix: unsupported installer '$INSTALLER', expected determinate or upstream" >&2 - exit 1 - ;; - esac - - - name: Install Determinate Nix - if: ${{ inputs.installer == 'determinate' }} - uses: DeterminateSystems/determinate-nix-action@16f94ba7aae399b9f9077c254b6719ec6de7e3e3 # v3.24.2 + - name: Install Nix + uses: cachix/install-nix-action@75c75c31ebece974e48ebc36b4ad125bd97bd97b # 31.11.3 with: - summarize: false - github-token: ${{ inputs.github-token }} + github_access_token: ${{ inputs.github-token }} + # Pinned so every repository runs the same Nix. Bump this line + # deliberately; pinact and Renovate do not track it. + install_url: https://releases.nixos.org/nix/nix-2.35.4/install # Nix's store dedup replaces duplicate files with hardlinks into - # /nix/store/.links. The Actions cache saves those as hardlink entries - # and tar cannot restore an entry before its target, so the restore - # drops the file. One upstream job lost 58707 files that way, flake.nix + # /nix/store/.links. The Actions cache saves those as hardlink + # entries, and tar cannot restore an entry before its target, so the + # restore drops the file. One job lost 58707 files that way, flake.nix # among them. Trade the store size for a restore that cannot lose data. - extra-conf: | - auto-optimise-store = false - - - name: Install upstream Nix - if: ${{ inputs.installer == 'upstream' }} - uses: DeterminateSystems/nix-installer-action@3138316df39ed29be04236d7ffc686fa525866aa # v23 - with: - summarize: false - determinate: false - github-token: ${{ inputs.github-token }} - extra-conf: | + extra_nix_config: | auto-optimise-store = false # Nix's git fetcher shells out to git, so it honours this rewrite. The @@ -100,9 +72,7 @@ runs: shell: bash env: PRIMARY_KEY: ${{ inputs.primary-key }} - # The version segment retires entries saved with store dedup enabled; - # those restore hardlinks that tar drops on the floor. - PREFIX: ${{ format('nix-v2-{0}-{1}-{2}-', runner.os, runner.arch, inputs.installer) }} + PREFIX: ${{ format('nix-v2-{0}-{1}-', runner.os, runner.arch) }} LOCK: ${{ hashFiles('**/flake.lock') }} run: | set -euo pipefail diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b25a25b..0d1560b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,17 +14,11 @@ concurrency: jobs: setup-nix: - name: setup-nix (${{ matrix.installer }}) + name: setup-nix runs-on: ubuntu-latest timeout-minutes: 20 permissions: contents: read - strategy: - fail-fast: false - matrix: - installer: - - determinate - - upstream steps: - name: Check out repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -34,8 +28,6 @@ jobs: - name: Setup Nix id: nix uses: $/.github/actions/setup-nix - with: - installer: ${{ matrix.installer }} - name: Check the devshell evaluates run: nix develop .#dev --command nix --version diff --git a/README.md b/README.md index 4519d49..6ce71bc 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,8 @@ update both. A job that uses the action needs no other Nix setup. | Input | Default | Description | | --- | --- | --- | -| `installer` | `determinate` | `determinate` installs Determinate Nix. `upstream` installs plain Nix. | | `cache` | `true` | Restore and save the Nix store through the Actions cache. | -| `primary-key` | derived | Cache key. The default uses the installer, the runner OS and architecture, and the digest of `flake.lock`. | +| `primary-key` | derived | Cache key. The default uses the runner OS and architecture and the digest of `flake.lock`. | | `github-token` | workflow token | Token for `github:` flake inputs. Pass a bot token when the flake reads private sibling repositories, because the workflow token cannot. | | `git-auth-token` | empty | Token for a global git `insteadOf` rewrite. This covers `git+https` flake inputs from private repositories. | @@ -124,6 +123,10 @@ The key contains the `flake.lock` digest. When the lock file changes, the action restores the previous store through the key prefix and downloads only the paths that changed. The job then saves a new entry under the new key. +The action installs one Nix version for every repository: `install_url` is +pinned to a release, and it does not follow the latest Nix. Bump that line when +you mean to move the org. + Measured on Depot runners, restoring one project devShell closure (3.3 GiB over 149 paths) takes 4 to 9 seconds. A cold download from cache.nixos.org takes 24 to 31 seconds. `DeterminateSystems/magic-nix-cache-action` gives no speedup on From c318f9319873bac15c3e31d875aacef9cf1b1a24 Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Mon, 9 Nov 2026 13:39:22 -0800 Subject: [PATCH 5/7] Test whether auto-optimise-store is still needed under plain Nix --- .github/actions/setup-nix/action.yml | 9 +-------- .github/workflows/ci.yml | 6 ++++++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/actions/setup-nix/action.yml b/.github/actions/setup-nix/action.yml index d0b8f24..50b0e70 100644 --- a/.github/actions/setup-nix/action.yml +++ b/.github/actions/setup-nix/action.yml @@ -45,13 +45,6 @@ runs: # Pinned so every repository runs the same Nix. Bump this line # deliberately; pinact and Renovate do not track it. install_url: https://releases.nixos.org/nix/nix-2.35.4/install - # Nix's store dedup replaces duplicate files with hardlinks into - # /nix/store/.links. The Actions cache saves those as hardlink - # entries, and tar cannot restore an entry before its target, so the - # restore drops the file. One job lost 58707 files that way, flake.nix - # among them. Trade the store size for a restore that cannot lose data. - extra_nix_config: | - auto-optimise-store = false # Nix's git fetcher shells out to git, so it honours this rewrite. The # daemon's `access-tokens` from the installer covers `github:` inputs and @@ -72,7 +65,7 @@ runs: shell: bash env: PRIMARY_KEY: ${{ inputs.primary-key }} - PREFIX: ${{ format('nix-v2-{0}-{1}-', runner.os, runner.arch) }} + PREFIX: ${{ format('nix-v3-{0}-{1}-', runner.os, runner.arch) }} LOCK: ${{ hashFiles('**/flake.lock') }} run: | set -euo pipefail diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d1560b..eba9e4e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,12 @@ jobs: - name: Check the devshell evaluates run: nix develop .#dev --command nix --version + - name: Report dedup state + run: | + nix show-config | grep -i auto-optimise-store || echo "auto-optimise-store: unset" + echo "links dir: $(ls /nix/store/.links 2>/dev/null | wc -l) files" + find /nix/store -maxdepth 2 -type f -links +1 2>/dev/null | wc -l + - name: Report cache env: CACHE_HIT: ${{ steps.nix.outputs.cache-hit }} From 833fdf953448dd45e1fa0278cb061ff5364c6407 Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Mon, 9 Nov 2026 13:42:36 -0800 Subject: [PATCH 6/7] Keep nixpkgs on the branch and pin the revision in flake.lock The input URL is `nixos-unstable` again. The working revision stays in flake.lock's `locked` node, which is where a pin belongs. The scheduled flake update now names the three inputs it may move, so the nixpkgs pin survives the night. It used `nix flake update` with no arguments, which would have moved nixpkgs to HEAD and brought back the zizmor build failure. Also drops the temporary dedup diagnostic from CI. --- .github/workflows/ci.yml | 6 ------ .github/workflows/update-flake-lock.yml | 5 ++++- flake.lock | 2 +- flake.nix | 8 +------- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eba9e4e..0d1560b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,12 +32,6 @@ jobs: - name: Check the devshell evaluates run: nix develop .#dev --command nix --version - - name: Report dedup state - run: | - nix show-config | grep -i auto-optimise-store || echo "auto-optimise-store: unset" - echo "links dir: $(ls /nix/store/.links 2>/dev/null | wc -l) files" - find /nix/store -maxdepth 2 -type f -links +1 2>/dev/null | wc -l - - name: Report cache env: CACHE_HIT: ${{ steps.nix.outputs.cache-hit }} diff --git a/.github/workflows/update-flake-lock.yml b/.github/workflows/update-flake-lock.yml index 8206dd7..07f84c4 100644 --- a/.github/workflows/update-flake-lock.yml +++ b/.github/workflows/update-flake-lock.yml @@ -18,8 +18,11 @@ jobs: - name: Install Nix uses: DeterminateSystems/determinate-nix-action@bafaa638b9d5ec0e7e3ac1a7fc80453ef1fd265f # v3.20.0 + # nixpkgs stays put: the locked revision is the last one whose zizmor + # builds on both architectures. Update it by hand, with `nix flake lock + # --update-input nixpkgs`, after checking that. See AGENTS.md. - name: Update flake.lock - run: nix flake update + run: nix flake update flake-parts mattware treefmt-nix - name: Validate flake run: nix flake check diff --git a/flake.lock b/flake.lock index ee3b47d..a3e9076 100644 --- a/flake.lock +++ b/flake.lock @@ -50,8 +50,8 @@ }, "original": { "owner": "nixos", + "ref": "nixos-unstable", "repo": "nixpkgs", - "rev": "40c7d8751ffb8d9faad086757b83d9ba7669a7b3", "type": "github" } }, diff --git a/flake.nix b/flake.nix index 011c4a7..6be06f9 100644 --- a/flake.nix +++ b/flake.nix @@ -1,12 +1,6 @@ { inputs = { - # Pinned to a revision, not nixos-unstable: zizmor 1.32.0 (the next - # nixpkgs bump) does not build on either architecture, because aws-lc-sys - # asks for a system AWS-LC that the nixpkgs package does not provide. This - # is the last revision with zizmor 1.31.1, which builds and is in - # cache.nixos.org for x86_64-linux and aarch64-linux. A revision pin also - # keeps `nix flake update` from moving it. - nixpkgs.url = "github:nixos/nixpkgs/40c7d8751ffb8d9faad086757b83d9ba7669a7b3"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; flake-parts.url = "github:hercules-ci/flake-parts"; mattware = { url = "github:mattrobenolt/nixpkgs"; From 72969ae1c1c18c31f14e3905ec9543f5afeffe83 Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Mon, 9 Nov 2026 13:43:45 -0800 Subject: [PATCH 7/7] State only the measured magic-nix-cache result The note claimed a mechanism for the Determinate Nix arm and an authorization conclusion from a control that ran on the wrong arm. Keep the numbers and name what is untested. --- AGENTS.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 23ffc95..4b3dddc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -118,10 +118,16 @@ A module that only uses nixpkgs (no nix-devshell inputs needed) skips the first Constraints that must not regress: -- `magic-nix-cache-action` does not work on Depot runners. The store uploads - return 405 against the Actions cache API, and with Determinate Nix it - subscribes to build events and caches nothing for substitution-only work. - Every job stayed cold with it installed. Do not add it back. +- `magic-nix-cache-action` is no faster than no cache on Depot runners. Measured + with all three installers, a warm `nix develop` took 29 to 32 seconds, the + same as a cold one. With plain Nix every store upload fails with + `405 Method Not Allowed`, once per path. With Determinate Nix the action + reports `Subscribing to Determinate Nixd build events` and logs no uploads at + all. `cache-nix-action` restores in 4 to 9 seconds and leaves `nix develop` + at under a second, so use that instead. + + Untested: whether `permissions: actions: write` changes the 405, and why + Determinate Nix logs no uploads. Do not restate either as fact. - Every `run:` step in the composite takes its inputs through `env:`, never through `${{ }}` interpolation, so zizmor's template-injection audit stays quiet.