Neovim plugins are not found

Hello :wave:

I am not able to add any plugin to neovim using home manager. When I use regular programs.neovim, it installs neovim correctly, but it does not create any init.lua file and plugins are not loaded:

programs.neovim = {
  enable = true;
  defaultEditor = true;
  viAlias = true;
  vimAlias = true;
  vimdiffAlias = true;

  plugins = with pkgs.vimPlugins; [
    nvim-tree-lua

    catppuccin-nvim

    nvim-lspconfig
    nvim-treesitter.withAllGrammars
    plenary-nvim
    gruvbox-material
    mini-nvim
  ];
};

And when I use nixvim, I get an error from a require(...) call in init.lua, and I cannot load the plugins:

rror detected while processing /home/ganyuss/.config/nvim/init.lua:
E5113: Error while calling lua chunk: /home/ganyuss/.config/nvim/init.lua:5: module 'lualine' not found:
        no field package.preload['lualine']
        no file '/nix/store/c5qdp465d4wfswhdngay2alhwxqkiczq-luajit-2.1.1713773202-env/share/lua/5.1/lualine.lua'
        no file '/nix/store/c5qdp465d4wfswhdngay2alhwxqkiczq-luajit-2.1.1713773202-env/share/lua/5.1/lualine/init.lua'
        no file '/nix/store/c5qdp465d4wfswhdngay2alhwxqkiczq-luajit-2.1.1713773202-env/lib/lua/5.1/lualine.so'
stack traceback:
        [C]: in function 'require'
        /home/ganyuss/.config/nvim/init.lua:5: in main chunk

Here is my nixvim config:

programs.nixvim = {
  enable = true;
  # plugins.catppuccin.enable = true;
  # colorschemes.catppuccin.enable = true;
  plugins.lualine.enable = true;
};

From what I have seen, it is probably because the paths to the plugins are not added in the runtimepath of neovim. But I have no idea why, nor where the huge list of paths in runtimepath comes from.

If you have any idea what I am doing wrong, that would be fantastic!

Hi, your initial neovim plugin setup looks fine, perhaps you could consider adding extra config like so:

programs.neovim = {
  enable = true;
  extraLuaConfig = builtins.readFile ./nvim/init.lua;

};

Where ./nvim/init.lua is accessed by your home.nix file, hopefully this should clear up some path issues.

Thank you for responding!

I added the init.lua file with the following content, as well as the extraLuaConfig you mentioned:

require("nvim-tree").setup()

This is the most basic setup with the nvim-tree-lua package. It creates the ~/.config/nvim/init.lua file with the correct content, but now whenever I open neovim I get this error:

Error detected while processing /home/ganyuss/.config/nvim/init.lua:
E5113: Error while calling lua chunk: /home/ganyuss/.config/nvim/init.lua:1: module 'nvim-tree' not found:
        no field package.preload['nvim-tree']
        no file '/nix/store/c5qdp465d4wfswhdngay2alhwxqkiczq-luajit-2.1.1713773202-env/share/lua/5.1/nvim-tree.lua'
        no file '/nix/store/c5qdp465d4wfswhdngay2alhwxqkiczq-luajit-2.1.1713773202-env/share/lua/5.1/nvim-tree/init.lua'
        no file '/nix/store/c5qdp465d4wfswhdngay2alhwxqkiczq-luajit-2.1.1713773202-env/lib/lua/5.1/nvim-tree.so'
stack traceback:
        [C]: in function 'require'
        /home/ganyuss/.config/nvim/init.lua:1: in main chunk

And I get the same result when running :lua require("nvim-tree").setup() in neovim.