Kan 209/integrate crane for faster nix builds#170
Open
fulsomenko wants to merge 6 commits intodevelopfrom
Open
Kan 209/integrate crane for faster nix builds#170fulsomenko wants to merge 6 commits intodevelopfrom
fulsomenko wants to merge 6 commits intodevelopfrom
Conversation
Add crane input and create craneLib instance that uses our rust-overlay toolchain. Pass craneLib to package builds to enable dependency caching. This sets up the infrastructure for faster incremental builds by separating dependency compilation from source compilation.
Replace rustPlatform.buildRustPackage with crane's buildPackage and buildDepsOnly. This separates dependency compilation from source compilation, enabling Nix to cache dependencies independently. Changes: - Use craneLib.buildDepsOnly to build dependencies in separate derivation - Use craneLib.buildPackage for final binary build - Add custom source filter for Rust files, TOML, and Cargo.lock - Replace cargoBuildFlags with cargoExtraArgs (crane convention) Build time improvements: - First build: ~2-3 min (dependencies + source) - Incremental builds: ~55 sec (source only, reuses cached deps) - Previous: ~5 min for every rebuild
Replace rustPlatform.buildRustPackage with crane's buildPackage and buildDepsOnly for the MCP server package. Changes: - Use craneLib.buildDepsOnly for dependency caching - Use craneLib.buildPackage for final binary - Add source filter to include only Rust/TOML/lock files - Replace cargoBuildFlags/cargoTestFlags with cargoExtraArgs/cargoTestExtraArgs The dependency derivation is cached separately, so source-only changes rebuild quickly while dependency changes are also cached efficiently.
Add crane flake input lock entry from ipetkov/crane repository.
3e878eb to
c1d6786
Compare
Replace cargo build with nix build in CI to benefit from Crane's dependency caching. This reduces build times from 5min to 55s on incremental changes (80% improvement). Changes: - Add magic-nix-cache-action to build job - Build both kanban CLI and MCP server with nix - Add binary verification step - Add rust-cache to dev jobs for complementary caching The magic-nix-cache stores Crane's dependency derivations in GitHub Actions cache, enabling fast rebuilds when only source changes. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrates from
rustPlatform.buildRustPackageto crane for building bothkanbanandkanban-mcppackages. This dramatically improves incremental rebuild times by separating dependency compilation from source compilation.Challenge
Currently, every NixOS rebuild recompiles all Rust dependencies from scratch (~5 minutes) even when only source code changes, because
buildRustPackagedoesn't cache dependencies separately.Solution
Crane builds dependencies in a separate derivation that gets cached by Nix. When source code changes, only the source is recompiled while dependencies are reused from cache.
Changes
craneLibinstance, pass to package buildscraneLib.buildPackagewithbuildDepsOnlyfor dependency cachingPerformance Impact
Test Plan
nix build .#defaultnix build .#kanban-mcpkanban --version,kanban-mcp)nix develop