From a19316451c65eb71a13d457fbe8f035a2e446137 Mon Sep 17 00:00:00 2001 From: Typas Liao Date: Sun, 26 Apr 2026 09:48:43 +0800 Subject: [PATCH 1/3] ci(mac): cache nix store between runs Repeated runs re-download the same Nix packages from cache.nixos.org every time, adding ~2m to the mac job. Cache the store keyed on init.sh's hash so subsequent runs find packages already present. A fallback prefix allows partial hits when only some deps changed. Store is capped at 1 GiB to stay within GHA cache limits. Co-Authored-By: Claude --- .github/workflows/bootstrap.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bootstrap.yml b/.github/workflows/bootstrap.yml index 37b3d69..9cf839b 100644 --- a/.github/workflows/bootstrap.yml +++ b/.github/workflows/bootstrap.yml @@ -57,7 +57,7 @@ jobs: - uses: ./.github/actions/mac-nix-setup with: github-token: ${{ secrets.GITHUB_TOKEN }} - - uses: nix-community/cache-nix-action@v6 + - uses: nix-community/cache-nix-action@v7 with: primary-key: nix-${{ runner.os }}-${{ hashFiles('init.sh') }} restore-prefixes-first-match: nix-${{ runner.os }}- From b46292240a221ea7ec57e228ce921154f642498d Mon Sep 17 00:00:00 2001 From: Typas Liao Date: Sun, 26 Apr 2026 09:57:48 +0800 Subject: [PATCH 2/3] ci(mac): fix nix cache key, add flake input cache, raise size cap Three issues made the cache ineffective: the key hashed init.sh but not flake.lock, so nix-darwin rebuilds from a nixpkgs update would reuse stale cache entries and miss when flake.lock changed. Flake input tarballs (~/.cache/nix) were not cached, so nixpkgs was re-downloaded every run regardless of store hits. The 1 GiB cap was too small for a full nix-darwin activation, causing evictions that forced re-downloads on the next run. Raised to 5 GiB to stay within the 10 GiB per-repo GitHub cache quota. Co-Authored-By: Claude --- .github/workflows/bootstrap.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bootstrap.yml b/.github/workflows/bootstrap.yml index 9cf839b..8f3b350 100644 --- a/.github/workflows/bootstrap.yml +++ b/.github/workflows/bootstrap.yml @@ -59,9 +59,11 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} - uses: nix-community/cache-nix-action@v7 with: - primary-key: nix-${{ runner.os }}-${{ hashFiles('init.sh') }} + primary-key: nix-${{ runner.os }}-${{ hashFiles('flake.lock', 'init.sh') }} restore-prefixes-first-match: nix-${{ runner.os }}- - gc-max-store-size-macos: 1073741824 + paths-macos: | + ~/.cache/nix + gc-max-store-size-macos: 5368709120 - name: bash init.sh run: | # shellcheck disable=SC1091 From b2f4eaf99b68b693fa9b0b6ab30cad0d4622d6ce Mon Sep 17 00:00:00 2001 From: Typas Liao Date: Sun, 26 Apr 2026 10:07:27 +0800 Subject: [PATCH 3/3] ci(mac): add nix to GITHUB_PATH so post-run steps can find it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cache-nix-action's post-job step runs nix --version to calculate store size before saving. Because mac-nix-setup never wrote to GITHUB_PATH, nix was absent from PATH in the post-run environment, causing an exit 127 that silently skipped the cache save — meaning the cache was never populated and every run stayed slow. Writing /nix/var/nix/profiles/default/bin to GITHUB_PATH persists nix across all subsequent steps and post-run hooks. The explicit profile source in bash init.sh is no longer needed and is removed. Co-Authored-By: Claude --- .github/actions/mac-nix-setup/action.yml | 1 + .github/workflows/bootstrap.yml | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/actions/mac-nix-setup/action.yml b/.github/actions/mac-nix-setup/action.yml index 65dae39..090efeb 100644 --- a/.github/actions/mac-nix-setup/action.yml +++ b/.github/actions/mac-nix-setup/action.yml @@ -29,3 +29,4 @@ runs: for f in /etc/bashrc /etc/zshrc; do test -e "$f" && sudo mv "$f" "$f.before-nix-darwin" done + echo "/nix/var/nix/profiles/default/bin" >> "$GITHUB_PATH" diff --git a/.github/workflows/bootstrap.yml b/.github/workflows/bootstrap.yml index 8f3b350..442ea57 100644 --- a/.github/workflows/bootstrap.yml +++ b/.github/workflows/bootstrap.yml @@ -65,7 +65,4 @@ jobs: ~/.cache/nix gc-max-store-size-macos: 5368709120 - name: bash init.sh - run: | - # shellcheck disable=SC1091 - . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh - bash init.sh + run: bash init.sh