blob: 62958ff84bc98b4ff632d2e67e2504ccc96a2231 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
{
inputs,
config,
pkgs,
lib,
...
}: let
inherit (pkgs) vimPlugins;
inherit (lib.trivial) flip;
inherit (builtins) filter isString hasAttr getAttr;
getPin = flip getAttr (inputs.mnw.lib.npinsToPluginsAttrs pkgs ../../../npins/sources.json);
# Build a Vim plugin with the given name and arguments.
buildPlug = attrs: let
pin = getPin attrs.pname;
in
pkgs.vimUtils.buildVimPlugin (
{
version = pin.revision or "dirty";
src = pin.outPath;
}
// attrs
);
# Build a given Treesitter grammar.
buildTreesitterPlug = grammars:
vimPlugins.nvim-treesitter.withPlugins (
_: builtins.filter (g: g != null) grammars
);
pluginBuilders = {
nvim-treesitter = buildTreesitterPlug config.vim.treesitter.grammars;
flutter-tools-patched = buildPlug {
pname = "flutter-tools-nvim";
patches = [./patches/flutter-tools.patch];
# Disable failing require check hook checks
doCheck = false;
};
# Checkhealth fails to get the plugin's commit and therefore to
# show the rest of the useful diagnostics if not built like this.
obsidian-nvim = pkgs.vimUtils.buildVimPlugin {
# If set to `"obsidian-nvim"`, this breaks like `buildPlug` and .
name = "obsidian.nvim";
src = getPin "obsidian-nvim";
nvimSkipModules = [
"minimal"
# require picker plugins
"obsidian.picker._telescope"
"obsidian.picker._snacks"
"obsidian.picker._fzf"
"obsidian.picker._mini"
];
};
# 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 cord-nvim;
};
buildConfigPlugins = plugins:
map (plug:
if (isString plug)
then
if hasAttr plug config.vim.pluginOverrides
then
(let
plugin = config.vim.pluginOverrides.${plug};
in
if (lib.isType "flake" plugin)
then plugin // {name = plug;}
else plugin)
else pluginBuilders.${plug} or (getPin plug)
else plug) (
filter (f: f != null) plugins
);
neovim-wrapped = config.mnw.finalPackage;
# A store path representing the built Lua configuration.
dummyInit = pkgs.writeText "nvf-init.lua" config.vim.builtLuaConfigRC;
# Additional helper scripts for printing and displaying nvf configuration
# in your commandline.
printConfig = pkgs.writers.writeDashBin "nvf-print-config" "cat ${dummyInit}";
printConfigPath = pkgs.writers.writeDashBin "nvf-print-config-path" "echo -n ${dummyInit}";
# Expose wrapped neovim-package for userspace
# or module consumption.
neovim = pkgs.symlinkJoin {
name = "nvf-with-helpers";
paths = [neovim-wrapped printConfig printConfigPath];
postBuild = "echo Helpers added";
passthru = {
# Allow evaluating config.vim, i.e., config.vim from the packages' passthru
# attribute. For example, packages.x86_64-linux.neovim.passthru.neovimConfig
# 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;
mnwConfig = neovim-wrapped.passthru.config;
mnwConfigDir = neovim-wrapped.passthru.configDir;
};
meta =
neovim-wrapped.meta
// {
description = "Wrapped Neovim package with helper scripts to print the config (path)";
};
};
in {
config = {
vim.build.finalPackage = neovim;
mnw = {
appName = lib.mkDefault "nvf";
neovim = config.vim.package;
initLua = config.vim.builtLuaConfigRC;
luaFiles = config.vim.extraLuaFiles;
# Plugin configurations
plugins = {
start = buildConfigPlugins config.vim.startPlugins;
opt = buildConfigPlugins config.vim.optPlugins;
};
# Providers for Neovim
providers = {
ruby.enable = config.vim.withRuby;
nodeJs.enable = config.vim.withNodeJs;
python3 = {
enable = config.vim.withPython3;
extraPackages = ps: (map (flip builtins.getAttr ps) config.vim.python3Packages) ++ [ps.pynvim];
};
};
# Aliases to link `nvim` to
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 (lib.flip builtins.getAttr ps) config.vim.luaPackages;
};
};
}
|