mirror of
https://github.com/nix-community/nixvim.git
synced 2025-08-02 00:54:48 +02:00
plugins/telescope: refactor mkExtension
Allow importing `mkExtension` without needing to supply any dependencies. All dependencies can be accessed via module args anyway.
This commit is contained in:
parent
c674f10d18
commit
929bb0cd1c
11 changed files with 115 additions and 136 deletions
85
plugins/by-name/telescope/extensions/_mk-extension.nix
Normal file
85
plugins/by-name/telescope/extensions/_mk-extension.nix
Normal file
|
@ -0,0 +1,85 @@
|
|||
{
|
||||
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
|
||||
builtins.map (
|
||||
option:
|
||||
let
|
||||
optionPath = lib.toList option;
|
||||
optionPathSnakeCase = map lib.nixvim.toSnakeCase optionPath;
|
||||
in
|
||||
lib.mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase)
|
||||
) 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 = { config, ... }: extraConfig (getPluginAttr config);
|
||||
in
|
||||
{
|
||||
imports = imports ++ [
|
||||
module
|
||||
extraConfigModule
|
||||
renameModule
|
||||
];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue