Shared Rust toolchain (pinned rustc + mold-on-gnu) consumed as a flake input
- Nix 100%
|
|
||
|---|---|---|
| flake.lock | ||
| flake.nix | ||
| README.md | ||
rust-toolchain
Purpose: One shared Rust toolchain (pinned rustc + mold) consumed as a flake input by projects, so versions don't drift and mold is wired the same everywhere.
Location: /home/caspar/nix/rust-toolchain/ — published as the public repo git+https://git.perhaps.works/caspar/rust-toolchain.git.
What it provides
- Rust 1.96 (rust-overlay stable, profile
default→ rustc, cargo, clippy, rustfmt, rust-src, rust-analyzer). - mold, gnu-only: sets
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS = "-C link-arg=-fuse-ld=mold". This speeds the everyday gnu/host dev-loop link and never touches musl builds (so staticcrt-staticrelease builds are unaffected).
Consume it
In a project flake:
inputs.rust-toolchain.url = "git+https://git.perhaps.works/caspar/rust-toolchain.git";
# ...
let rt = rust-toolchain.lib.${system}; in {
devShells.default = rt.mkDevShell {
# add a musl target if you ship static binaries:
toolchain = rt.mkToolchain { targets = [ "x86_64-unknown-linux-musl" ]; };
packages = [ pkgs.just /* ... */ ];
env = { /* extra env */ };
};
}
lib API (rust-toolchain.lib.<system>)
mkToolchain { targets ? [], extensions ? ["rust-src" "rust-analyzer"] }— the pinned toolchain, optionally with extra cross targets.mkDevShell { toolchain ? mkToolchain {}, packages ? [], env ? {} }—mkShellwith the toolchain +mold+ the gnu mold env merged in.rustVersion— the pinned version string.
Bump the version
Edit rustVersion in flake.nix, commit + push this repo, then in each consumer:
nix flake update rust-toolchain.
Gotchas
- Must be a
gitinput, notpath:. Consumers (e.g. the Forgejonix:hostCI runner) run as users that can't traverse/home/caspar(0700), so apath:/home/caspar/...input is unreadable. The public git URL sidesteps filesystem perms entirely. - mold is gnu-only by design. Don't add it to musl targets — it gives little on the infrequent cold release link and complicates the static linker wiring.
See Also
big/docs/forgejo-and-agents.md— the CI build/release pipeline that consumes this (perch → static musl → codeberg).