4 ms·
Nix seems great for terminal-based development environments where starting a nix-shell sets up all the proper symlinks, env vars, etc. But how does this transla
by zaps 3y ago
Nix seems great for terminal-based development environments where starting a nix-shell sets up all the proper symlinks, env vars, etc. But how does this translate to IDEs like VSCode or IntelliJ?
Like if you clone a repo with a shell.nix file, how does the IDE know to use that environment when you, say, use the File > Debug command, instead of executing whatever toolchain that happens to be on your path? Are there plugins available that enable this?
I realize you could just open a terminal within the IDE, start a nix shell, and run the equivalent run/debug/etc commands, but I am curious if anything exists to make the experience seamless to the user.
- 1una 3y ago> Are there plugins available that enable this? Try https://github.com/direnv/direnv-vscode https://github.com/direnv/direnv-vscode or https://github.com/fehnomenal/intellij-direnv https://github.com/fehnomenal/intellij-direnv
- nextos 3y agoYes, most Nix users employ https://direnv.net https://direnv.net or the equivalent for your IDE of choice. Emacs for instance has https://github.com/purcell/envrc https://github.com/purcell/envrc which set per-buffer variables. More background in https://github.com/direnv/direnv/wiki/Nix https://github.com/direnv/direnv/wiki/Nix.
- rgoulter 3y agoThat said, I believe VSCode (and some IDEs) don't necessarily support direnv in all cases.. e.g. you'd want direnv to load before other plugins (and update the PATH), but might not get that.
- angio 3y agoIf you start vscode with `code .` after entering the nix shell it will work in most cases.
- tripdout 3y agoThere is a Nix VScode plugin
- chpatrick 3y agoThere's a vscode plugin for exactly that: https://marketplace.visualstudio.com/items?itemName=arrterian.nix-env-selector https://marketplace.visualstudio.com/items?itemName=arrteria...
- JamesSwift 3y agoIn general you have to open the IDE from a terminal that is running in the context of the nix environment, and then everything will "just work" (except for issues sometimes with nix being readonly)