mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-02 21:34:33 +02:00
lib/*-plugin: use lib.mkPackageOption
internally
Instead of maintainers providing an actual `defaultPackage`, they should specify the pkg name which we'll use when calling `lib.mkPackageOption`. This makes `mkVimPlugin` and `mkNeovimPlugin` compliant with #1950.
This commit is contained in:
parent
c8bb7880bf
commit
285f6cbd7b
6 changed files with 150 additions and 109 deletions
|
@ -17,7 +17,7 @@ with lib;
|
|||
{
|
||||
name,
|
||||
maintainers,
|
||||
url ? defaultPackage.meta.homepage,
|
||||
url ? throw "default",
|
||||
imports ? [ ],
|
||||
description ? null,
|
||||
# deprecations
|
||||
|
@ -28,7 +28,13 @@ with lib;
|
|||
colorscheme ? name,
|
||||
# options
|
||||
originalName ? name,
|
||||
defaultPackage,
|
||||
# WARNING: `defaultPackage` is deprecated by `package`,
|
||||
defaultPackage ? throw "mkVimPlugin called without either `package` or `defaultPackage`.",
|
||||
# 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`
|
||||
package ? helpers.mkPluginPackageOption originalName defaultPackage,
|
||||
settingsOptions ? { },
|
||||
settingsExample ? null,
|
||||
settingsDescription ? "Options provided to the `require('${luaName}')${setup}` function.",
|
||||
|
@ -42,22 +48,78 @@ with lib;
|
|||
extraPackages ? [ ],
|
||||
callSetup ? true,
|
||||
installPackage ? true,
|
||||
}:
|
||||
}@args:
|
||||
let
|
||||
namespace = if isColorscheme then "colorschemes" else "plugins";
|
||||
|
||||
module =
|
||||
{
|
||||
config,
|
||||
options,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.${namespace}.${name};
|
||||
opt = options.${namespace}.${name};
|
||||
extraConfigNamespace = if isColorscheme then "extraConfigLuaPre" else "extraConfigLua";
|
||||
in
|
||||
{
|
||||
meta = {
|
||||
inherit maintainers;
|
||||
nixvimInfo = {
|
||||
inherit description;
|
||||
url = args.url or opt.package.default.meta.homepage;
|
||||
path = [
|
||||
namespace
|
||||
name
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
options.${namespace}.${name} =
|
||||
{
|
||||
enable = mkEnableOption originalName;
|
||||
package =
|
||||
if lib.isOption package then
|
||||
package
|
||||
else
|
||||
lib.mkPackageOption pkgs originalName {
|
||||
default =
|
||||
if builtins.isList package then
|
||||
package
|
||||
else
|
||||
[
|
||||
"vimPlugins"
|
||||
package
|
||||
];
|
||||
};
|
||||
}
|
||||
// optionalAttrs hasSettings {
|
||||
settings = helpers.mkSettingsOption {
|
||||
description = settingsDescription;
|
||||
options = settingsOptions;
|
||||
example = settingsExample;
|
||||
};
|
||||
}
|
||||
// extraOptions;
|
||||
|
||||
config = mkIf cfg.enable (mkMerge [
|
||||
{
|
||||
extraPlugins = (optional installPackage cfg.package) ++ extraPlugins;
|
||||
inherit extraPackages;
|
||||
}
|
||||
(optionalAttrs callSetup {
|
||||
${extraConfigNamespace} = ''
|
||||
require('${luaName}')${setup}(${optionalString (cfg ? settings) (helpers.toLuaObject cfg.settings)})
|
||||
'';
|
||||
})
|
||||
(optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; })
|
||||
(extraConfig cfg)
|
||||
]);
|
||||
};
|
||||
in
|
||||
{
|
||||
meta = {
|
||||
inherit maintainers;
|
||||
nixvimInfo = {
|
||||
inherit description url;
|
||||
path = [
|
||||
namespace
|
||||
name
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
imports =
|
||||
let
|
||||
basePluginPath = [
|
||||
|
@ -67,49 +129,10 @@ with lib;
|
|||
settingsPath = basePluginPath ++ [ "settings" ];
|
||||
in
|
||||
imports
|
||||
++ [ module ]
|
||||
++ (optional deprecateExtraOptions (
|
||||
mkRenamedOptionModule (basePluginPath ++ [ "extraOptions" ]) settingsPath
|
||||
))
|
||||
++ (nixvim.mkSettingsRenamedOptionModules basePluginPath settingsPath optionsRenamedToSettings)
|
||||
++ [
|
||||
(
|
||||
{ config, ... }:
|
||||
{
|
||||
config =
|
||||
let
|
||||
cfg = config.${namespace}.${name};
|
||||
extraConfigNamespace = if isColorscheme then "extraConfigLuaPre" else "extraConfigLua";
|
||||
in
|
||||
mkIf cfg.enable (mkMerge [
|
||||
{
|
||||
extraPlugins = (optional installPackage cfg.package) ++ extraPlugins;
|
||||
inherit extraPackages;
|
||||
}
|
||||
(optionalAttrs callSetup {
|
||||
${extraConfigNamespace} = ''
|
||||
require('${luaName}')${setup}(${optionalString (cfg ? settings) (helpers.toLuaObject cfg.settings)})
|
||||
'';
|
||||
})
|
||||
(optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; })
|
||||
(extraConfig cfg)
|
||||
]);
|
||||
}
|
||||
)
|
||||
];
|
||||
|
||||
options.${namespace}.${name} =
|
||||
{
|
||||
enable = mkEnableOption originalName;
|
||||
|
||||
package = helpers.mkPluginPackageOption originalName defaultPackage;
|
||||
}
|
||||
// optionalAttrs hasSettings {
|
||||
settings = helpers.mkSettingsOption {
|
||||
description = settingsDescription;
|
||||
options = settingsOptions;
|
||||
example = settingsExample;
|
||||
};
|
||||
}
|
||||
// extraOptions;
|
||||
++ (nixvim.mkSettingsRenamedOptionModules basePluginPath settingsPath optionsRenamedToSettings);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue