mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
lib/plugins: extract common logic for package
options
Adds `mkPluginPackageModule`.
This commit is contained in:
parent
896f6be694
commit
690fc895b5
3 changed files with 58 additions and 72 deletions
|
@ -31,4 +31,50 @@
|
|||
loc' = lib.toList (if isOrder then loc.content else loc);
|
||||
in
|
||||
lib.setAttrByPath loc' (withOrder def);
|
||||
|
||||
mkPluginPackageModule =
|
||||
{
|
||||
loc,
|
||||
packPathName,
|
||||
package,
|
||||
}:
|
||||
# Return a module
|
||||
{ config, pkgs, ... }:
|
||||
let
|
||||
cfg = lib.getAttrFromPath loc config;
|
||||
in
|
||||
{
|
||||
options = lib.setAttrByPath loc {
|
||||
package =
|
||||
if lib.isOption package then
|
||||
package
|
||||
else
|
||||
lib.mkPackageOption pkgs packPathName {
|
||||
default =
|
||||
if builtins.isList package then
|
||||
package
|
||||
else if builtins.isString package then
|
||||
[
|
||||
"vimPlugins"
|
||||
package
|
||||
]
|
||||
else
|
||||
throw "Unexpected `package` type for `${lib.showOption loc}` expected (option, list, or string), but found: ${builtins.typeOf 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;
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
extraPlugins = [ (cfg.packageDecorator cfg.package) ];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue