{
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "nixpkgs";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
inputs@{
nixpkgs,
flake-parts,
rust-overlay,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
];
perSystem =
{
system,
pkgs,
...
}:
let
extensions = [
"rust-analyzer"
"rustfmt"
"clippy"
"rust-src"
];
in
{
_module.args.pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
devShells =
let
buildInputs = [ ];
nativeBuildInputs = with pkgs; [
cargo-show-asm
cargo-expand
cargo-bloat
cargo-fuzz
cargo-outdated
cargo-machete
cargo-sort
cargo-cache
cargo-depgraph
cargo-benchcmp
cargo-audit
];
# Pinned to the crate's MSRV (see `rust-version` in Cargo.toml).
rust-msrv = [ (pkgs.rust-bin.stable."1.87.0".default.override { inherit extensions; }) ];
rust-stable = [ (pkgs.rust-bin.stable.latest.default.override { inherit extensions; }) ];
# Fuzzing (cargo-fuzz / libfuzzer) needs a nightly toolchain for the
# sanitizer instrumentation, so this is the shell to use for `cargo fuzz`.
rust-nightly = [
(pkgs.rust-bin.selectLatestNightlyWith (
toolchain: toolchain.default.override { inherit extensions; }
))
];
shell =
toolchain: params:
{
inherit buildInputs;
nativeBuildInputs = nativeBuildInputs ++ [ toolchain ] ++ [ ];
name = "rust";
shellHook = "";
}
// params;
msrv-shell = pkgs.mkShell (shell rust-msrv { });
stable-shell = pkgs.mkShell (shell rust-stable { });
nightly-shell = pkgs.mkShell (shell rust-nightly { name = "nightly"; });
in
{
stable = stable-shell;
nightly = nightly-shell;
msrv = msrv-shell;
default = stable-shell;
};
};
};
}