Newb: How to run nix-shell with a derivation?

I’m able to build something by running nix-build -A nodejs.'"13.6.0"' in a folder with my custom .nix files.

This build node v13.6.0, and the result is in result/bin/node.

Now how do I run a nix-shell with that node available in PATH? Or is this the wrong use-case for nix-shell?

For reference, my nix example is at Nix-build does not build anything (lazy evaluation in the way?). Recommendations?

Put that nodejs."13.6.0" in the (native)buildInputs of your mkShell in the shell.nix.

Assuming its globally available.

The way I prefer is to create an overlay, explicitely pulled in via niv that replaces/overrides that package in the required version.

1 Like

Thanks I’ll try that mkShell/shell.nix thing next. Is there a way to do it with only the nix-shell command? Ah… I assume I’d need to write the mkShell expression in the command?

I’m just trying to figure what’s the simplest way to manage this, so it is as easy as if I were using n 13.6.0 to manage node versions.

I’ve not yet experimented with one-off nix-shells but only declarative ones which have a shell.nix file. Additionally I use direnv to avoid the need of having to remember switching the shells manually

1 Like

If you’ve already run nix-build, I believe you should also be able to do the following:

$ nix-shell -p ./result

This should put you in a nix-shell with everything in result/ in your PATH. This should “just work”.

Instead of passing the result/ soft-link, I believe you can also pass any /nix/store/ derivation as well.

Although keep in mind that @NobbZ’s suggestion of actually creating a shell.nix file that is reproducible is the easier option if you plan on using this frequently.

1 Like