Hello.
I am a recently nix joiner, and I’m loving it so much that I started using it in all my projects and for all my configs.
I want to use it also for all the commands that I want to run from any place, including my code editor. One example is configuring MCP servers. What I’m doing now is starting a new shell for each command I want to run (see the snippet below), but this feels a bit wasteful, and I’m not sure if it’s the right way of doing it.
It depends on your editor. Direnv has nix support and there are editor plugins that automatically switch to a nix shell, which can then change what e.g. npx or nodejs refers to, which will make any command executed any way run the nix-installed nodejs/npx.
I’m currently using windsurf, and I indeed use the direnv plugin.
So all I have to do is to have node+npx in the project flake.nix, and that will be just available for the whole editor? That is something interesting. However that only works for projects where having node makes sense, but not that much in other projects where I still want to use MCP but I don’t use node.
Well, in those projects don’t put them in your devshell I’ve never used windsurf, so I’m not sure how granular its env config is, but at least in emacs I can easily have multiple projects with different dependencies.
This editors (basically VSCode forks) are not very respectful of user choices, and they just do what the majority of people will want, which is global dependencies hell.
Will ask if it is possible to have a per-project MCP config (which I think VSCode now allows, you can put the MCP servers in the project settings).
However, the question remains. In those cases, what is the best strategy?
Maybe the best idea is to configure the MCP dependencies somewhere in my nix-darwin and then wrap the editor executable somehow with an env with those dependencies. How is that called in nix? a trampoline?
AIUI the vscode plugin for direnv handles this just fine, give it a shot.
What you’re talking about is generally referred to as a “wrapper”, but I don’t think this is a use case for that. If you really have to go down that route, use direnv, and launch your editor from a shell that has been cd’d into the project directory. Then all the correct environment variables will have been set before the editor runs and it will work as intended.