{ inputs = { nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; fenix = { url = "github:nix-community/fenix"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { self , nixpkgs , flake-utils , fenix }: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; stdenv = if pkgs.stdenv.isLinux then pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv else pkgs.stdenv; mkToolchain = fenix.packages.${system}.combine; toolchain = fenix.packages.${system}.stable; devToolchain = mkToolchain (with toolchain; [ cargo clippy rust-src rustc # Always use nightly rustfmt because most of its options are unstable fenix.packages.${system}.latest.rustfmt ]); in { devShells.default = (pkgs.mkShell.override { inherit stdenv; }) { # Rust Analyzer needs to be able to find the path to default crate # sources, and it can read this environment variable to do so. The # `rust-src` component is required in order for this to work. RUST_SRC_PATH = "${devToolchain}/lib/rustlib/src/rust/library"; # Development tools nativeBuildInputs = [ devToolchain ] ++ (with pkgs; [ engage nixpkgs-fmt ]) ++ (with pkgs.nodePackages; [ markdownlint-cli ]); }; checks = { devShellsDefault = self.devShells.${system}.default; }; }); }