nix-community / nixvim

Configure Neovim with Nix! [maintainer=@GaetanLepage, @traxys, @mattsturgeon, @khaneliman]
https://nix-community.github.io/nixvim
MIT License
1.58k stars 246 forks source link

`plugins.*.package` should be nullable, to use package from system. #1970

Open MattSturgeon opened 1 month ago

MattSturgeon commented 1 month ago

Discussed in https://github.com/nix-community/nixvim/discussions/1969

Originally posted by **niksingh710** August 2, 2024 ```nix plugins = { ltex-extra = { enable = true; # This has been made null so that nvix uses system latex package and nix run becomes faster (no downloads for test or build) # vimplugin-ltex_extra.nvim package = null; }; vimtex.enable = true; }; ``` I am trying this to make ltex-extra use the ltex-extra package that is available in my system. but this throws an error ``` error: A definition for option `plugins.ltex-extra.package' is not of type `package'. Definition values: - In `/nix/store/fdn1lw1j5wlmpqxixr92hy8nvx7igshf-lang/tex.nix': null ```
MattSturgeon commented 1 month ago

My understanding is that we don't allow null in these package options because we need to be able to add something to neovim's rtp (via extraPlugins).

I don't know if there's a way to do this by getting system installed packages from the PATH, so this may be a WONTFIX.

@traxys @GaetanLepage do you have any insight into this?

traxys commented 1 month ago

I don't know what such a feature would look like indeed, maybe we could allow strings, and this would add the corrsponding path to the rtp?

MattSturgeon commented 1 month ago

Perhaps just making the option nullable is enough, but we'd have to document clearly that users need to manually edit their rtp for the plugin to work.

I expect many users would wrongly expect to be able to just add vimPlugins.* to their home.packages or equivalent.

Instead they could either add to their rtp via extraConfigLuaPre or by adding their own package to extraPlugins... Although doing the latter would be no different from setting package.

niksingh710 commented 1 month ago

Enabling null should be an option to set up a conditional configuration for nixd, statix, and deadnix such that the Language Server Protocol (LSP) only activates them if they are present on the system. and if the user is explicitly making a package null then they should know the workaround. Not only for lsp packages but others too.

MattSturgeon commented 1 month ago

Most package options in nixvim are nullable already; anywhere that the program can be loaded from the PATH.

This applies to LSP language server, e.g. plugins.lsp.servers.*.package is type null or package.

This issue only relates to plugin's package options that aren't currently nullable, because they need to be added to the rtp to be loaded by neovim.

There's no way for neovim to "detect" plugin packages installed on the system; that's not how neovim's plugin loading works.

To install a plugin in neovim it must be explicitly added to neovim's runtimepath.

niksingh710 commented 1 month ago

Can Nixvim expose an attribute to set runtimepath via user input? Alternatively, can it read a specific directory where users can point to their packages so that they can be considered by plugins?

MattSturgeon commented 1 month ago

When you have a plugin package, you can simply add that package to the extraPlugins list. This will make the package available on the rtp.

If you want some other arbitrary path on the rtp, you can use extraConfigLua like so:

extraConfigLua= ''
  vim.opt.runtimepath:prepend('/some/random/path')
'';

Maybe it would be useful for extraPlugins to also accept paths/strings? Or to have some other way to configure the rtp from a nix option. However it'd only be a thin wrapper over the lua interface and I think the use-case is fairly niche?