Running lsp servers inside a nix-shell?

Is it possible to run lsp servers inside a nix shell? So (suppose) if you open a rust file, the required lsp servers would be run inside a nix shell and you would have full lsp support even though the lsp servers weren’t installed previously.

There is a neovim plugin which does this and it works well for 99% of cases

Is there anyway to replicate this on doom emacs?

Thanks

With direnv, nix-direnv, and Doom’s :tools direnv module, sure. I use this myself. Setup instructions can be found here.

Thanks for replying quickly.

I also use direnv with the doom module, which works great for projects. However, when editing “loose” files (files located randomly and not in the same directory), creating a shell.nix and .envrc file in each of those directories becomes annoying.

For common languages (bash ,perl , python etc), I’ve added their respective lsp servers and formatters to my systems global packages.

I was wondering if there was a way for doom to automagically run these in a nix-shell (or if not automagically , manual specify which packages to load in a nix-shell when editing a certain languages file). The neovim plugin does exactly this