wrapper/build: add option examples; put evaluated values in literalExpression

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I6a6a69648220a65886994d4cac67f634a61815d5
This commit is contained in:
raf 2025-09-03 14:44:46 +03:00
commit 8b98f07862
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
2 changed files with 44 additions and 25 deletions

View file

@ -22,9 +22,7 @@
passthru.vimPlugin = false; passthru.vimPlugin = false;
}; };
# build a vim plugin with the given name and arguments # Build a Vim plugin with the given name and arguments.
# if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug
# instead
buildPlug = attrs: let buildPlug = attrs: let
pin = getPin attrs.pname; pin = getPin attrs.pname;
in in
@ -36,6 +34,7 @@
// attrs // attrs
); );
# Build a given Treesitter grammar.
buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars); buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars);
pluginBuilders = { pluginBuilders = {
@ -48,6 +47,9 @@
doCheck = false; doCheck = false;
}; };
# Get plugins built from source from self.packages
# If adding a new plugin to be built from source, it must also be inherited
# here.
inherit (inputs.self.packages.${pkgs.stdenv.system}) blink-cmp avante-nvim; inherit (inputs.self.packages.${pkgs.stdenv.system}) blink-cmp avante-nvim;
}; };
@ -71,29 +73,38 @@
# Wrap the user's desired (unwrapped) Neovim package with arguments that'll be used to # Wrap the user's desired (unwrapped) Neovim package with arguments that'll be used to
# generate a wrapped Neovim package. # generate a wrapped Neovim package.
neovim-wrapped = inputs.mnw.lib.wrap {inherit pkgs;} { neovim-wrapped = inputs.mnw.lib.wrap {inherit pkgs;} {
appName = "nvf";
neovim = config.vim.package; neovim = config.vim.package;
initLua = config.vim.builtLuaConfigRC;
luaFiles = config.vim.extraLuaFiles;
# Plugin configurations
plugins = { plugins = {
start = buildConfigPlugins config.vim.startPlugins; start = buildConfigPlugins config.vim.startPlugins;
opt = buildConfigPlugins config.vim.optPlugins; opt = buildConfigPlugins config.vim.optPlugins;
}; };
appName = "nvf";
extraBinPath = config.vim.extraPackages; # Providers for Neovim
initLua = config.vim.builtLuaConfigRC;
luaFiles = config.vim.extraLuaFiles;
providers = { providers = {
ruby.enable = config.vim.withRuby;
nodeJs.enable = config.vim.withNodeJs;
python3 = { python3 = {
enable = config.vim.withPython3; enable = config.vim.withPython3;
extraPackages = ps: map (flip builtins.getAttr ps) config.vim.python3Packages; extraPackages = ps: map (flip builtins.getAttr ps) config.vim.python3Packages;
}; };
ruby.enable = config.vim.withRuby;
nodeJs.enable = config.vim.withNodeJs;
}; };
# Aliases to link `nvim` to
aliases = lib.optional config.vim.viAlias "vi" ++ lib.optional config.vim.vimAlias "vim"; aliases = lib.optional config.vim.viAlias "vi" ++ lib.optional config.vim.vimAlias "vim";
# Additional packages or Lua packages to be made available to Neovim
extraBinPath = config.vim.extraPackages;
extraLuaPackages = ps: map (flip builtins.getAttr ps) config.vim.luaPackages; extraLuaPackages = ps: map (flip builtins.getAttr ps) config.vim.luaPackages;
}; };
# A store path representing the built Lua configuration.
dummyInit = pkgs.writeText "nvf-init.lua" config.vim.builtLuaConfigRC; dummyInit = pkgs.writeText "nvf-init.lua" config.vim.builtLuaConfigRC;
# Additional helper scripts for printing and displaying nvf configuration # Additional helper scripts for printing and displaying nvf configuration
# in your commandline. # in your commandline.
printConfig = pkgs.writers.writeDashBin "nvf-print-config" "cat ${dummyInit}"; printConfig = pkgs.writers.writeDashBin "nvf-print-config" "cat ${dummyInit}";
@ -106,10 +117,20 @@
paths = [neovim-wrapped printConfig printConfigPath]; paths = [neovim-wrapped printConfig printConfigPath];
postBuild = "echo Helpers added"; postBuild = "echo Helpers added";
# Allow evaluating config.vim, i.e., config.vim from the packages' passthru passthru = {
# attribute. For example, packages.x86_64-linux.neovim.passthru.neovimConfig # Allow evaluating config.vim, i.e., config.vim from the packages' passthru
# will return the configuration in full. # attribute. For example, packages.x86_64-linux.neovim.passthru.neovimConfig
passthru.neovimConfig = config.vim; # will return the configuration in full.
neovimConfig = config.vim;
# Also expose the helper scripts in passthru.
nvfPrintConfig = printConfig;
nvfPrintConfigPath = printConfigPath;
# In systems where we only have a package and no module, this can be used
# to access the built init.lua
initLua = dummyInit;
};
meta = meta =
neovim-wrapped.meta neovim-wrapped.meta

