neovim module migrations #188
Replies: 9 comments 4 replies
-
|
Yes. The |
Beta Was this translation helpful? Give feedback.
-
|
Oh, thank you, didn't notice that |
Beta Was this translation helpful? Give feedback.
-
|
and the plugins also take impure paths :) |
Beta Was this translation helpful? Give feedback.
-
|
oh, you can also |
Beta Was this translation helpful? Give feedback.
-
|
also if it seems like its weird that the name of an option has an underscore in it, it translates to lua directly and you can find it in the info plugin. This is a general rule with the nvim module's existing options. |
Beta Was this translation helpful? Give feedback.
-
|
Also you may find this module useful in your journey of moving stuff over, to replace the standard plugin overlay. { config, lib, ... }: {
options.nvim-lib.pluginsFromPrefix = lib.mkOption {
type = lib.types.raw;
readOnly = true;
default =
prefix: inputs:
lib.pipe inputs [
builtins.attrNames
(builtins.filter (s: lib.hasPrefix prefix s))
(map (
input:
let
name = lib.removePrefix prefix input;
in
{
inherit name;
value = config.nvim-lib.mkPlugin name inputs.${input};
}
))
builtins.listToAttrs
];
};
}Import it via the imports list, and then you could do this neovimPlugins = config.nvim-lib.pluginsFromPrefix "plugins-" inputs; |
Beta Was this translation helpful? Give feedback.
-
|
Some lua utils local M
M.isNix = vim.g.nix_info_plugin_name ~= nil
-- function to get the path to a plugin
function M.get_nix_plugin_path(name)
local nixInfo = require(vim.g.nix_info_plugin_name)
return nixInfo(nil, "plugins", "lazy", name) or nixInfo(nil, "plugins", "start", name)
end
-- handler for lze to disable the plugin if not installed via nix if flagged for auto_enable
-- If you used nixCats, this is kinda like the for_cat handler, but checks plugin installation and not category
M.auto_enable_handler = {
spec_field = "auto_enable",
set_lazy = false,
modify = function(plugin)
if M.isNix then
if type(plugin.auto_enable) == "table" then
for _, name in pairs(plugin.auto_enable) do
if not M.get_nix_plugin_path(name) then
plugin.enabled = false
break
end
end
elseif type(plugin.auto_enable) == "string" then
if not M.get_nix_plugin_path(plugin.auto_enable) then
plugin.enabled = false
end
elseif type(plugin.auto_enable) == "boolean" and plugin.auto_enable then
if not M.get_nix_plugin_path(plugin.name) then
plugin.enabled = false
end
end
end
return plugin
end,
}
return MFor the lze handler register the handler at the start of your config require('lze').register_handlers { require('idk').auto_enable_handler, }And now require('lze').load {
{
"eyeliner.nvim",
auto_enable = true,
event = "DeferredUIEnter",
-- keys = "",
after = function(_)
-- Highlights unique characters for f/F and t/T motions
require('eyeliner').setup {
highlight_on_key = true, -- show highlights only after key press
dim = true, -- dim all other characters
}
end,
},
{
"vim-dadbod",
auto_enable = {
"vim-dadbod",
"vim-dadbod-ui",
"vim-dadbod-completion",
},
cmd = { "DB", "DBUI", "DBUIAddConnection", "DBUIClose",
"DBUIToggle", "DBUIFindBuffer", "DBUILastQueryInfo", "DBUIRenameBuffer", },
load = function(name)
vim.cmd.packadd(name)
vim.cmd.packadd("vim-dadbod-ui")
vim.cmd.packadd("vim-dadbod-completion")
vim.cmd.packadd("vim-dadbod-completion/after")
end,
after = function(_)
end,
},
} |
Beta Was this translation helpful? Give feedback.
-
|
If you want to be able to put what is in extraPackages directly into your specs, you can make a module which looks something like this and import it { config, lib, wlib, ... }: {
config.specMods = {
options.extraPackages = lib.mkOption {
type = lib.types.listOf wlib.types.stringable;
default = [ ];
description = "a extraPackages spec field to put packages to suffix to the PATH";
};
};
config.extraPackages = config.specCollect (acc: v: acc ++ (v.extraPackages or [ ])) [ ];
}also, on the note of putting stuff directly in specs, you can use them like categories config.info.cats = builtins.mapAttrs (_: v: v.enable) config.specs;if require(vim.g.nix_info_plugin_name)(false, "info", "cats", "NAME") then
-- do something
endAnd a lze handler for that like the auto_enable one above to throw in the same file and register M.for_cat_handler = {
spec_field = "for_cat",
set_lazy = false,
modify = function(plugin)
local nixInfo = require(vim.g.nix_info_plugin_name)
if vim.g.nix_info_plugin_name then
if type(plugin.for_cat) == "table" then
plugin.enabled = nixInfo(plugin.for_cat.default, "info", "cats", plugin.for_cat.cat)
elseif type(plugin.for_cat) == "string" then
plugin.enabled = nixInfo(false, "info", "cats", plugin.for_cat)
end
end
return plugin
end,
}Please feel free to edit any of these snippets to your liking, they are to give you ideas, and because I wanted them when I was transferring my config from nixCats to this one. I may add them to the template and/or swap the template over to lze and/or add a new template which uses lze, but I also don't want to bias people, there might be an even better way to use this module I don't know about, this was just the first thing that came to mind for me was to add the cats back Edit: all of this except the lze handlers are in the tips and tricks section of the docs! Edit 2: All of this is in the template now. |
Beta Was this translation helpful? Give feedback.
-
|
Lazy.nvim the way nixCats does it (Don't do this, use lze or lz.n instead this is bad because it does a ton of extra stuff and is thus slower and harder to reason about, and you MUST make a lazy.nvim spec if you want nix installed plugins to work when doing it this way, even if you are loading it at startup without any config, and I also have not tested the converted version, so use at your own risk). Source: this nixCats template Usage is the same (assuming this is somehow without syntax errors due to github coding) make sure names match up between nix and lazy.nvim or you will install it twice, it's version 1 (requires collate_grammars to be true for specs, which it is by default): ---lazy.nvim wrapper
---lazy.nvim setup function but with an optional first argument for if lazy.nvim is in a weird place and a few options preset
---@overload fun(nixLazyPath: string|nil, lazySpec: any, opts: table)
---@overload fun(nixLazyPath: string|nil, opts: table)
local function setup(nixLazyPath, lazySpec, opts)
local lazySpecs = nil
local lazyCFG = nil
if opts == nil and type(lazySpec) == "table" and lazySpec.spec then
lazyCFG = lazySpec
else
lazySpecs = lazySpec
lazyCFG = opts
end
local lazypath
if not vim.g.nix_info_plugin_name then
vim.pack.add({ "https://github.com/folke/lazy.nvim" }, { load = true, confirm = false })
lazypath = (vim.pack.get({ "lazy.nvim" }, { info = false })[1] or {}).path -- <-- ?? I think??
else
local nixInfo = require(vim.g.nix_info_plugin_name)
local function get_nix_plugin_path(name)
return nixInfo(nil, "plugins", "lazy", name) or nixInfo(nil, "plugins", "start", name)
end
lazypath = nixLazyPath or get_nix_plugin_path("lazy.nvim")
if lazypath == nil then
vim.pack.add({ "https://github.com/folke/lazy.nvim" }, { load = true, confirm = false })
lazypath = (vim.pack.get({ "lazy.nvim" }, { info = false })[1] or {}).path -- <-- ?? I think??
end
local fallback = ((lazyCFG or {}).dev or {}).fallback
lazyCFG = vim.tbl_deep_extend("force", lazyCFG or {}, {
performance = {
rtp = {
reset = false,
},
},
dev = {
path = function(plugin)
return get_nix_plugin_path(plugin.name)
end,
patterns = { "" },
fallback = fallback == nil and true or fallback,
}
})
-- do the reset we disabled without removing important stuff
local cfgdir = nixInfo.settings.config_directory
vim.opt.rtp = {
cfgdir,
nixInfo.info_plugin_path,
nixInfo.plugins.start.COLLATED_TS_GRAMMARS,
vim.fn.stdpath("data") .. "/site",
lazypath,
vim.env.VIMRUNTIME,
vim.fn.fnamemodify(vim.v.progpath, ":p:h:h") .. "/lib/nvim",
cfgdir .. "/after",
}
end
if lazySpecs then
require('lazy').setup(lazySpecs, lazyCFG)
else
require('lazy').setup(lazyCFG)
end
endversion 2: This might also work, if you use it, let me know if it does or not, because its cleaner than the above version. Theoretically, this one should work fine? But it is possible nix provided treesitter grammars bug out, if you provided any from nix, so if they throw an error which says something about your queries when you try this, it doesn't work and you need to do it the above way. But this SHOULD work. ---lazy.nvim wrapper
---lazy.nvim setup function but with an optional first argument for if lazy.nvim is in a weird place and a few options preset
---@overload fun(lazy_is_pre_installed: boolean?, lazySpec: any, opts: table)
---@overload fun(lazy_is_pre_installed: boolean?, opts: table)
local function setup(lazy_is_pre_installed, lazySpec, opts)
local lazySpecs = nil
local lazyCFG = nil
if opts == nil and type(lazySpec) == "table" and lazySpec.spec then
lazyCFG = lazySpec
else
lazySpecs = lazySpec
lazyCFG = opts
end
if not vim.g.nix_info_plugin_name then
vim.pack.add({ "https://github.com/folke/lazy.nvim" }, { load = true, confirm = false })
else
local nixInfo = require(vim.g.nix_info_plugin_name)
local function get_nix_plugin_path(name)
return nixInfo(nil, "plugins", "lazy", name) or nixInfo(nil, "plugins", "start", name)
end
if not (lazy_is_pre_installed or get_nix_plugin_path("lazy.nvim")) then
vim.pack.add({ "https://github.com/folke/lazy.nvim" }, { load = true, confirm = false })
end
local fallback = ((lazyCFG or {}).dev or {}).fallback
lazyCFG = vim.tbl_deep_extend("force", lazyCFG or {}, {
performance = {
rtp = {
reset = false,
},
reset_packpath = false,
},
dev = {
path = function(plugin)
return get_nix_plugin_path(plugin.name)
end,
patterns = { "" },
fallback = fallback == nil and true or fallback,
}
})
end
if lazySpecs then
require('lazy').setup(lazySpecs, lazyCFG)
else
require('lazy').setup(lazyCFG)
end
endIf you try this and the second one works, let me know so I can delete the first version I showed in this comment because the second one is way nicer and will feel identical to the first one use (i.e. you have to make sure the names match between nix and lazy.nvim if you want it to pick up the thing from nix or lazy.nvim will still try to install it, but otherwise, basically just lazy.nvim + nix as one might expect, where one must make a lazy.nvim spec for their plugin if they want it to work even if nix installed it) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
wrapRc = falseI often use that feature from nixCats to test out new configs without rebuilding the system. Is it possible to do it here?
Beta Was this translation helpful? Give feedback.
All reactions