2024-12-18 23:15:09 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
utils,
|
|
|
|
}:
|
2024-12-18 21:05:05 +00:00
|
|
|
{
|
|
|
|
name,
|
|
|
|
maintainers,
|
2025-01-27 18:55:45 +00:00
|
|
|
url ? null,
|
2024-12-18 21:05:05 +00:00
|
|
|
imports ? [ ],
|
|
|
|
description ? null,
|
|
|
|
# deprecations
|
|
|
|
deprecateExtraOptions ? false,
|
|
|
|
optionsRenamedToSettings ? [ ],
|
|
|
|
# colorscheme
|
|
|
|
isColorscheme ? false,
|
|
|
|
colorscheme ? name,
|
|
|
|
# luaConfig
|
|
|
|
configLocation ? if isColorscheme then "extraConfigLuaPre" else "extraConfigLua",
|
|
|
|
# Some plugin are not supposed to generate lua configuration code.
|
|
|
|
# For example, they might just be configured through some other mean, like global variables
|
|
|
|
hasLuaConfig ? true,
|
|
|
|
# options
|
|
|
|
packPathName ? name,
|
|
|
|
# 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`
|
|
|
|
# Defaults to `name`, i.e. `pkgs.vimPlugins.${name}`
|
|
|
|
package ? name,
|
2025-04-27 09:13:33 +02:00
|
|
|
# Which dependencies to enable by default
|
|
|
|
dependencies ? [ ],
|
2024-12-18 21:05:05 +00:00
|
|
|
settingsOptions ? { },
|
|
|
|
settingsExample ? null,
|
|
|
|
settingsDescription ? "Options provided to the `require('${moduleName}')${setup}` function.",
|
|
|
|
hasSettings ? true,
|
|
|
|
extraOptions ? { },
|
|
|
|
# config
|
|
|
|
moduleName ? name,
|
|
|
|
setup ? ".setup",
|
|
|
|
extraConfig ? cfg: { },
|
|
|
|
extraPlugins ? [ ],
|
|
|
|
extraPackages ? [ ],
|
|
|
|
callSetup ? true,
|
|
|
|
}@args:
|
|
|
|
let
|
|
|
|
namespace = if isColorscheme then "colorschemes" else "plugins";
|
|
|
|
loc = [
|
|
|
|
namespace
|
|
|
|
name
|
|
|
|
];
|
|
|
|
|
|
|
|
module =
|
2024-12-18 22:29:47 +00:00
|
|
|
{ config, options, ... }:
|
2024-12-18 21:05:05 +00:00
|
|
|
let
|
|
|
|
cfg = lib.getAttrFromPath loc config;
|
|
|
|
opts = lib.getAttrFromPath loc options;
|
|
|
|
|
|
|
|
setupCode = ''
|
|
|
|
require('${moduleName}')${setup}(${
|
|
|
|
lib.optionalString (cfg ? settings) (lib.nixvim.toLuaObject cfg.settings)
|
|
|
|
})
|
|
|
|
'';
|
|
|
|
|
2024-12-18 23:15:09 +00:00
|
|
|
luaConfigAtLocation = utils.mkConfigAt configLocation cfg.luaConfig.content;
|
2024-12-18 21:05:05 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = lib.setAttrByPath loc (
|
|
|
|
{
|
|
|
|
enable = lib.mkEnableOption packPathName;
|
2024-12-26 07:13:32 -03:00
|
|
|
autoLoad = lib.nixvim.mkAutoLoadOption cfg packPathName;
|
2024-12-18 21:05:05 +00:00
|
|
|
lazyLoad = lib.nixvim.mkLazyLoadOption packPathName;
|
|
|
|
}
|
|
|
|
// lib.optionalAttrs hasSettings {
|
|
|
|
settings = lib.nixvim.mkSettingsOption {
|
|
|
|
description = settingsDescription;
|
|
|
|
options = settingsOptions;
|
|
|
|
example = settingsExample;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// lib.optionalAttrs hasLuaConfig {
|
|
|
|
luaConfig = lib.mkOption {
|
|
|
|
type = lib.types.pluginLuaConfig;
|
|
|
|
default = { };
|
|
|
|
description = "The plugin's lua configuration";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// extraOptions
|
|
|
|
);
|
|
|
|
|
|
|
|
config =
|
|
|
|
assert lib.assertMsg (
|
|
|
|
callSetup -> hasLuaConfig
|
|
|
|
) "This plugin is supposed to call the `setup()` function but has `hasLuaConfig` set to false";
|
|
|
|
lib.mkIf cfg.enable (
|
|
|
|
lib.mkMerge (
|
|
|
|
[
|
2024-12-18 22:29:47 +00:00
|
|
|
{ inherit extraPackages extraPlugins; }
|
2024-12-18 21:05:05 +00:00
|
|
|
|
|
|
|
(lib.optionalAttrs (isColorscheme && colorscheme != null) {
|
|
|
|
colorscheme = lib.mkDefault colorscheme;
|
|
|
|
})
|
|
|
|
|
|
|
|
# Apply any additional configuration added to `extraConfig`
|
|
|
|
(lib.optionalAttrs (args ? extraConfig) (
|
2024-12-18 23:15:09 +00:00
|
|
|
utils.applyExtraConfig {
|
2024-12-18 21:05:05 +00:00
|
|
|
inherit extraConfig cfg opts;
|
|
|
|
}
|
|
|
|
))
|
|
|
|
|
2025-04-27 09:13:33 +02:00
|
|
|
(lib.nixvim.plugins.utils.enableDependencies dependencies)
|
|
|
|
|
2024-12-18 21:05:05 +00:00
|
|
|
# When lazy loading is enabled for this plugin, route its configuration to the enabled provider
|
|
|
|
(lib.mkIf cfg.lazyLoad.enable {
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = (isColorscheme && colorscheme != null) || cfg.lazyLoad.settings != { };
|
|
|
|
message = "You have enabled lazy loading for ${packPathName} but have not provided any configuration.";
|
|
|
|
}
|
|
|
|
];
|
2024-12-25 17:25:53 -03:00
|
|
|
|
2024-12-18 21:05:05 +00:00
|
|
|
plugins.lz-n = {
|
|
|
|
plugins = [
|
|
|
|
(
|
|
|
|
{
|
|
|
|
__unkeyed-1 = packPathName;
|
|
|
|
# Use provided after, otherwise fallback to normal function wrapped lua content
|
|
|
|
after =
|
|
|
|
let
|
|
|
|
after = cfg.lazyLoad.settings.after or null;
|
2024-12-25 17:25:53 -03:00
|
|
|
default = if hasLuaConfig then "function()\n " + cfg.luaConfig.content + " \nend" else null;
|
2024-12-18 21:05:05 +00:00
|
|
|
in
|
|
|
|
if (lib.isString after || lib.types.rawLua.check after) then after else default;
|
|
|
|
colorscheme = lib.mkIf isColorscheme (cfg.lazyLoad.settings.colorscheme or colorscheme);
|
|
|
|
}
|
|
|
|
// lib.removeAttrs cfg.lazyLoad.settings [
|
|
|
|
"after"
|
|
|
|
"colorscheme"
|
|
|
|
]
|
|
|
|
)
|
|
|
|
];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
]
|
2024-12-25 17:25:53 -03:00
|
|
|
# Lua configuration code generation
|
|
|
|
++ lib.optionals hasLuaConfig [
|
|
|
|
|
|
|
|
# Add the plugin setup code `require('foo').setup(...)` to the lua configuration
|
|
|
|
(lib.optionalAttrs callSetup (lib.setAttrByPath loc { luaConfig.content = setupCode; }))
|
|
|
|
|
|
|
|
# When NOT lazy loading, write `luaConfig.content` to `configLocation`
|
|
|
|
(lib.mkIf (!cfg.lazyLoad.enable) luaConfigAtLocation)
|
|
|
|
]
|
2024-12-18 21:05:05 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
imports =
|
|
|
|
let
|
|
|
|
settingsPath = loc ++ [ "settings" ];
|
|
|
|
in
|
|
|
|
imports
|
2024-12-18 22:29:47 +00:00
|
|
|
++ [
|
|
|
|
module
|
2024-12-18 23:15:09 +00:00
|
|
|
(utils.mkPluginPackageModule { inherit loc packPathName package; })
|
2025-01-27 18:55:45 +00:00
|
|
|
(utils.mkMetaModule {
|
|
|
|
inherit
|
|
|
|
loc
|
|
|
|
maintainers
|
|
|
|
description
|
|
|
|
url
|
|
|
|
;
|
|
|
|
})
|
2024-12-18 22:29:47 +00:00
|
|
|
]
|
2024-12-18 21:05:05 +00:00
|
|
|
++ lib.optional deprecateExtraOptions (
|
|
|
|
lib.mkRenamedOptionModule (loc ++ [ "extraOptions" ]) settingsPath
|
|
|
|
)
|
|
|
|
++ lib.nixvim.mkSettingsRenamedOptionModules loc settingsPath optionsRenamedToSettings;
|
|
|
|
}
|