-
-
Notifications
You must be signed in to change notification settings - Fork 305
/
Copy pathlazy.nix
204 lines (171 loc) · 8.14 KB
/
lazy.nix
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
{ lib, pkgs, ... }:
let
inherit (lib.nixvim)
defaultNullOpts
mkNullOrOption
mkNullOrLuaFn
mkNullOrStrLuaFnOr
;
inherit (lib) types;
in
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "lazy";
originalName = "lazy.nvim";
package = "lazy-nvim";
maintainers = with lib.maintainers; [
MattSturgeon
my7h3le
];
extraOptions =
let
# A plugin defined in the `nixvim.plugins.lazy.plugins` list can either
# be of `types.package` or `types.str`. Depending on the type of the
# given plugin this plugin will conditionally return an appropriate
# plugin spec.
coerceToLazyPluginSpec =
plugin:
if lib.isDerivation plugin then
{
dir = lib.mkDefault "${plugin}";
name = lib.mkDefault "${lib.getName plugin}";
}
else if lib.isString plugin then
{ __unkeyed = lib.mkDefault plugin; }
else
plugin;
lazyPluginCoercableType = with types; either str package;
lazyPluginType =
with types;
types.coercedTo lazyPluginCoercableType coerceToLazyPluginSpec (
submodule (
{ config, ... }:
let
cfg = config;
in
{
freeformType = attrsOf anything;
options = {
__unkeyed = mkNullOrOption str ''
The "unkeyed" attribute is the plugin's short plugin url.
It ill be expanded using `config.git.url_format`. It can
also be a url or dir.
'';
dir = mkNullOrOption str "A directory pointing to a local plugin";
url = mkNullOrOption str "A custom git url where the plugin is hosted";
pkg = mkNullOrOption package "Vim plugin to install";
name = mkNullOrOption str "Name of the plugin to install";
dev = defaultNullOpts.mkBool false ''
When true, a local plugin directory will be used instead.
See config.dev
'';
lazy = defaultNullOpts.mkBool true ''
When true, the plugin will only be loaded when needed.
Lazy-loaded plugins are automatically loaded when their Lua modules are required,
or when one of the lazy-loading handlers triggers
'';
enabled = defaultNullOpts.mkStrLuaFnOr bool "`true`" ''
When false then this plugin will not be included in the spec. (accepts fun():boolean)
'';
cond = defaultNullOpts.mkStrLuaFnOr bool "`true`" ''
When false, or if the function returns false,
then this plugin will not be loaded. Useful to disable some plugins in vscode,
or firenvim for example. (accepts fun(LazyPlugin):boolean)
'';
# WARNING: Be very careful if changing the type of
# `dependencies`. Choosing the wrong type may cause a stack
# overflow due to infinite recursion, and it's very possible
# that the test cases won't catch this problem. To be safe,
# perform thorough manual testing if you do change the type of
# `dependencies`. Also use `types.eitherRecursive` instead of
# `types.either` here, as using just `types.either` also leads
# to stack overflow.
dependencies = mkNullOrOption (eitherRecursive lazyPluginType lazyPluginsListType) ''
A list of plugin names or plugin specs that should be
loaded when the plugin loads. Dependencies are always
lazy-loaded unless specified otherwise. When specifying a
name, make sure the plugin spec has been defined somewhere
else. This can also be a single string such as for a short
plugin url (See: https://lazy.folke.io/spec).
'';
init = mkNullOrLuaFn "init functions are always executed during startup";
config = mkNullOrStrLuaFnOr (enum [ true ]) ''
config is executed when the plugin loads.
The default implementation will automatically run require(MAIN).setup(opts).
Lazy uses several heuristics to determine the plugin's MAIN module automatically based on the plugin's name.
See also opts. To use the default implementation without opts set config to true.
'';
main = mkNullOrOption str ''
You can specify the main module to use for config() and opts(),
in case it can not be determined automatically. See config()
'';
submodules = defaultNullOpts.mkBool true ''
When false, git submodules will not be fetched.
Defaults to true
'';
event =
mkNullOrOption (maybeRaw (
either str (listOf str)
)) "Lazy-load on event. Events can be specified as BufEnter or with a pattern like BufEnter *.lua";
cmd = mkNullOrOption (maybeRaw (either str (listOf str))) "Lazy-load on command";
ft = mkNullOrOption (maybeRaw (either str (listOf str))) "Lazy-load on filetype";
keys = mkNullOrOption (maybeRaw (either str (listOf str))) "Lazy-load on key mapping";
module = mkNullOrOption (enum [ false ]) ''
Do not automatically load this Lua module when it's required somewhere
'';
priority = mkNullOrOption number ''
Only useful for start plugins (lazy=false) to force loading certain plugins first.
Default priority is 50. It's recommended to set this to a high number for colorschemes.
'';
optional = defaultNullOpts.mkBool false ''
When a spec is tagged optional, it will only be included in the final spec,
when the same plugin has been specified at least once somewhere else without optional.
This is mainly useful for Neovim distros, to allow setting options on plugins that may/may not be part
of the user's plugins
'';
opts =
mkNullOrOption (maybeRaw (attrsOf anything)) ''
opts should be a table (will be merged with parent specs),
return a table (replaces parent specs) or should change a table.
The table will be passed to the Plugin.config() function.
Setting this value will imply Plugin.config()
'';
};
config.name = lib.mkIf (cfg.pkg != null) (lib.mkDefault "${lib.getName cfg.pkg}");
config.dir = lib.mkIf (cfg.pkg != null) (lib.mkDefault "${cfg.pkg}");
}
)
);
lazyPluginsListType = types.listOf lazyPluginType;
in
{
gitPackage = lib.mkPackageOption pkgs "git" { nullable = true; };
luarocksPackage = lib.mkPackageOption pkgs "luarocks" { nullable = true; };
plugins = lib.mkOption {
type = lazyPluginsListType;
default = [ ];
description = "List of plugins";
};
};
extraConfig =
cfg:
let
# The `pkg` property isn't a part of the `lazy.nvim` plugin spec, while
# it shouldn't do any harm but it does take up unecessary space in the
# init.lua file. Since we're done using it we will strip it from the
# final list of specs.
removePkgAttrFromPlugin =
plugin:
builtins.removeAttrs plugin [ "pkg" ]
// lib.optionalAttrs (((plugin.dependencies or null) != null) && lib.isList plugin.dependencies) {
dependencies = map removePkgAttrFromPlugin plugin.dependencies;
};
removePkgAttrFromPlugins = plugins: map removePkgAttrFromPlugin plugins;
in
{
extraPackages = [
cfg.gitPackage
cfg.luarocksPackage
];
plugins.lazy.settings.spec = removePkgAttrFromPlugins cfg.plugins;
};
}