View file

@ -3,7 +3,7 @@
lib, lib,
... ...
}: let }: let
inherit (lib.options) mkOption mkEnableOption literalMD; inherit (lib.options) mkOption mkEnableOption literalMD literalExpression;
inherit (lib.types) package bool str listOf attrsOf; inherit (lib.types) package bool str listOf attrsOf;
inherit (lib.nvim.types) pluginsOpt extraPluginType; inherit (lib.nvim.types) pluginsOpt extraPluginType;
in { in {
@ -11,6 +11,7 @@ in {
package = mkOption { package = mkOption {
type = package; type = package;
default = pkgs.neovim-unwrapped; default = pkgs.neovim-unwrapped;
defaultText = literalExpression "pkgs.neovim-unwrapped";
description = '' description = ''
The neovim package to use for the wrapper. This The neovim package to use for the wrapper. This
corresponds to the package that will be wrapped corresponds to the package that will be wrapped
@ -27,21 +28,20 @@ in {
viAlias = mkOption { viAlias = mkOption {
type = bool; type = bool;
default = true; default = true;
example = false;
description = "Enable the `vi` alias for `nvim`"; description = "Enable the `vi` alias for `nvim`";
}; };
vimAlias = mkOption { vimAlias = mkOption {
type = bool; type = bool;
default = true; default = true;
example = false;
description = "Enable the `vim` alias for `nvim`"; description = "Enable the `vim` alias for `nvim`";
}; };
startPlugins = pluginsOpt { startPlugins = pluginsOpt {
default = ["plenary-nvim"]; default = ["plenary-nvim"];
example = '' example = literalExpression "[pkgs.vimPlugins.telescope-nvim]";
[pkgs.vimPlugins.telescope-nvim]
'';
description = '' description = ''
List of plugins to load on startup. This is used List of plugins to load on startup. This is used
internally to add plugins to Neovim's runtime. internally to add plugins to Neovim's runtime.
@ -54,9 +54,7 @@ in {
optPlugins = pluginsOpt { optPlugins = pluginsOpt {
default = []; default = [];
example = '' example = literalExpression "[pkgs.vimPlugins.vim-ghost]";
[pkgs.vimPlugins.vim-ghost]
'';
description = '' description = ''
List of plugins to optionally load on startup. List of plugins to optionally load on startup.
@ -108,7 +106,7 @@ in {
''; '';
}; };
# this defaults to `true` in the wrapper # This defaults to `true` in the wrapper
# and since we pass this value to the wrapper # and since we pass this value to the wrapper
# with an inherit, it should be `true` here as well # with an inherit, it should be `true` here as well
withRuby = withRuby =
@ -120,14 +118,14 @@ in {
}; };
withNodeJs = mkEnableOption '' withNodeJs = mkEnableOption ''
NodeJs support in the Neovim wrapper NodeJS support in the Neovim wrapper
''; '';
luaPackages = mkOption { luaPackages = mkOption {
type = listOf str; type = listOf str;
default = []; default = [];
example = ''["magick" "serpent"]''; example = ''["magick" "serpent"]'';
description = "List of lua packages to install"; description = "List of Lua packages to install";
}; };
withPython3 = mkEnableOption '' withPython3 = mkEnableOption ''
@ -144,7 +142,7 @@ in {
pluginOverrides = mkOption { pluginOverrides = mkOption {
type = attrsOf package; type = attrsOf package;
default = {}; default = {};
example = '' example = literalExpression ''
{ {
lazydev-nvim = pkgs.fetchFromGitHub { lazydev-nvim = pkgs.fetchFromGitHub {
owner = "folke"; owner = "folke";