{
nightly ? false,
cross ? false,
}:
let
nixpkgsBase = import (fetchTarball {
name = "nixpkgs-stable-25.11";
url = "https://github.com/NixOS/nixpkgs/archive/refs/tags/25.11.tar.gz";
sha256 = "sha256:1zn1lsafn62sz6azx6j735fh4vwwghj8cc9x91g5sx2nrg23ap9k";
});
# Oxalica's Rust overlay gives us the rust-bin function which allows us
# to select a specific Rust toolchain. Furthermore, we can configure
# additional targets like shown below.
rustOverlay = import (
builtins.fetchTarball {
name = "rust-overlay-2026-03-25";
url = "https://github.com/oxalica/rust-overlay/archive/d6471ee5a8f470251e6e5b83a20a182eb6c46c9b.tar.gz";
sha256 = "1wydd5hq65y3zkn9kf1rfkdczq5pg8dlj9rkh7vnfxirpzv5szr6";
}
);
nixpkgs = nixpkgsBase {
overlays = [ rustOverlay ];
};
hostTriple =
if nixpkgs.stdenv.hostPlatform.isDarwin then
(if nixpkgs.stdenv.hostPlatform.isAarch64 then "aarch64-apple-darwin" else "x86_64-apple-darwin")
else if nixpkgs.stdenv.hostPlatform.isLinux then
(
if nixpkgs.stdenv.hostPlatform.isAarch64 then
"aarch64-unknown-linux-gnu"
else
"x86_64-unknown-linux-gnu"
)
else
nixpkgs.stdenv.hostPlatform.config;
targets = if cross then [ "thumbv7em-none-eabihf" ] else [ hostTriple ];
# Choose between a specific Rust channel and 'latest', between stable and nightly
# For nightly, we use a specific one so we do not download a new compiler every day
rustChannel = (
if nightly then
nixpkgs.rust-bin.nightly."2026-03-25".default.override {
extensions = [
"rust-src"
"rust-std"
"rust-analysis"
];
inherit targets;
}
# Stable Version of current nixpkgs
else
nixpkgs.rust-bin.stable."1.94.0".default.override {
extensions = [
"rust-src"
"rust-std"
"rust-analysis"
];
inherit targets;
}
);
# cargo-udeps only runs on nightly so we only need to include it if on nightly
# this lets us skip downloading another nixpkgs when not required
optionalCargoUdeps = if nightly then [ nixpkgs.cargo-udeps ] else [ ];
in
with nixpkgs;
mkShell {
buildInputs = [
rustChannel
cargo-deny
cargo-readme
gitlab-clippy
cargo-tarpaulin
cargo2junit
git
nodePackages.cspell
go
gcc
] ++ optionalCargoUdeps;
RUST_BACKTRACE = 1;
}