diff --git a/lib/plugins/mk-neovim-plugin.nix b/lib/plugins/mk-neovim-plugin.nix index ddb89a49..4bf51eac 100644 --- a/lib/plugins/mk-neovim-plugin.nix +++ b/lib/plugins/mk-neovim-plugin.nix @@ -45,12 +45,7 @@ let ]; module = - { - config, - options, - pkgs, - ... - }: + { config, options, ... }: let cfg = lib.getAttrFromPath loc config; opts = lib.getAttrFromPath loc options; @@ -77,30 +72,6 @@ let { enable = lib.mkEnableOption packPathName; lazyLoad = lib.nixvim.mkLazyLoadOption packPathName; - package = - if lib.isOption package then - package - else - lib.mkPackageOption pkgs packPathName { - default = - if builtins.isList package then - package - else - [ - "vimPlugins" - 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; - }; } // lib.optionalAttrs hasSettings { settings = lib.nixvim.mkSettingsOption { @@ -126,12 +97,7 @@ let lib.mkIf cfg.enable ( lib.mkMerge ( [ - { - inherit extraPackages; - extraPlugins = extraPlugins ++ [ - (cfg.packageDecorator cfg.package) - ]; - } + { inherit extraPackages extraPlugins; } (lib.optionalAttrs (isColorscheme && colorscheme != null) { colorscheme = lib.mkDefault colorscheme; @@ -194,7 +160,10 @@ in settingsPath = loc ++ [ "settings" ]; in imports - ++ [ module ] + ++ [ + module + (lib.nixvim.plugins.utils.mkPluginPackageModule { inherit loc packPathName package; }) + ] ++ lib.optional deprecateExtraOptions ( lib.mkRenamedOptionModule (loc ++ [ "extraOptions" ]) settingsPath ) diff --git a/lib/plugins/mk-vim-plugin.nix b/lib/plugins/mk-vim-plugin.nix index bbf7b1c8..48e0ff10 100644 --- a/lib/plugins/mk-vim-plugin.nix +++ b/lib/plugins/mk-vim-plugin.nix @@ -51,12 +51,7 @@ let }; module = - { - config, - options, - pkgs, - ... - }: + { config, options, ... }: let cfg = lib.getAttrFromPath loc config; opts = lib.getAttrFromPath loc options; @@ -74,30 +69,6 @@ let options = lib.setAttrByPath loc ( { enable = lib.mkEnableOption packPathName; - package = - if lib.isOption package then - package - else - lib.mkPackageOption pkgs packPathName { - default = - if builtins.isList package then - package - else - [ - "vimPlugins" - 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; - }; } // settingsOption // extraOptions @@ -106,10 +77,7 @@ let config = lib.mkIf cfg.enable ( lib.mkMerge [ { - inherit extraPackages; - extraPlugins = extraPlugins ++ [ - (cfg.packageDecorator cfg.package) - ]; + inherit extraPackages extraPlugins; globals = lib.nixvim.applyPrefixToAttrs globalPrefix (cfg.settings or { }); } (lib.optionalAttrs (isColorscheme && colorscheme != null) { @@ -130,7 +98,10 @@ in settingsPath = loc ++ [ "settings" ]; in imports - ++ [ module ] + ++ [ + module + (lib.nixvim.plugins.utils.mkPluginPackageModule { inherit loc packPathName package; }) + ] ++ lib.optional (deprecateExtraConfig && createSettingsOption) ( lib.mkRenamedOptionModule (loc ++ [ "extraConfig" ]) settingsPath ) diff --git a/lib/plugins/utils.nix b/lib/plugins/utils.nix index 03a2278a..a93e24de 100644 --- a/lib/plugins/utils.nix +++ b/lib/plugins/utils.nix @@ -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) ]; + }; + }; }