Setting up perfect devshell

Hello fellow NixOS enjoyers,

This is my first post here, but I do often read a lot from you.

I did recently go through the fantastic experience of building packages with nix, and on top of that I decided to learn how to setup a devshell in the most “correct” way.

I am building a Rust package for different platforms, like windows and linux-musl (static). Using rustPlatform.buildRustPackage, from pkgs.pkgsStatic and pkgs.pkgsCross.mingwW64 it works flawlessly, but, as usual, when I solve one problem, two more appear.

I saw that when creating a package with packages.”TARGET”.something, I can nix develop .#something, but I don’t understand how is that shell created (and often doesn’t fully work for what I have to do), so I am trying to setup my own shell, just for understanding how things work.

My first question is, what is the difference between pkgs.pkgsStatic and pkgs.pkgsCross.musl64? Why is the non-static musl considered a “pkgsCross” and the static is not?

Second: When setting up a shell with mkShell, I have plenty of options:

I want to have the exact toolchain that it is used, or at least something that is very close, like if I build with pkgsStatic, then I want pkgsStatic.rustc, not pkgs.rustc. I could setup a shell using pkgs.mkShell and then supply pkgsStatic.rustc as nativeBuildInputs and also the opposite, but where is the difference?

Also what is the difference between pkgsStatic.buildPackages.rustc and pkgsStatic.rustc?

Thank you

This is my shell I use rust-overlay for full control of the toolchain, targets, etc. If you want static libraries (musl) just add to buildInputs pkgs.pkgsStatic.{library}. I don’t know if it is the best way but it work.

1 Like

For musl follow rust-overlay/examples/cross-aarch64/shell.nix at eb3898d8ef143d4bf0f7f2229105fc51c7731b2f · oxalica/rust-overlay · GitHub and instead use musl. This is a cross target and works differently than just adding the rustc target with Nix.