Going to quote @lilyball’s reply verbatim from another thread because it is highly relevant:
BTW the “better option” here is
nix run.nix-shell -p foosets up the environment as it would for buildingfoo, so all offoo's dependencies are in yourPATHand all of the other environment vars are set too (I count 23 env vars containingNIX), butnix runproduces an environment much more similar to what you’d get if you simply installed the package (e.g. it basically just prefixes yourPATHwith the appropriate directories from the specified package).That said,
nix-shellreplaces your normal shell initialization files andnix rundoesn’t, so depending on how your.bashrcis set up you might override thePATH. For example with my setup,echo $PATHin anix runshell starts the path with/usr/local/binbefore the nix-provided path value, because my current.bashrcunconditionally prefixes my PATH (which I really should fix).