Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
Superseded by moq-dev/moq#8666, which lands this spike's bitcode-only per-crate layout for every Nix-built Rust package and removes crane, following the maintainer's 2026-11-13 decision to adopt it. Closing this spike. (Written by Opus 5.5) |
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.
Spike, not for landing: would one Nix derivation per crate (crate2nix's generated
Cargo.nixon nixpkgs'buildRustCrate) make caching of moq's Nix-built Rust meaningfully better than crane, withnix.moq.dev's CI bucket as the shared cache?just checkandjust testwere not run: this branch will not land.Problem
Today Nix builds Rust in one place per main push: Cache's
runtimejob (sh/gh/cache-runtime.sh, GitHub-hostedubuntu-24.04) builds crane's dependency layers (.#moq-relay.cargoArtifacts,.#moq.cargoArtifacts, now also moq-boy's) and the packages, then pushes them tonix-ci-moq-dev(14-day expiry,refreshrestarts the age of the newest cached commit's closure). Smoke's nix cell and deploys substitute the packages of the newest cached commit. Release Nix builds tagged packages on three platforms intonix-moq-dev, and macOS release dry-runs build.#<bin>through Nix. Everything else (just ci: clippy, nextest, every feature set and platform) builds with cargo through mbx, cached in thembx-moq-devR2 bucket.crane caches only two layers. Its package derivation takes the whole filtered workspace, so any
.rschange anywhere rebuilds every workspace crate of both packages. Its dependency layer takesCargo.lock, so any lock change, release-plz version bumps included, rebuilds all ~430 dependencies. Last week 606 Cache runs started; 380 of their runtime jobs ran 8 to 22 minutes (rebuilding), the rest 1 to 2.Approach
nix/Cargo.nix(crate2nix 0.15.0) andnix/crate2nix.nixbuild moq-relay and moq-cli per crate, on the same rust-overlay 1.98.1 toolchain crane uses, with[profile.release]restated: codegen-units 1, fat LTO andstrip=symbolson the root binaries only, opt-level 0 build scripts and proc macros, frame pointers on every crate, crane's source filter on workspace crates. Features resolve per package, as crane's two-pbuilds do.spike-crate2nixmatches the per-crate layout a downstream spike used: every crate emits machine code and bitcode.spike-crate2nix-bitcodecompiles every crate outside the host closure (proc macros, build-script dependencies, and their dependencies) with-C linker-plugin-lto, bitcode only, as cargo does under fat LTO: 215 of 539 derivations.spike-craneis today's two packages with atimeshook; every variant prints builder CPU intonix log.nix/spike/holds the scripts.Measurements
Desktop, 24 cores, Nix 2.35.2, one build at a time through
quest gate,--max-jobs 24. CPU is user+sys summed over every derivation built. Warm: the base commit's outputs are in the local store. Subst: the base's Rust outputs are deleted locally and served, signed, from afile://cache, asnix.moq.devwould. Edits: a comment appended tors/moq-relay/src/main.rs(leaf) andrs/moq-net/src/lib.rs(core); lock:cargo update -p arc-swap -p flate2 -p itoa.Per change, what a CI
nix copywould add to the bucket, and what a fresh runner downloads:Sizes are zstd, as
just infra nix pushwrites. Each path is 2 objects (narinfo and NAR). A full per-crate set is 1077 paths, 405 MiB. crane's is 2 layers (573 MiB), 2 packages, and 910 vendored-source paths (100 MiB).Weekly
Applying each of the 582 main commits from Nov 6 to 12 to the per-crate graph, priced from the measured per-derivation CPU. The model predicts 378, 682 and 785 CPU-s for the three scenarios above (measured 376, 686, ~830):
These are upper bounds, since Cache coalesces pushes. At R2's list prices both stay under a dollar a month: 16,900 puts a week is ~$0.08, inside the free 1M a month, and 14 days of pushes is ~40 GiB against ~54 GiB, $0.60 against $0.80 a month.
refreshwalks runtime closures, which hold no rlibs, so per-crate would record every crate output as a root: up to ~2,200 copy operations a week. crane's closure already refreshes ~1,850 objects, its vendored sources.Fidelity
--help, dynamic libraries and jemalloc, frame pointers kept (21249 against 21202push %rbp), and sizes within 0.6%.dep:rustlsas also enabling a crate's same-namedrustlsfeature. In reqwest 0.13 that feature pulls in aws-lc-rs, which is not inCargo.lock, so rustls-webpki fails to compile. The fix keeps only features cargo resolved somewhere, read from crate2nix'sinternal.crates, an unstable interface.proc-macro-crateoverride references nixpkgs' cargo 1.99, not 1.98.1, which drags rustc 1.99 and LLVM (~600 MiB) into the closure once.Maintenance
nix/Cargo.nixis 42,875 lines (1.6 MB), pluscrate-hashes.jsonfor the uniffi git fork.crate2nix generatetakes 2.5 s. Any lock or manifest change makes it stale: 38 of last week's 582 main commits, release-plz bumps included. The lock bump here changed 12 lines.EXTRA_LINK_ARGS_BINS,crateBin = [ ]on non-roots, and every future[profile]change restated in Nix.--max-jobs, since one derivation at a time leaves most cores idle.mbx
Per-crate Nix neither replaces nor duplicates mbx. mbx caches cargo's dev, test and clippy compilations for
just ci, across feature sets and platforms.buildRustCratecompiles release LTO artifacts with its own-C metadataand path remaps, so no compilation is shared between the two. Tests stay on cargo and nextest. Per-crate Nix replaces only crane.Downstream substitution
A consumer substitutes moq's crates only when it evaluates byte-identical derivations: the same nixpkgs (stdenv,
buildRustCrate, its overrides), the same toolchain store path (moq's rust-overlaystable."1.98.1".default, not one derived fromrust-toolchain.toml), the sameCargo.lockresolution, features, flags and source filter.Cargo.nix.Recommendation
Not worth it.
Impact
None. The spike adds flake outputs only.
Alternatives
spike-crate2nixcolumn. It costs 13% more than crane cold (under higher load) and 5% more on the core edit.Follow-ups
flake.nix's header says CI paths expire after 30 days.infra/nix/lifecycle.jsonexpires them after 14. Recommend planning a one-line fix.Models
Size: M
Implementer: Claude Code, claude-opus-5-5, high effort
🤖 Generated with Claude Code
(Written by Opus 5.5)