Skip to content
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

vim plugin specific snippets #172538

Closed
teto opened this issue May 11, 2022 · 7 comments
Closed

vim plugin specific snippets #172538

teto opened this issue May 11, 2022 · 7 comments

Comments

@teto
Copy link
Member

teto commented May 11, 2022

Issue description

Some of the vim plugins need a specific vim configuration to work on nixos, we should add these to nixpkgs (via a passthru key) so that either
1/ users can reference these snippets e.g. in a home manager configuration:

      programs.neovim.plugins = [ {
        plugin = unicode-vim;
        config = pkgs.vimPlugins.unicode-vim.advisedSnippet; 
        # the advisedSnippet being: 
        # with "let g:Unicode_data_directory='${pkgs.vimPlugins.unicode-vim}/share/vim-plugins/unicode-vim/autoload/unicode'
      }

or
2/ the neovim wrapper can add these snippets to the init.vim / init.lua

The alternative of patching the plugin doesnt suit me as it makes bug reports harder and in case we dont patch correctly could taint the nixos reputation: it's best to generate a config that the user can then report to the vim plugin author.

An additionnal issue is that some plugins depend on treesitter grammars such as rest.nvim: without the grammer it triggers
no parser for 'http' language, see :help treesitter-parsers so we should be able to set that as a dependency

Here I want to collect such snippets until we agree on the proposition/naming:

  • unicode.vim needs:
let g:Unicode_data_directory='${pkgs.vimPlugins.unicode-vim}/autoload/unicode'
g.coq_settings.xdg
@teto
Copy link
Member Author

teto commented Aug 13, 2024

@mrcjkb @GaetanLepage after I've patched sqlite.nvim to remove the need for the snippet, I felt guilty. We should not patch plugins at the risk of maddening maintainers.

so I thought of 2 things to tackle the issue:

  1. reproducing the unwrapped/wrapped nix way, aka sqlite.nvim-wrapped would have sqlite.nvim as a dependency plus the snippet let g:sql_clib_path = '${pkgs.sqlite.out}/lib/libsqlite3.so'
  2. add a passthru.initRc that contains the snippet so users are free to use it directly, as well as us in the nixpkgs infrastructure (to setup tests for instance).

I believe 1 adds too much boilerplate. 2 seems more straightforward and generic. We could have an option in the neovim wrapper that auto-adds passthru.initRc when available as well.

What do you think ?

@mrcjkb
Copy link
Member

mrcjkb commented Aug 13, 2024

This would be my preferred approach:

Luarocks has a external_dependencies option. We should be able to utilise this as follows:

  • Update the rockspec to use external_dependencies.
  • Fix the sqlite.lua library so that it can auto-detect the sqlite library and fall back to g:sql_clib_path if it isn't found.
    This would probably need a similar mechanism that luarocks uses.
  • I don't think it will be possible for luarocks-nix to make use of the external_dependencies1, so this would require an override.
    But the luarocks build should fail if the external dependency isn't present. And specifying them becomes the responsibility of the upstream plugin author.

This would be more work initially, but I think we could speed up adoption if we add a section to the neorocks best practices guide.

Footnotes

  1. The format is { EXPAT = { header = "expat.h" } }

@teto
Copy link
Member Author

teto commented Aug 13, 2024

the sqlite.nvim was just an example, I did not mean it as an example to handle external dependencies, see for instance the fzf-hoogle-nvim example.

It's probably left better for another issue but I have little faith upon external_dependencies reliance. It would need a mapping between external_dependencies and all the distribs packages (if we consider only nixpkgs, luarocks-nix should be able to map the common ones, but what library name should rockspec authors use in their external_dependencies ?). Not only that but luarocks doesnt care about pkg-config for finding libraries, which is a pain for nixpkgs.
Even then, libraries might need special care. I think it's a multi-year project which I personally would refrain from. It's to handle problems like this we have nix :)
Now if anyone could make me believe this is possible, that would be the neorocks team but it's out of the scope of this issue (in my mind, we can create another ticket if you really want to tackle this).

@mrcjkb
Copy link
Member

mrcjkb commented Aug 14, 2024

I see.

Something to watch out for (e.g. with the fzf-hoogle-vim example): That will only work with Nvim, but not Vim. It looks like something that should be fixed upstream.

But I see your point, e.g. for Python dependencies.
I'd prefer the passthru.initRc (for vim compatibility) or passthru.initLua (for nvim compatibility) option.
Perhaps the config could even default to using it if it's null.

luarocks doesnt care about pkg-config for finding libraries, which is a pain for nixpkgs.

I don't think a plain Lua wrapper for pkg-config would be very hard to implement. And perhaps something like that could be upstreamed to luarocks.

@GaetanLepage
Copy link
Contributor

I'd prefer the passthru.initRc or passthru.initLua option.

I agree, this seems like an appropriate approach.

@teto
Copy link
Member Author

teto commented Aug 15, 2024

The PR of what I mean: #334913

teto added a commit to teto/nixpkgs that referenced this issue Aug 18, 2024
as described in NixOS#172538, some vim
plugins need some configuration to be able to work at all.
We choose not to patch those plugins and instead expose the necessary
configuration to make them work in `PLUGIN.passthru.initLua`.
For now the user can check if plugins have a `PLUGIN.passthru.initLua`
and if yes, prepend it to their own init.lua.

Maybe later we can revisit this to either patch them in a way that is
clear that it's a nixpkgs patch or by having the neovim wrapper pick
those snippets and autoadd them to init.lua ?
teto added a commit that referenced this issue Aug 19, 2024
* vimPlugins: introduce passthru.initLua for some plugins

as described in #172538, some vim
plugins need some configuration to be able to work at all.
We choose not to patch those plugins and instead expose the necessary
configuration to make them work in `PLUGIN.passthru.initLua`.
For now the user can check if plugins have a `PLUGIN.passthru.initLua`
and if yes, prepend it to their own init.lua.

Maybe later we can revisit this to either patch them in a way that is
clear that it's a nixpkgs patch or by having the neovim wrapper pick
those snippets and autoadd them to init.lua ?

* Update doc/languages-frameworks/vim.section.md

Co-authored-by: Marc Jakobi <[email protected]>

---------

Co-authored-by: Marc Jakobi <[email protected]>
@teto
Copy link
Member Author

teto commented Aug 19, 2024

With the related PR being merged, I will close this. Feel free to add your snippets and tag me if I've forgotten any

teto added a commit to teto/nixpkgs that referenced this issue Oct 8, 2024
as described in NixOS#172538, some vim
plugins need some configuration to be able to work at all.
We choose not to patch those plugins and instead expose the necessary
configuration to make them work in `PLUGIN.passthru.initLua`.
For now the user can check if plugins have a `PLUGIN.passthru.initLua`
and if yes, prepend it to their own init.lua.

Maybe later we can revisit this to either patch them in a way that is
clear that it's a nixpkgs patch or by having the neovim wrapper pick
those snippets and autoadd them to init.lua ?
teto added a commit to teto/nixpkgs that referenced this issue Oct 14, 2024
as described in NixOS#172538, some vim
plugins need some configuration to be able to work at all.
We choose not to patch those plugins and instead expose the necessary
configuration to make them work in `PLUGIN.passthru.initLua`.
For now the user can check if plugins have a `PLUGIN.passthru.initLua`
and if yes, prepend it to their own init.lua.

Maybe later we can revisit this to either patch them in a way that is
clear that it's a nixpkgs patch or by having the neovim wrapper pick
those snippets and autoadd them to init.lua ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants