Don't expose gcc on the PATH after starting nvim
The plugin rust-analyzer adds gcc to the $PATH.
If we open a terminal inside neovim, and run cargo build/cargo test etc, it will fail if the project depends on various dynamically linked libraries (e.g. if using diesel, which links dynamically the C header files) because obviously the headers of those libs are outside /nix/store.
Fixes I've tried and worked:
- manually remove the nix's gcc from the
$PATH(but you have to do this in every terminal instance you open in neovim) - write
build.rsto inform the compiler and linker where various system libs are installed
Fix I'm proposing:
- don't expose the gcc from nix on the $PATH when starting neovim, if possible
I realise that gcc gets added to the $PATH by rust-analyzer, not by nixvim, but can still be removed by nixvim afterwards, unless there's a concern that doing so may break rust-analyzer.
I'm not sure we want to go in this direction in nixvim, as this is strictly a nixpkgs issue. If we start going into those kinds of issues it would be a huge maintance burden because we would have to vet every plugin & package we install.
Though are you sure gcc is not inserted by nvim-treesitter? This plugin has an enabled by default dependency on gcc, but that one can be removed: https://nix-community.github.io/nixvim/plugins/treesitter/index.html#pluginstreesittergccpackage
Thanks @traxys.
Yes, I agree with your view that nixvim shouldn't add layers of custom logic on top of the native plugins, that can get out of hand quickly.
You're right, it's treesitter exposing cc (I enabled both treesitter and rust-analyzer at the same time so I thought it might've been the latter doing it).
As a side note, I do want the grammars, so I think it's a good idea to let treesitter expose cc.
The real fix in my case, which is a Rust project, is to write a build.rs which makes nix's cc get the same compilation flags that the system cc is getting (it's probably some pkg-config business when using something Rust ffi like openssl-sys, because otherwise it can't find some of the headers).
Think we can close this.
The treesitter option gcc option is meant to be set to null when cc is provided externally from nixvim, I think this is your case if I understood correctly. I think I'll add an entry to the FAQ because it is a bit buried in the documentation before closing this
@traxys, worth mentioning that I am using nixvim as a home-manager module.
After I upgraded inputs.nixpkgs.url to the nixpkgs-unstable branch (as opposed to 23.11), the nixvim's url to main (as opposed to nixos-23.11 branch), without any other changes in the treesitter plugin (I literaly just have treesitter = {enable=true;}; without other settings), now when I open a terminal inside neovim and check the PATH, gcc is no longer shown as being exposed from inside /nix/store, thus cargo build works fine as it uses the system builder+linker.
It looks likee gcc was removed from being automatically injected in this commit, which isn't part of the branch I was working with, nixos-23.11.
It looks likee
gccwas removed from being automatically injected in this commit, which isn't part of the branch I was working with,nixos-23.11.
Indeed, this is the reason why it works now. Is everything good for you now ? If so, I will close the issue.
I'd still want to add an entry to the FAQ for this
It looks likee
gccwas removed from being automatically injected in this commit, which isn't part of the branch I was working with,nixos-23.11.Indeed, this is the reason why it works now. Is everything good for you now ? If so, I will close the issue.
Yes, it works well now, I no longer get nix's gcc injected on the PATH when I start nvim.
The only minor "issue" at the moment (before nix 24.05 is released I think) is that I had to follow nixpkgs-unstable branch of nixpkgs in my flake.nix to use the main branch of nixvim repo.
I used to follow the 23.11 nixpkgs branch, but going to nixpkgs-unstable didn't break anything for me.
inputs = {
nixpkgs.url = "flake:nixpkgs/nixpkgs-unstable";
nixvim = {url = "github:nix-community/nixvim/main"; inputs.nixpkgs.follows = "nixpkgs"; };
};