nix-community.nixvim/plugins/by-name/telescope/extensions/_mk-extension.nix
Matt Sturgeon 896f6be694
lib/plugins: take ownership of modules utils
These util functions were previously defined in `modules`, but
`plugins.utils` is a better home.
2024-12-22 09:35:16 +00:00

89 lines
1.9 KiB
Nix

{
name,
package,
extensionName ? name,
settingsOptions ? { },
settingsExample ? null,
extraOptions ? { },
imports ? [ ],
optionsRenamedToSettings ? [ ],
extraConfig ? cfg: { },
}:
let
getPluginAttr = attrs: attrs.plugins.telescope.extensions.${name};
renameModule =
{ lib, ... }:
{
# TODO remove this once all deprecation warnings will have been removed.
imports =
let
basePluginPath = [
"plugins"
"telescope"
"extensions"
name
];
settingsPath = basePluginPath ++ [ "settings" ];
in
lib.nixvim.mkSettingsRenamedOptionModules basePluginPath settingsPath optionsRenamedToSettings;
};
module =
{
lib,
config,
pkgs,
...
}:
let
cfg = getPluginAttr config;
in
{
options.plugins.telescope.extensions.${name} = {
enable = lib.mkEnableOption "the `${name}` telescope extension";
package = lib.mkPackageOption pkgs name {
default = [
"vimPlugins"
package
];
};
settings = lib.nixvim.mkSettingsOption {
description = "settings for the `${name}` telescope extension.";
options = settingsOptions;
example = settingsExample;
};
} // extraOptions;
config = lib.mkIf cfg.enable {
extraPlugins = [ cfg.package ];
plugins.telescope = {
enabledExtensions = [ extensionName ];
settings.extensions.${extensionName} = cfg.settings;
};
};
};
extraConfigModule =
{
lib,
config,
options,
...
}:
lib.nixvim.plugins.utils.applyExtraConfig {
inherit extraConfig;
cfg = getPluginAttr config;
opts = getPluginAttr options;
};
in
{
imports = imports ++ [
module
extraConfigModule
renameModule
];
}