Skip to content

Kan 209/integrate crane for faster nix builds#170

Open
fulsomenko wants to merge 6 commits intodevelopfrom
KAN-209/integrate-crane-for-faster-nix-builds
Open

Kan 209/integrate crane for faster nix builds#170
fulsomenko wants to merge 6 commits intodevelopfrom
KAN-209/integrate-crane-for-faster-nix-builds

Conversation

@fulsomenko
Copy link
Owner

Summary

Migrates from rustPlatform.buildRustPackage to crane for building both kanban and kanban-mcp packages. 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 buildRustPackage doesn'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

  • flake.nix: Add crane input, create craneLib instance, pass to package builds
  • default.nix: Migrate kanban CLI to craneLib.buildPackage with buildDepsOnly for dependency caching
  • crates/kanban-mcp/default.nix: Migrate kanban-mcp to crane-based build
  • flake.lock: Add crane input lock entry

Performance Impact

  • First build: ~2-3 min (unchanged - dependencies must compile once)
  • Incremental builds: ~55 sec (down from ~5 min) - ~80% faster
  • Dependency changes only: Fast rebuild of deps, source reuses previous build
  • Source changes only: Reuses cached deps, only rebuilds source (~55 sec)

Test Plan

  • Build kanban CLI: nix build .#default
  • Build kanban-mcp: nix build .#kanban-mcp
  • All tests pass (52 tests: 39 unit + 13 integration)
  • Binaries work correctly (kanban --version, kanban-mcp)
  • Dev shell works: nix develop
  • Incremental rebuild tested (55s vs previous 5min)

@fulsomenko fulsomenko self-assigned this Feb 22, 2026
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.
@fulsomenko fulsomenko force-pushed the KAN-209/integrate-crane-for-faster-nix-builds branch from 3e878eb to c1d6786 Compare February 22, 2026 12:29
fulsomenko and others added 2 commits February 22, 2026 13:29
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>
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.

1 participant