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

bug: Unable to configure Vim Plugins #3683

Closed
2 tasks done
dinkopehar opened this issue Feb 19, 2023 · 5 comments
Closed
2 tasks done

bug: Unable to configure Vim Plugins #3683

dinkopehar opened this issue Feb 19, 2023 · 5 comments
Assignees
Labels
bug triage Issues or feature request that have not been triaged yet

Comments

@dinkopehar
Copy link

Are you following the right branch?

  • My Nixpkgs and Home Manager versions are in sync

Is there an existing issue for this?

  • I have searched the existing issues

Issue description

Hello.

I have a problem setting up Neovim plugins when config is specified. I have searched various sources, issues, comments, reddit threads but not sure what else to do.

For example, this is part of my neovim configuration that is managed by home-manager:

{ pkgs, ... }:

{
  programs.neovim = {
    enable = true;
    vimAlias = true;
    defaultEditor = true;
    extraLuaConfig = builtins.readFile ./init.lua;
    plugins = with pkgs.vimPlugins; [
      # Core
      {
        plugin = chad;
        config = builtins.readFile ./plugins/chadtree.vim;
      }
      {
       plugin = alpha-nvim;
       config = builtins.readFile ./plugins/alpha-nvim.lua;
       type = "lua";
      }
      {
        plugin = barbar-nvim;
        config = builtins.readFile ./plugins/barbar.lua;
        type = "lua";
      }

      vim-gitgutter
      toggleterm-nvim
      nvim-autopairs
...

I'm trying to setup plugins to work with their proper configs. And for example, the plugin alpha-nvim does not work. In the README.md of alpha-nvim, it states how to enable it using some Vim package managers.

If I try similar thing in ./plugins/alpha-nvim.lua:

alpha = require('alpha')
dashboard = require('alpha.themes.dashboard')
alpha.setup(dashboard.config)

nothing happens. I have also similar problem with barbar.


The only resource I found was at the end of Neovim page on NixOS https://nixos.wiki/wiki/Neovim#Note_on_Lua_plugins . It states:

Due to how the runtimepath for Lua modules is processed, your configuration may require packadd! plugin-name to require a module.

but that solution with packadd! does not work when I add it in alpha-nvim.lua as:

vim.cmd [[packadd alpha-nvim]]
alpha = require('alpha')
dashboard = require('alpha.themes.dashboard')
alpha.setup(dashboard.config)

Am I doing something wrong here ? I'm not sure what that "Lua modules" with packadd does so any help would be appreciated if you know the solution/workaround.

Thank you

Maintainer CC

@teto @rycee

System information

- system: `"aarch64-darwin"`
 - host os: `Darwin 22.2.0, macOS 13.1`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.12.0`
 - channels(raziel): `"darwin, home-manager, unstable"`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
@dinkopehar dinkopehar added bug triage Issues or feature request that have not been triaged yet labels Feb 19, 2023
@dinkopehar dinkopehar changed the title bug: Unable to configure Vim Plugin bug: Unable to configure Vim Plugins Feb 19, 2023
@dinkopehar
Copy link
Author

Update:

I installed Neovim only as package and managed to enable and install plugins using Packer.

@lucidph3nx
Copy link

There are few things as horrifying as finding only a single GitHub issue with the exact problem you are facing and no resolution.
I too, tried to manage my neovim plug-ins with nix. I wanted a configuration like so many I had seen on GitHub, using pure nix, but with each plug-ins configuration in the style of:

  programs.neovim.plugins = [
    {
      plugin = pkgs.vimPlugins.nvim-autopairs;
      type = "lua";
      config = 
        ''
        require('nvim-autopairs').setup()
        '';
    }
  ];

The issue I faced was the same, the lua module 'nvim-autopairs' could not be found when opening neovim. The /nix/store/ path it was looking in was all wrong and I couldn't find any way to reconcile it. I tried every combination of config I could think of, minimal reproducible examples, installing only a single plugin, in a home.nix containing basically just neovim. I delved into the build process of vimPlugins packages, into the code for home-manager. How could all of these other GitHub configurations even work when a clearly simplistic example would fail?

After several whole days of battling the issue, convinced that my problem was some kind of caching problem, I attempted to remove neovim from my system entirely, only to find that no amount of config changes could remove it.

I had installed it, as part of my system bootstrap, using nix-env --install neovim and this alternate version of neovim was what I had been opening this whole time.
nix-env --uninstall neovim followed by a rebuild, finally fixed the issue.

Whoever is reading this, whenever in the future, I sincerely hope this helps. Good luck on your nix journey.

@teto
Copy link
Collaborator

teto commented Apr 23, 2024

sry to hear this. My fork of home-manager installs plugins in the $HOME folder such that this would have worked even with an alternate neovim. It was once merged but we had to roll it back, you just reminded me to merge it again (though there is only so much time in a day :'( ).

@lucidph3nx
Copy link

Its all good @teto, it all worked out in the end, I just hope my comment prevents similar pain to others getting started in nix.

I've come across a lot of your code in my search and its clear that an immense amount work has gone into this stuff by yourself and an army of others. Thank you so much for your contributions here, I really appreciate them.

@teto
Copy link
Collaborator

teto commented Apr 23, 2024

nixpkgs historically wraps neovim (my intent being to limit the amount of wrapping): a good way to debug what neovim executable you are using with less $(readlink -f $(which nvim))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug triage Issues or feature request that have not been triaged yet
Projects
None yet
Development

No branches or pull requests

6 participants