Skip to content

feat: enhance flake for build cache performance - #2649

Open
lamalex wants to merge 1 commit into
moonrepo:masterfrom
lamalex:feat/improve-flake
Open

feat: enhance flake for build cache performance#2649
lamalex wants to merge 1 commit into
moonrepo:masterfrom
lamalex:feat/improve-flake

Conversation

@lamalex

@lamalex lamalex commented Jul 31, 2026

Copy link
Copy Markdown
Contributor
  1. Adds Apple silicon to nix builds.
  2. Adds matrix build to CI for multiple archs.
  3. Adds binary caching for build speed up.

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

Copilot AI review requested due to automatic review settings July 31, 2026 16:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.nix to Crane and exposed a moon-deps output 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.

Comment thread flake.nix
Comment on lines +59 to 64
cargoFiles = pkgs.lib.fileset.unions [
./Cargo.toml
./Cargo.lock
./.cargo/config.toml
(craneLib.fileset.commonCargoSources ./crates)
];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@codspeed-hq

codspeed-hq Bot commented Jul 31, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 37.92%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 6 improved benchmarks
✅ 17 untouched benchmarks

Performance Changes

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)

Open in CodSpeed

@milesj

milesj commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

@lamalex Is cachix free? How does it work for OSS?

@lamalex

lamalex commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

@milesj Cachix offers 5gb of cache free for open source,

Users have a free 5 GB limit for open source projects and 20 Cachix Deploy agents.

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:

Artifact Compressed Cachix size
aarch64-darwin moon-deps 495 MiB
aarch64-darwin final package 14.5 MiB
aarch64-linux moon-deps 502 MiB
Expected x86_64-linux moon-deps About 500 MiB

@milesj

milesj commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

How long are builds without the cache?

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants