Shared Rust toolchain (pinned rustc + mold-on-gnu) consumed as a flake input
Find a file
Caspar Oostendorp ade8cfad7c docs: README (purpose, consume via git input, bump, gotchas)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 02:56:12 +00:00
flake.lock Shared Rust toolchain: rustc 1.96 + mold-on-gnu 2026-06-12 03:56:43 +00:00
flake.nix Shared Rust toolchain: rustc 1.96 + mold-on-gnu 2026-06-12 03:56:43 +00:00
README.md docs: README (purpose, consume via git input, bump, gotchas) 2026-06-14 02:56:12 +00:00

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 static crt-static release 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 ? {} }mkShell with 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 git input, not path:. Consumers (e.g. the Forgejo nix:host CI runner) run as users that can't traverse /home/caspar (0700), so a path:/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).