-
-
Notifications
You must be signed in to change notification settings - Fork 239
/
vim-plugin.nix
115 lines (106 loc) · 3.22 KB
/
vim-plugin.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
{
lib,
nixvimOptions,
nixvimUtils,
}:
with lib;
{
mkVimPlugin =
config:
{
name,
url ? if defaultPackage != null then defaultPackage.meta.homepage else null,
maintainers,
imports ? [ ],
description ? null,
# deprecations
deprecateExtraConfig ? false,
optionsRenamedToSettings ? [ ],
# colorscheme
isColorscheme ? false,
colorscheme ? name,
# options
originalName ? name,
defaultPackage ? null,
settingsOptions ? { },
settingsExample ? null,
globalPrefix ? "",
extraOptions ? { },
# config
extraConfig ? cfg: { },
extraPlugins ? [ ],
extraPackages ? [ ],
}:
let
namespace = if isColorscheme then "colorschemes" else "plugins";
cfg = config.${namespace}.${name};
globals = cfg.settings or { };
# does this evaluate package?
packageOption =
if defaultPackage == null then
{ }
else
{ package = nixvimOptions.mkPluginPackageOption name defaultPackage; };
createSettingsOption = (isString globalPrefix) && (globalPrefix != "");
settingsOption = optionalAttrs createSettingsOption {
settings = nixvimOptions.mkSettingsOption {
options = settingsOptions;
example = settingsExample;
description = ''
The configuration options for **${name}** without the `${globalPrefix}` prefix.
Example: To set `${globalPrefix}foo_bar` to `1`, write
```nix
settings = {
foo_bar = true;
};
```
'';
};
};
in
{
meta = {
inherit maintainers;
nixvimInfo = {
inherit description url;
path = [
namespace
name
];
};
};
options.${namespace}.${name} = {
enable = mkEnableOption originalName;
} // settingsOption // packageOption // extraOptions;
imports =
let
basePluginPath = [
namespace
name
];
settingsPath = basePluginPath ++ [ "settings" ];
in
imports
++ (optional (deprecateExtraConfig && createSettingsOption) (
mkRenamedOptionModule (basePluginPath ++ [ "extraConfig" ]) settingsPath
))
++ (map (
option:
let
optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list)
optionPathSnakeCase = map nixvimUtils.toSnakeCase optionPath;
in
mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase)
) optionsRenamedToSettings);
config = mkIf cfg.enable (mkMerge [
{
inherit extraPackages;
globals = mapAttrs' (n: nameValuePair (globalPrefix + n)) globals;
# does this evaluate package? it would not be desired to evaluate package if we use another package.
extraPlugins = extraPlugins ++ optional (defaultPackage != null) cfg.package;
}
(optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; })
(extraConfig cfg)
]);
};
}