Mixing Debian-packaged Neovim plugins with Lazy.nvim
I've been packaging Neovim plugins for Debian for some time, and a few other people are doing the same. Debian unstable now ships a good number of Neovim plugins. I wanted my config to use these packages, both to dogfood and test them and to gradually migrate to them.
However, I still rely on plugins that aren't available in the archive. So I figured out how to make Lazy work with Debian packages.
Why are we packaging plugins in the first place?
The main advantage of packaging plugins in Debian is that it takes some of the maintenance burden off users.
Many Neovim plugins don't have formal releases, so it's not always obvious when it's safe to upgrade. Sometimes, a needed fix comes bundled with new features that require a newer Neovim version than the one available in Debian.
By packaging them, we can ensure they're tested and work with the Neovim version shipped in Debian. That way, users get stable, compatible updates without having to track upstream changes themselves.
I'm already doing this work whenever I need to update plugins or Neovim on my machine, so packaging them just formalizes the process and makes the benefits available to everyone.
Here's the full list of plugins I'm planning to package to complete my goal of having my Neovim-as-IDE setup available in Debian:
https://people.debian.org/~cipriano/nvim-as-ide-plugins/neovim-plugins.html
Where Debian puts the plugins
First, a bit of context. Every neovim-* package installs
its plugin into Neovim's system-wide package directory:
/usr/share/nvim/site/pack/dist-bundle/start/<name>
Normally, Neovim automatically loads plugins found under
start/ at startup. If I weren't using plugins that aren't
packaged yet, my configuration would be pretty straightforward.
The layout
This is how I organize my configuration:
├── init.lua
├── lazy-lock.json
├── lua
│ ├── helpers
│ │ ├── debian.lua
│ │ ├── icons.lua
│ │ ├── language_servers.lua
│ │ └── treesitter_langs.lua
│ ├── keymaps.lua
│ ├── keymaps_plugins.lua
│ ├── Lazy.lua
│ ├── options.lua
│ ├── plugins
│ │ └── <plugin-name>.lua
│ └── plugins_debian
│ ├── libs.lua
│ └── <plugin-name>.lua
lua/plugins holds the plugins that don't have a Debian
package, while lua/plugins_debian holds the ones that do.
Lazy imports both directories:
require("lazy").setup({
{ import = "plugins" },
{ import = "plugins_debian" }, -- Uses the .deb when installed, see lua/helpers/debian.lua
}, {...}This separation isn't strictly necessary, as we'll see later. I just find it useful for keeping track of which plugins are already packaged and which ones still need work.
The whole trick
Lazy supports a dir field in a plugin spec, which is
intended for local plugins. When dir is set, Lazy loads the
plugin from that directory instead of cloning its repository.
When dir is nil, Lazy behaves as if the
field wasn't set and uses the repository specified in the plugin spec
instead.
That's why I have lua/helpers/debian.lua, which contains
a single helper function. It returns the dist-bundle
directory if the package is installed, and nil
otherwise:
return function(name)
local dir = "/usr/share/nvim/site/pack/dist-bundle/start/" .. name
return vim.uv.fs_stat(dir) and dir or nil
endWith this function, we can write something like this:
local deb = require("helpers.debian")
return {
"tpope/vim-fugitive",
dir = deb("fugitive"),
event = "BufReadPre",
}If the Debian package is installed, Lazy uses it. Otherwise, it falls back to cloning the repository as usual.
This also means I can use the same configuration on my work machine, which runs Ubuntu and doesn't have all the packages available in Debian unstable.
To check where each plugin is coming from, just open
:Lazy and look at its path. After installing a new Debian
package, I can manually run :Lazy clean to remove the old
Git clone.
Optional packages
Another useful feature is being able to enable plugins only when certain packages are installed.
For example, vimtex will only work if I have the
vim-vimtex package installed. I use Lazy's
enabled field to enforce this:
local deb = require("helpers.debian")
local vimtex_dir = deb("vimtex")
return {
"lervag/vimtex",
dir = vimtex_dir,
enabled = vimtex_dir ~= nil,
...
}This way, Lazy won't try to clone or load vimtex on machines where the Debian package isn't installed.
Lazy does not load start packages automatically
There's one more thing to keep in mind: every plugin I want to use needs a spec, even the ones that don't require any configuration.
This is what plugins_debian/libs.lua is for:
-- Plugins without configuration, used as dependencies by others.
local deb = require("helpers.debian")
return {
-- neovim-plenary
{ "nvim-lua/plenary.nvim", dir = deb("plenary") },
-- neovim-promise-async
{ "kevinhwang91/promise-async", dir = deb("promise-async") },
-- neovim-telescope-fzf-native
{ "nvim-telescope/telescope-fzf-native.nvim", dir = deb("telescope-fzf-native.nvim"), build = "make" },
}The reason for this is that Lazy takes over the plugin loading
process and sets loadplugins=false, effectively disabling
Neovim's normal plugin loading mechanism.
As a result, the plugin/ scripts inside
dist-bundle/start aren't automatically sourced. Lazy needs
to manage these plugins itself, which is why they must be included in
its specs.
neovim-treesitter caveats
There are a few additional details worth mentioning when using Debian-packaged plugins.
The Debian package for nvim-treesitter disables the
:TSInstall and :TSUpdate commands through a
patch, but the Lua API for installing parsers is still available.
I use the get_installed() function to check which
parsers are missing and install them automatically.
This is another part of the setup I still want to improve, I'd like to use parsers packaged in Debian instead of downloading and compiling them separately.
Here's my nvim-treesitter configuration:
local deb = require("helpers.debian")
-- Lua install() still works: it downloads each parser tarball with curl, extracts
-- it with tar and compiles it with `tree-sitter build` (which calls cc).
local required_executables = { "curl", "tar", "tree-sitter", "cc" }
local function install_parser()
local ts = require("nvim-treesitter")
local installed = ts.get_installed("parsers")
local missing = vim.tbl_filter(function(lang)
return not vim.list_contains(installed, lang)
end, require("helpers.treesitter_langs"))
if #missing == 0 then
return
end
local missing_exes = vim.tbl_filter(function(exe)
return vim.fn.executable(exe) == 0
end, required_executables)
if #missing_exes > 0 then
vim.notify(
(
"nvim-treesitter: cannot install parsers (%s), missing executables: %s\n"
.. "sudo apt install curl tree-sitter-cli gcc libc6-dev"
):format(table.concat(missing, ", "), table.concat(missing_exes, ", ")),
vim.log.levels.WARN
)
return
end
ts.install(missing)
end
return {
"nvim-treesitter/nvim-treesitter",
dir = deb("nvim-treesitter"),
...
config = function()
install_parser()
vim.api.nvim_create_autocmd("FileType", {...})
end,
}I also check for the required executables before attempting installation. Otherwise, the installation can fail silently without making it particularly obvious why.
It's not necessarily the best solution, but it works for now.
What's left
Maybe we can have a Debian package called neovim-as-ide
or something similar in the future. Who knows? It would be useful to
have an easy way to set up a complete Neovim environment by simply
running apt install.
The end goal is to get rid of Lazy entirely. Once everything is
packaged, Neovim can load the plugins directly from
dist-bundle/start, and the configuration will just consist
of setup() calls.
Until then, a dir field and a four-line helper are
enough to make apt and Lazy work together.
Written on 2026-11-30.