Can't load local plugin in `home-manager` installed `neovim`

I would like to locally develop a neovim plugin (or contribute to an existing one). For testing and debugging purposes, I would like to use such plugin with my neovim installation.

Currently, I installed neovim and the plugins using home-manager.
I would like to avoid using plugin managers (packer, lazy, whatever) because they add yet another layer, and, in the end, they don’t add much compared to HM…

As per How do I install Plugins in NeoVim Correctly - Stack Overflow, I thought that adding the code under ~/.local/share/nvim/site/pack/*/start/ was the way to go:

git clone https://github.com/pwntester/codeql.nvim
ln -s codeql.nvim/ ~/.local/share/nvim/site/pack/myPackages/start/

And I use the following in my init.lua:

require("codeql.nvim")

But I get the following error when starting nvim:

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

It seems that the HM installed neovim doesn’t look into the XDG base directories.
I couldn’t find an HM option to configure neovim to do it…
Surely some of you are achieving something similar in your configuration… Welp!


Similar issues:

check out what nvim contains: less $(readlink -f $(which nvim)).
Most likely it contains -u initrc in which case neovim skips parts of its normal initialization phase.

I will try to revive programs.neovim: link packpath dir in XDG_DATA_HOME by teto · Pull Request #3717 · nix-community/home-manager · GitHub (got reverted) which made nvim configured by home-manager behave more normally.

A workaround is to add your plugin to rtp: vim.opt.rtp:prepend(os.getenv("HOME").."/neovim/plenary.nvim") for instance

1 Like

I am probably missing something else, as XDG base directories are indeed included in runtimepath and packpath:

set rtp?
runtimepath=/nix/store/ig2aak3cvdjjwi0c4z7c9622g8dnrxm5-vim-pack-dir,~/.config/nvim,/etc/xdg/nvim,~/.local/share/nvim/site,~/.local/share/flatpak/exports/share/nvim/site,/var/lib/flatpak/exports/share/nvim/site,
/usr/local/share/nvim/site,/usr/share/nvim/site,/nix/store/ciga24j1nxi5g92jap6nyiqbhmn6qzrm-neovim-unwrapped-0.10.0/share/nvim/runtime,/nix/store/ciga24j1nxi5g92jap6nyiqbhmn6qzrm-neovim-unwrapped-0.10.0/lib/nvim,/
usr/share/nvim/site/after,/usr/local/share/nvim/site/after,/var/lib/flatpak/exports/share/nvim/site/after,~/.local/share/flatpak/exports/share/nvim/site/after,~/.local/share/nvim/site/after,/etc/xdg/nvim/after,~/.
config/nvim/after
set packpath?
packpath=/nix/store/ig2aak3cvdjjwi0c4z7c9622g8dnrxm5-vim-pack-dir,~/.config/nvim,/etc/xdg/nvim,~/.local/share/nvim/site,~/.local/share/flatpak/exports/share/nvim/site,/var/lib/flatpak/exports/share/nvim/site,/us
r/local/share/nvim/site,/usr/share/nvim/site,/nix/store/ciga24j1nxi5g92jap6nyiqbhmn6qzrm-neovim-unwrapped-0.10.0/share/nvim/runtime,/nix/store/ciga24j1nxi5g92jap6nyiqbhmn6qzrm-neovim-unwrapped-0.10.0/lib/nvim,/usr
/share/nvim/site/after,/usr/local/share/nvim/site/after,/var/lib/flatpak/exports/share/nvim/site/after,~/.local/share/flatpak/exports/share/nvim/site/after,~/.local/share/nvim/site/after,/etc/xdg/nvim/after,~/.con
fig/nvim/after

Most likely it contains -u initrc in which case neovim skips parts of its normal initialization phase.

It doesn’t.

A workaround is to add your plugin to rtp: vim.opt.rtp:prepend(os.getenv("HOME").."/neovim/plenary.nvim") for instance

Yeah, this adds to the runtimepath alright (but as previous message, this doesn’t seem to be the issue).

However, I still don’t see the plugin code being executed, and require(...) still fails.
In your example, what do I need to use for the plugin to be executed at runtime?

I was using the require(...) wrong: One needs to use require("codeql"), and NOT require("codeql.nvim"):roll_eyes:

Thanks @teto for your help :slightly_smiling_face: