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 foo
sets up the environment as it would for buildingfoo
, so all offoo
's dependencies are in yourPATH
and all of the other environment vars are set too (I count 23 env vars containingNIX
), butnix run
produces an environment much more similar to what you’d get if you simply installed the package (e.g. it basically just prefixes yourPATH
with the appropriate directories from the specified package).That said,
nix-shell
replaces your normal shell initialization files andnix run
doesn’t, so depending on how your.bashrc
is set up you might override thePATH
. For example with my setup,echo $PATH
in anix run
shell starts the path with/usr/local/bin
before the nix-provided path value, because my current.bashrc
unconditionally prefixes my PATH (which I really should fix).