feat: enhance flake for build cache performance - #2649
Conversation
There was a problem hiding this comment.
Pull request overview
Enhances the repository’s Nix flake and CI workflow to improve build performance via binary caching and to expand build coverage to additional architectures (including Apple Silicon).
Changes:
- Added Cachix binary cache configuration to the flake and CI, and updated docs accordingly.
- Migrated the Rust build in
flake.nixto Crane and exposed amoon-depsoutput for cache warming. - Updated CI to run a matrix build across Linux x86_64, Linux aarch64, and macOS aarch64 runners.
Reviewed changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| flake.nix | Adds Cachix config, introduces Crane-based Rust packaging, adds aarch64-darwin, and exports moon-deps. |
| flake.lock | Pins the new Crane input and wires it into the flake inputs. |
| docs/NIX.md | Updates Nix docs for new outputs, caching behavior, and CI expectations. |
| .gitignore | Ignores Nix build outputs (result*) and .direnv/. |
| .github/workflows/nix.yml | Converts Nix CI to a multi-arch matrix and configures Cachix usage/push behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| cargoFiles = pkgs.lib.fileset.unions [ | ||
| ./Cargo.toml | ||
| ./Cargo.lock | ||
| ./.cargo/config.toml | ||
| (craneLib.fileset.commonCargoSources ./crates) | ||
| ]; |
There was a problem hiding this comment.
This is intentional. craneLib.buildDepsOnly internally uses mkDummySrc, which replaces workspace sources and build scripts while compiling external dependencies. The real workspace crates and their compile-time assets are rebuilt by buildPackage using the broader source fileset.
Keeping these assets out of cargoSource prevents template, protobuf, grammar, or embedded WASM changes from unnecessarily invalidating the dependency artifact.
This has been verified with successful full moon-deps builds on Linux and Darwin, followed by a successful full aarch64-darwin package build.
Merging this PR will improve performance by 37.92%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | WallTime | track_tasks_async[1000] |
1,157 ms | 779.7 ms | +48.39% |
| ⚡ | WallTime | track_tasks_async[100] |
118.3 ms | 80.7 ms | +46.59% |
| ⚡ | WallTime | track_tasks_sync[1000] |
7 s | 5.2 s | +34.41% |
| ⚡ | WallTime | track_tasks_sync[100] |
701.8 ms | 522.2 ms | +34.39% |
| ⚡ | WallTime | track_tasks_async[10] |
43.4 ms | 32.8 ms | +32.38% |
| ⚡ | WallTime | track_tasks_sync[10] |
106.2 ms | 80.3 ms | +32.32% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing lamalex:feat/improve-flake (8bcca38) with master (772b9cf)
|
@lamalex Is cachix free? How does it work for OSS? |
|
@milesj Cachix offers 5gb of cache free for open source,
note that deploy agents aren't relevant for our simple binary cache case 5gb should cover mac, arm64 linux, and x86 linux cacheing for a few generations this is what i'm seeing with those arch's built on my machine:
|
|
How long are builds without the cache? |
Logistical item: I'm the owner of the Cachix binary cache. That should probably be moved to be owned by the moonrepo org and the cache token needs set as a repo secret for CI builds to be pushed to the cache