2024-09-29 14:41:41 +01:00
|
|
|
{ lib }:
|
2024-12-17 18:13:02 +01:00
|
|
|
rec {
|
|
|
|
mkSettingsOptionDescription =
|
|
|
|
{ name, globalPrefix }:
|
|
|
|
''
|
|
|
|
The configuration options for **${name}** without the `${globalPrefix}` prefix.
|
|
|
|
|
|
|
|
For example, the following settings are equivialent to these `:setglobal` commands:
|
|
|
|
- `foo_bar = 1` -> `:setglobal ${globalPrefix}foo_bar=1`
|
|
|
|
- `hello = "world"` -> `:setglobal ${globalPrefix}hello="world"`
|
|
|
|
- `some_toggle = true` -> `:setglobal ${globalPrefix}some_toggle`
|
|
|
|
- `other_toggle = false` -> `:setglobal no${globalPrefix}other_toggle`
|
|
|
|
'';
|
|
|
|
|
|
|
|
mkSettingsOption =
|
|
|
|
{
|
|
|
|
options ? { },
|
|
|
|
example ? { },
|
|
|
|
name,
|
|
|
|
globalPrefix,
|
|
|
|
}:
|
|
|
|
lib.nixvim.mkSettingsOption {
|
|
|
|
inherit options example;
|
|
|
|
description = mkSettingsOptionDescription { inherit name globalPrefix; };
|
|
|
|
};
|
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
mkVimPlugin =
|
|
|
|
{
|
|
|
|
name,
|
2024-09-01 09:39:25 +01:00
|
|
|
url ? throw "default",
|
2024-05-05 19:39:35 +02:00
|
|
|
maintainers,
|
|
|
|
imports ? [ ],
|
|
|
|
description ? null,
|
|
|
|
# deprecations
|
|
|
|
deprecateExtraConfig ? false,
|
|
|
|
optionsRenamedToSettings ? [ ],
|
|
|
|
# colorscheme
|
|
|
|
isColorscheme ? false,
|
|
|
|
colorscheme ? name,
|
|
|
|
# options
|
2024-12-13 08:27:14 -06:00
|
|
|
packPathName ? name,
|
2024-09-01 09:39:25 +01:00
|
|
|
# Can be a string, a list of strings, or a module option:
|
|
|
|
# - A string will be intrpreted as `pkgs.vimPlugins.${package}`
|
|
|
|
# - A list will be interpreted as a "pkgs path", e.g. `pkgs.${elem1}.${elem2}.${etc...}`
|
|
|
|
# - An option will be used as-is, but should be built using `lib.mkPackageOption`
|
2024-09-02 14:05:11 +01:00
|
|
|
# Defaults to `name`, i.e. `pkgs.vimPlugins.${name}`
|
|
|
|
package ? name,
|
2024-05-05 19:39:35 +02:00
|
|
|
settingsOptions ? { },
|
|
|
|
settingsExample ? null,
|
|
|
|
globalPrefix ? "",
|
|
|
|
extraOptions ? { },
|
|
|
|
# config
|
|
|
|
extraConfig ? cfg: { },
|
|
|
|
extraPlugins ? [ ],
|
|
|
|
extraPackages ? [ ],
|
2024-09-01 09:39:25 +01:00
|
|
|
}@args:
|
2024-05-05 19:39:35 +02:00
|
|
|
let
|
|
|
|
namespace = if isColorscheme then "colorschemes" else "plugins";
|
2024-03-08 12:06:00 +01:00
|
|
|
|
2024-08-30 14:49:20 -05:00
|
|
|
createSettingsOption = (lib.isString globalPrefix) && (globalPrefix != "");
|
2024-02-12 12:07:50 +01:00
|
|
|
|
2024-08-30 14:49:20 -05:00
|
|
|
settingsOption = lib.optionalAttrs createSettingsOption {
|
2024-12-17 18:13:02 +01:00
|
|
|
settings = mkSettingsOption {
|
2024-02-12 16:13:52 +01:00
|
|
|
options = settingsOptions;
|
|
|
|
example = settingsExample;
|
2024-12-17 18:13:02 +01:00
|
|
|
inherit name globalPrefix;
|
2024-01-24 22:49:29 +01:00
|
|
|
};
|
2024-02-12 12:07:50 +01:00
|
|
|
};
|
2024-09-01 12:36:31 +01:00
|
|
|
|
2024-09-01 09:39:25 +01:00
|
|
|
module =
|
|
|
|
{
|
|
|
|
config,
|
|
|
|
options,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.${namespace}.${name};
|
2024-11-19 13:55:33 +00:00
|
|
|
opts = options.${namespace}.${name};
|
2024-09-01 09:39:25 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
meta = {
|
|
|
|
inherit maintainers;
|
|
|
|
nixvimInfo = {
|
|
|
|
inherit description;
|
2024-11-19 13:55:33 +00:00
|
|
|
url = args.url or opts.package.default.meta.homepage;
|
2024-09-01 09:39:25 +01:00
|
|
|
path = [
|
|
|
|
namespace
|
|
|
|
name
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-12-06 11:33:22 +01:00
|
|
|
options.${namespace}.${name} =
|
|
|
|
{
|
2024-12-13 08:27:14 -06:00
|
|
|
enable = lib.mkEnableOption packPathName;
|
2024-12-06 11:33:22 +01:00
|
|
|
package =
|
|
|
|
if lib.isOption package then
|
|
|
|
package
|
|
|
|
else
|
2024-12-13 08:27:14 -06:00
|
|
|
lib.mkPackageOption pkgs packPathName {
|
2024-12-06 11:33:22 +01:00
|
|
|
default =
|
|
|
|
if builtins.isList package then
|
2024-09-01 09:39:25 +01:00
|
|
|
package
|
2024-12-06 11:33:22 +01:00
|
|
|
else
|
|
|
|
[
|
|
|
|
"vimPlugins"
|
|
|
|
package
|
|
|
|
];
|
|
|
|
};
|
|
|
|
packageDecorator = lib.mkOption {
|
|
|
|
type = lib.types.functionTo lib.types.package;
|
|
|
|
default = lib.id;
|
|
|
|
defaultText = lib.literalExpression "x: x";
|
|
|
|
description = ''
|
|
|
|
Additional transformations to apply to the final installed package.
|
|
|
|
The result of these transformations is **not** visible in the `package` option's value.
|
|
|
|
'';
|
|
|
|
internal = true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// settingsOption
|
|
|
|
// extraOptions;
|
2024-09-01 09:39:25 +01:00
|
|
|
|
2024-08-30 14:49:20 -05:00
|
|
|
config = lib.mkIf cfg.enable (
|
|
|
|
lib.mkMerge [
|
|
|
|
{
|
|
|
|
inherit extraPackages;
|
2024-11-15 17:28:47 +00:00
|
|
|
extraPlugins = extraPlugins ++ [
|
|
|
|
(cfg.packageDecorator cfg.package)
|
|
|
|
];
|
2024-12-17 21:18:57 +01:00
|
|
|
globals = lib.nixvim.applyPrefixToAttrs globalPrefix (cfg.settings or { });
|
2024-08-30 14:49:20 -05:00
|
|
|
}
|
|
|
|
(lib.optionalAttrs (isColorscheme && (colorscheme != null)) {
|
|
|
|
colorscheme = lib.mkDefault colorscheme;
|
|
|
|
})
|
2024-11-19 13:55:33 +00:00
|
|
|
(lib.optionalAttrs (args ? extraConfig) (
|
|
|
|
lib.nixvim.modules.applyExtraConfig {
|
|
|
|
inherit extraConfig cfg opts;
|
|
|
|
}
|
|
|
|
))
|
2024-08-30 14:49:20 -05:00
|
|
|
]
|
|
|
|
);
|
2024-09-01 09:39:25 +01:00
|
|
|
};
|
2024-05-05 19:39:35 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
imports =
|
|
|
|
let
|
|
|
|
basePluginPath = [
|
|
|
|
namespace
|
|
|
|
name
|
|
|
|
];
|
|
|
|
settingsPath = basePluginPath ++ [ "settings" ];
|
|
|
|
in
|
|
|
|
imports
|
2024-09-01 09:39:25 +01:00
|
|
|
++ [ module ]
|
2024-08-30 14:49:20 -05:00
|
|
|
++ (lib.optional (deprecateExtraConfig && createSettingsOption) (
|
|
|
|
lib.mkRenamedOptionModule (basePluginPath ++ [ "extraConfig" ]) settingsPath
|
2024-05-05 19:39:35 +02:00
|
|
|
))
|
2024-08-30 14:49:20 -05:00
|
|
|
++ (lib.nixvim.mkSettingsRenamedOptionModules basePluginPath settingsPath optionsRenamedToSettings);
|
2024-05-05 19:39:35 +02:00
|
|
|
};
|
2024-01-24 22:49:29 +01:00
|
|
|
}
|