Okay, this is going to depend on whether or not you are on Nixos.
If you are not on NixOS, then this shell.nix works for me, although you will need libstdc++ installed on your host. Also, I cut out some of the packages, because the default nix shell provides ldd and gcc already, so there is no need to specifically include them.
{ pkgs ? import <nixpkgs> {} }:
let packages = [
pkgs.cargo
pkgs.cmake # Cmake
pkgs.git # Git version control system
pkgs.pkg-config # often needed for C dependencies
pkgs.rustc # Nix’s rustc (matches the store layout)
pkgs.libcxx
pkgs.gccNGPackages_15.libstdcxx
];
in
pkgs.mkShell {
nativeBuildInputs = packages;
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath packages;
# Optional – tell Rust to prefer lld for Rust‑only code, but fall back to gcc
# for build‑script / C‑linking steps.
RUSTFLAGS = "-C link-arg=-fuse-ld=lld -C link-arg=-Wl,-rpath,/usr/lib -C link-arg=-Wl,-dynamic-linker,/lib64/ld-linux-x86-64.so.2";
RUST_BACKTRACE = 1;
}
But if you are on NixOS, then things get a bit different. NixOS won't put some of the stuff that the rust compiler is expecting to be there by default, but not there. For the NixOS version, remove this part -C link-arg=-Wl,-dynamic-linker,/lib64/ld-linux-x86-64.so.2 from RUSTFLAGS.
You will probably have to either run it from the shell, or create a nix package for it.