Skip to content

ci: cache gnu32 nix store#256

Open
Sjors wants to merge 1 commit intobitcoin-core:masterfrom
Sjors:2026/03/nix-cache
Open

ci: cache gnu32 nix store#256
Sjors wants to merge 1 commit intobitcoin-core:masterfrom
Sjors:2026/03/nix-cache

Conversation

@Sjors
Copy link
Member

@Sjors Sjors commented Mar 12, 2026

gnu32 is by far the slowest ci job and it spends most of it's time building Nix stuff.

Caching the Nix store drops subsequent runs to just 3 minutes.

Not caching the other ones, because the cache is quite large and Github limits us to 10GB total.

Using https://github.com/nix-community/cache-nix-action

Closes #254

@DrahtBot
Copy link

DrahtBot commented Mar 12, 2026

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

@Sjors Sjors force-pushed the 2026/03/nix-cache branch from 915a7f8 to 7aa3271 Compare March 12, 2026 13:42
@Sjors
Copy link
Member Author

Sjors commented Mar 12, 2026

@ryanofsky can you whitelist nix-community/cache-nix-action@v7?

@ryanofsky
Copy link
Collaborator

@ryanofsky can you whitelist nix-community/cache-nix-action@v7?

Thanks, added. This sorry for the delay. If there is a way we could give you github permissions to change these settings that would seem nice too

@Sjors
Copy link
Member Author

Sjors commented Mar 12, 2026

There's no rush and I don't expect to have to make many such changes. Basic ccache and more tailored nix cache should do the trick.

@Sjors
Copy link
Member Author

Sjors commented Mar 12, 2026

About 800 MB, not too bad:
Scherm­afbeelding 2026-03-12 om 20 20 26

Runtime was 60 minutes. I'm going to amend the commit (date) to trigger a re-run which should use this cache...

@Sjors Sjors force-pushed the 2026/03/nix-cache branch 2 times, most recently from 3fa8a2c to 34da50f Compare March 12, 2026 19:54
@Sjors
Copy link
Member Author

Sjors commented Mar 12, 2026

Looks like the cache got trimmed the first write. Trying again.

This push to 34da50f is not expected to be substantially faster, the next push should be.

@Sjors
Copy link
Member Author

Sjors commented Mar 12, 2026

Depsite the incomplete cache it ran in only 30 minutes. The new cache entry is 1.7 GB. Let's run it again...

@Sjors Sjors force-pushed the 2026/03/nix-cache branch from 34da50f to 6dc9700 Compare March 12, 2026 20:35
if: matrix.config == 'gnu32'
uses: nix-community/cache-nix-action@v7
with:
primary-key: nix-${{ runner.os }}-${{ matrix.config }}-${{ env.NIXPKGS_CHANNEL }}-${{ hashFiles('shell.nix', 'ci/patches/*.patch', 'ci/configs/gnu32.bash') }}-${{ github.sha }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to drop -${{ github.sha }} so our cache won't get flushed as often.

@Sjors
Copy link
Member Author

Sjors commented Mar 12, 2026

Down to 3 minutes, nice!

@Sjors Sjors marked this pull request as ready for review March 12, 2026 20:41
@Sjors Sjors force-pushed the 2026/03/nix-cache branch from 6dc9700 to e734375 Compare March 12, 2026 21:14
@Sjors
Copy link
Member Author

Sjors commented Mar 12, 2026

Trying a different caching approach, using the latest nix channel commit - which doesn't change that often for nixos-25.05. It should now save the cache only once.

If it can't get an exact match it will try a broader match, so IIUC even if something in nix changes from under us, we might still get some benefit out of earlier cache entries. Once the build succeeds, it produces a fresh one that's then used in subsequent runs.

@Sjors Sjors force-pushed the 2026/03/nix-cache branch 2 times, most recently from 7664d7c to 76d3e51 Compare March 12, 2026 21:27
@Sjors Sjors marked this pull request as draft March 12, 2026 21:28
@Sjors Sjors force-pushed the 2026/03/nix-cache branch from 76d3e51 to 6562d22 Compare March 12, 2026 21:35
@Sjors
Copy link
Member Author

Sjors commented Mar 12, 2026

Alright, 76d3e51 created a new entry nix-Linux-gnu32-ac62194c3917d5f474c1a844b6fd6da2db95077d-67a1dfa5824ce68902b067211c47c342ba705ad71d773f96e6885ba6d3defc3e which the next run should reuse and not resave.

Pushed an amended date commit 6562d22 to test that.

@Sjors
Copy link
Member Author

Sjors commented Mar 12, 2026

As expected, the last gnu32 CI run found a match for the primary key and did not re-save it.

https://github.com/bitcoin-core/libmultiprocess/actions/runs/23025035895/job/66870747483?pr=256

Runtime slightly under 3 minutes.

So this should be good to go now.

@Sjors Sjors marked this pull request as ready for review March 12, 2026 21:39

# Use an explicit save step instead of the action post-step so we only
# archive the store after the build succeeded and the shell closure is
# rooted against the save-time garbage collection pass.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what "shell closure is rooted against the save-time garbage collection pass" means, so it would be good for someone who knows Nix to sanity check this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: cache nix store

3 participants