Skip to content

Commit c65b8ea

Browse files
committed
ci(cache): scope macOS Nix cache key by target arch
The arm64 and x64 macOS native packages both build on the same arm64 Blacksmith runner (x64 cross-compiles via the multi-arch Apple SDK), so runner.os and runner.arch are identical for both jobs. They therefore shared a single cache-nix-action key (`nix-macOS-ARM64-<hash>`) and clobbered each other's restored store on every run, leaving the Intel build effectively uncached. Thread a `cache-key-suffix` input through setup-nix into setup-macos-nix-cache and pass the target arch from build-macos-nix-native-package, so build-mac-arm64 and build-mac-x64 get independent cache entries.
1 parent 7bcafc9 commit c65b8ea

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎.github/actions/build-macos-nix-native-package/action.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ runs:
1111
using: composite
1212
steps:
1313
- uses: ./.github/actions/setup-nix
14+
with:
15+
# arm64 and x64 both run on the same arm64 runner, so scope the macOS
16+
# Nix cache by target arch to stop the two builds clobbering one store.
17+
cache-key-suffix: ${{ inputs.arch }}
1418

1519
- name: Build macOS binary
1620
shell: bash
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
name: Setup macOS Nix cache
22
description: Restore and save the macOS Nix store with the original Nix cache action
3+
inputs:
4+
key-suffix:
5+
description: >
6+
Extra suffix to scope the cache key. The arm64 and x64 macOS builds run on
7+
the same arm64 runner (same runner.os/runner.arch), so without this they
8+
would share one key and clobber each other's store.
9+
default: ''
310
runs:
411
using: composite
512
steps:
613
- name: Cache macOS Nix store
714
uses: nix-community/cache-nix-action@7df957e333c1e5da7721f60227dbba6d06080569 # v7.0.2
815
with:
9-
primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('flake.lock', 'flake.nix', 'default.nix', 'package.nix', 'package.json', 'nix/**/*.nix', 'rust-toolchain.toml', 'rust/Cargo.lock', 'rust/**/Cargo.toml') }}
10-
restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }}-
16+
primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ inputs.key-suffix }}-${{ hashFiles('flake.lock', 'flake.nix', 'default.nix', 'package.nix', 'package.json', 'nix/**/*.nix', 'rust-toolchain.toml', 'rust/Cargo.lock', 'rust/**/Cargo.toml') }}
17+
restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }}-${{ inputs.key-suffix }}-
1118
gc-max-store-size-macos: 3500000000
1219
purge: true
13-
purge-prefixes: nix-${{ runner.os }}-${{ runner.arch }}-
20+
purge-prefixes: nix-${{ runner.os }}-${{ runner.arch }}-${{ inputs.key-suffix }}-
1421
purge-created: 172800
1522
purge-primary-key: never

‎.github/actions/setup-nix/action.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: Setup Nix
22
description: Install Nix with platform-specific cache setup
3+
inputs:
4+
cache-key-suffix:
5+
description: Extra suffix to scope the macOS Nix cache key (e.g. cross target arch)
6+
default: ''
37
runs:
48
using: composite
59
steps:

0 commit comments

Comments
 (0)