wrapper/environment: add vim.appName corresponding to NVIM_APPNAME

This commit is contained in:
Gabriel Nützi 2026-06-13 13:14:15 +02:00
commit 2b3b0d0c46
No known key found for this signature in database
GPG key ID: 37A5F59C07097058
2 changed files with 72 additions and 39 deletions

View file

@ -4,17 +4,25 @@
pkgs, pkgs,
lib, lib,
... ...
}: let }:
let
inherit (pkgs) vimPlugins; inherit (pkgs) vimPlugins;
inherit (lib.trivial) flip; inherit (lib.trivial) flip;
inherit (builtins) filter isString hasAttr getAttr; inherit (builtins)
filter
isString
hasAttr
getAttr
;
getPin = flip getAttr (inputs.mnw.lib.npinsToPluginsAttrs pkgs ../../../npins/sources.json); getPin = flip getAttr (inputs.mnw.lib.npinsToPluginsAttrs pkgs ../../../npins/sources.json);
# Build a Vim plugin with the given name and arguments. # Build a Vim plugin with the given name and arguments.
buildPlug = attrs: let buildPlug =
pin = getPin attrs.pname; attrs:
in let
pin = getPin attrs.pname;
in
pkgs.vimUtils.buildVimPlugin ( pkgs.vimUtils.buildVimPlugin (
{ {
version = pin.revision or "dirty"; version = pin.revision or "dirty";
@ -24,16 +32,14 @@
); );
# Build a given Treesitter grammar. # Build a given Treesitter grammar.
buildTreesitterPlug = grammars: buildTreesitterPlug =
vimPlugins.nvim-treesitter.withPlugins ( grammars: vimPlugins.nvim-treesitter.withPlugins (_: builtins.filter (g: g != null) grammars);
_: builtins.filter (g: g != null) grammars
);
pluginBuilders = { pluginBuilders = {
nvim-treesitter = buildTreesitterPlug config.vim.treesitter.grammars; nvim-treesitter = buildTreesitterPlug config.vim.treesitter.grammars;
flutter-tools-patched = buildPlug { flutter-tools-patched = buildPlug {
pname = "flutter-tools-nvim"; pname = "flutter-tools-nvim";
patches = [./patches/flutter-tools.patch]; patches = [ ./patches/flutter-tools.patch ];
# Disable failing require check hook checks # Disable failing require check hook checks
doCheck = false; doCheck = false;
@ -60,27 +66,28 @@
inherit (inputs.self.packages.${pkgs.stdenv.system}) blink-cmp avante-nvim; inherit (inputs.self.packages.${pkgs.stdenv.system}) blink-cmp avante-nvim;
}; };
buildConfigPlugins = plugins: buildConfigPlugins =
map (plug: plugins:
if (isString plug) map (
then plug:
if hasAttr plug config.vim.pluginOverrides if (isString plug) then
then if hasAttr plug config.vim.pluginOverrides then
(let (
plugin = config.vim.pluginOverrides.${plug}; let
in plugin = config.vim.pluginOverrides.${plug};
if (lib.isType "flake" plugin) in
then plugin // {name = plug;} if (lib.isType "flake" plugin) then plugin // { name = plug; } else plugin
else plugin) )
else pluginBuilders.${plug} or (getPin plug) else
else plug) ( pluginBuilders.${plug} or (getPin plug)
filter (f: f != null) plugins else
); plug
) (filter (f: f != null) plugins);
# 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"; appName = config.vim.appName;
neovim = config.vim.package; neovim = config.vim.package;
initLua = config.vim.builtLuaConfigRC; initLua = config.vim.builtLuaConfigRC;
luaFiles = config.vim.extraLuaFiles; luaFiles = config.vim.extraLuaFiles;
@ -97,7 +104,7 @@
nodeJs.enable = config.vim.withNodeJs; 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) ++ [ps.pynvim]; extraPackages = ps: (map (flip builtins.getAttr ps) config.vim.python3Packages) ++ [ ps.pynvim ];
}; };
}; };
@ -121,7 +128,11 @@
# or module consumption. # or module consumption.
neovim = pkgs.symlinkJoin { neovim = pkgs.symlinkJoin {
name = "nvf-with-helpers"; name = "nvf-with-helpers";
paths = [neovim-wrapped printConfig printConfigPath]; paths = [
neovim-wrapped
printConfig
printConfigPath
];
postBuild = "echo Helpers added"; postBuild = "echo Helpers added";
passthru = { passthru = {
@ -142,13 +153,12 @@
mnwConfigDir = neovim-wrapped.passthru.configDir; mnwConfigDir = neovim-wrapped.passthru.configDir;
}; };
meta = meta = neovim-wrapped.meta // {
neovim-wrapped.meta description = "Wrapped Neovim package with helper scripts to print the config (path)";
// { };
description = "Wrapped Neovim package with helper scripts to print the config (path)";
};
}; };
in { in
{
config.vim.build = { config.vim.build = {
finalPackage = neovim; finalPackage = neovim;
}; };

View file

@ -3,11 +3,34 @@
lib, lib,
... ...
}: let }: let
inherit (lib.options) mkOption mkEnableOption literalMD literalExpression; inherit
inherit (lib.types) package bool str listOf attrsOf; (lib.options)
mkOption
mkEnableOption
literalMD
literalExpression
;
inherit
(lib.types)
package
bool
str
listOf
attrsOf
;
inherit (lib.nvim.types) pluginsOpt extraPluginType; inherit (lib.nvim.types) pluginsOpt extraPluginType;
in { in {
options.vim = { options.vim = {
appName = mkOption {
type = str;
default = "nvf";
description = ''
The neovim application name corresponding to the
`NVIM_APPNAME`
[environment variable](https://neovim.io/doc/user/starting/#_nvim_appname).
'';
};
package = mkOption { package = mkOption {
type = package; type = package;
default = pkgs.neovim-unwrapped; default = pkgs.neovim-unwrapped;
@ -99,7 +122,7 @@ in {
extraPackages = mkOption { extraPackages = mkOption {
type = listOf package; type = listOf package;
default = []; default = [];
example = ''[pkgs.fzf pkgs.ripgrep]''; example = "[pkgs.fzf pkgs.ripgrep]";
description = '' description = ''
List of additional packages to make available to the Neovim List of additional packages to make available to the Neovim
wrapper. wrapper.