I was figuring out how to setup a Nix, Rust & IntelliJ setup.
At the moment this setup does not use the Mozilla overlay.
derivation.nix
{ stdenv, rustPlatform, lib, ... }:
rustPlatform.buildRustPackage rec {
pname = "example";
version = "0.1.0";
# clean source is super important so that the path names are consistent
# across machines
src = lib.cleanSource ./.;
buildInputs = [ ];
cargoSha256 = "13gxfrc7vxhf32y0vcp8x6rcjxc1hsq81qj1l4p9qrj7899k617y";
verifyCargoDeps = true;
meta = with stdenv.lib; {
description = "My example project";
homepage = "https://example.org/my-project";
license = licenses.mit;
platforms = platforms.linux;
maintainers = [ "you@you.com" ];
};
}
overlay
self: super:
{
# make our package installable easily to minimize the default.nix file
example = self.callPackage ./derivation.nix { };
}
default.nix
let
nixpkgs =
import <nixpkgs> { overlays = [ (import ./overlay.nix) ]; };
in nixpkgs.example
shell.nix
let
pkgs =
import <nixpkgs> {};
rust-toolchain = pkgs.symlinkJoin {
name = "rust-toolchain";
paths = [pkgs.rustc pkgs.cargo pkgs.rustPlatform.rustcSrc];
};
in with pkgs;
mkShell {
name = "scriptr";
buildInputs = [rust-toolchain evcxr rustracer];
RUST_BACKTRACE = 1;
}
The interesting part is rust-toolchain which I create a symlinkJoin to include cargo & rustc into a single output directory – this was needed by IntelliJ.
I also figured out the Rust SRC path by just seeing what racer was set to.
Current configuration runs with: (Anything that starts after core shows a lot of time in Stats, don’t worry, it’s actually before that thing not in that thing, notice the angle brackets)
It cold-starts in maybe 3 seconds on my 6 year old machine and takes all of 100 MB.
It could also be used for development but I couldn’t get my language server working (year old story, don’t know what changed since rust-analyzer) and after a while didn’t feel the need.
put something like this in shell.nix (no need for overlays now? Nixpkgs has a valid Rust toolchain available)
let
pkgs =
import <nixpkgs> {};
rust-toolchain = pkgs.symlinkJoin {
name = "rust-toolchain";
paths = [pkgs.rustc pkgs.cargo pkgs.rustPlatform.rustcSrc];
};
in with pkgs;
mkShell {
name = "scriptr";
buildInputs = [rust-toolchain];
RUST_BACKTRACE = 1;
}
Then start idea-community . with the Nix shell active.
IDEA will pester you to configure a Rust toolchain (or visit Settings → Rust)
IDEA will suggest the toolchain location in the drop-down on the path selection box; choose that.
For the stdlib sources, copy the same path but remove the /bin suffix.
Hope this helps someone else e.g. if they’re also coming here by search engine
This also did not work for me. I tried what @malteneuss suggested, using the rustcbin path, but RustRover gives me an error: Cannot Save Settings: Invalid toolchain location: can't find Cargo in /nix/store/...-rustc-wrapper-1.80.1/bin
Nevermind, forgot to do the symlink join in the original post. Working now!