-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support nix-shell environment #9506
Comments
I think it should be the responsibility of the client to spawn rust-analyzer itself in the nix-shell environment. For vscode https://marketplace.visualstudio.com/items?itemName=arrterian.nix-env-selector seems like the right extension. |
Yes, in fact, I also think that this is something that the system should solve or VS Code provides support. I have never found a good solution, so I made this feature request. Fortunately, the VS Code extension you sent is very useful, and the initial test has made rust-analyzer run perfectly. Thank you so much! 🧡 💛 💚 💙 💜 |
I hope this issue can help NixOS users who search for related issues in the future. To avoid disturbing you, I will close it first! |
We could probably add a small section for this to the manual for vscode + nix setup? cc #9504 |
I'm not familiar with NixOS, but what about non-Code users? Can you run your editor inside |
Yes, I used to enter nix-shell first and then start VS Code in the shell to avoid this problem. Now I have found a VS Code extension that can automatically apply this environment, so I don't think I need to wrap the rust-analyzer program myself. Thank you for the solution ideas. 😄 |
FWIW, my solution to this is to use the nix-direnv and direnv nixpkgs to set up my environment rather than manually invoking nix-shell. Then the direnv extension in VSCode loads everything for you based on that. rust-analyzer works perfectly once everything is set up. |
direnv can load our nix-shell environment by default when opening a terminal. I haven't used the VS Code extension for it, but the way you use it, it should also allow VS Code to load the environment configured in the nix-shell so that rust-analyzer can start successfully. There is also the Nix Environment Selector extension mentioned in this issue, which is also perfect for making VS code automatically load the environment configured in the nix-shell, and it can also switch to a different shell.nix. |
I've started using the extension direnv-vscode and it works well with rust-analyzer 👍🏻 |
When developing a Rust project on NixOS, there will usually be compilation errors in projects that rely on external C libraries. This is because
pkg-config
under NixOS cannot find any shared libraries by default.We NixOS users will create a
default.nix
file in the current directory, for example:This file can control all aspects of the
nix-shell
environment (including installed packages, shared libraries, etc.). Then when we entered nix-shell, the customized environment that was able to successfully build the project was born.Unfortunately, we can hardly avoid rust-analyzer's error report, because rust-analyzer will not execute
cargo
or other commands in nix-shell.If possible, I would like rust-analyzer to use
nix-shell
to execute commands when it recognizes that there is adefault.nix
file in the current directory, or to launch itself through nix-shell.The text was updated successfully, but these errors were encountered: