dev-templates/rust/flake.nix
Yuval Kogman fbef9e0916 Add rust-src toolchain component
Provides sources of standard library, e.g. for rust-analyzer.
2023-05-25 22:31:35 +03:00

59 lines
1.5 KiB
Nix

{
description = "A Nix-flake-based Rust development environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-22.11";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs =
{ self
, nixpkgs
, flake-utils
, rust-overlay
}:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [
(import rust-overlay)
(self: super: {
rustToolchain =
let
rust = super.rust-bin;
toolchain =
if builtins.pathExists ./rust-toolchain.toml then
rust.fromRustupToolchainFile ./rust-toolchain.toml
else if builtins.pathExists ./rust-toolchain then
rust.fromRustupToolchainFile ./rust-toolchain
else
rust.stable.latest.default;
in
toolchain.override {
extensions = [ "rust-src" ]; # https://github.com/the-nix-way/dev-templates/issues/4
};
})
];
pkgs = import nixpkgs { inherit system overlays; };
in
{
devShells.default = pkgs.mkShell {
packages = with pkgs; [
rustToolchain
openssl
pkg-config
cargo-deny
cargo-edit
cargo-watch
rust-analyzer
];
shellHook = ''
${pkgs.rustToolchain}/bin/cargo --version
'';
};
});
}