diff --git a/lib/modules.nix b/lib/modules.nix index e09ffeab..75d5946d 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -10,6 +10,9 @@ let # Removed 2024-09-27 specialArgs = "It has been integrated into `evalNixvim`"; specialArgsWith = "It has been integrated into `evalNixvim`"; + # Removed 2024-12-18 + applyExtraConfig = "It has been moved to `lib.plugins.utils`"; + mkConfigAt = "It has been moved to `lib.plugins.utils`"; }; in { @@ -45,37 +48,6 @@ in helpers = self; } // extraSpecialArgs; }; - - /** - Apply an `extraConfig` definition, which should produce a `config` definition. - As used by `mkVimPlugin` and `mkNeovimPlugin`. - - The result will be wrapped using a `mkIf` definition. - */ - applyExtraConfig = - { - extraConfig, - cfg, - opts, - enabled ? cfg.enable or (throw "`enabled` argument not provided and no `cfg.enable` option found."), - }: - let - maybeApply = x: maybeFn: if builtins.isFunction maybeFn then maybeFn x else maybeFn; - in - lib.pipe extraConfig [ - (maybeApply cfg) - (maybeApply opts) - (lib.mkIf enabled) - ]; - - mkConfigAt = - loc: def: - let - isOrder = loc._type or null == "order"; - withOrder = if isOrder then lib.modules.mkOrder loc.priority else lib.id; - loc' = lib.toList (if isOrder then loc.content else loc); - in - lib.setAttrByPath loc' (withOrder def); } // lib.mapAttrs ( name: msg: diff --git a/lib/plugins/default.nix b/lib/plugins/default.nix index cf507021..341d4a16 100644 --- a/lib/plugins/default.nix +++ b/lib/plugins/default.nix @@ -3,6 +3,7 @@ lib, }: { + utils = call ./utils.nix { }; neovim = call ./neovim.nix { }; vim = call ./vim.nix { }; diff --git a/lib/plugins/mk-neovim-plugin.nix b/lib/plugins/mk-neovim-plugin.nix index 369aac33..ddb89a49 100644 --- a/lib/plugins/mk-neovim-plugin.nix +++ b/lib/plugins/mk-neovim-plugin.nix @@ -61,7 +61,7 @@ let }) ''; - luaConfigAtLocation = lib.nixvim.modules.mkConfigAt configLocation cfg.luaConfig.content; + luaConfigAtLocation = lib.nixvim.plugins.utils.mkConfigAt configLocation cfg.luaConfig.content; in { meta = { @@ -139,7 +139,7 @@ let # Apply any additional configuration added to `extraConfig` (lib.optionalAttrs (args ? extraConfig) ( - lib.nixvim.modules.applyExtraConfig { + lib.nixvim.plugins.utils.applyExtraConfig { inherit extraConfig cfg opts; } )) diff --git a/lib/plugins/mk-vim-plugin.nix b/lib/plugins/mk-vim-plugin.nix index 20ceddc1..bbf7b1c8 100644 --- a/lib/plugins/mk-vim-plugin.nix +++ b/lib/plugins/mk-vim-plugin.nix @@ -116,7 +116,7 @@ let colorscheme = lib.mkDefault colorscheme; }) (lib.optionalAttrs (args ? extraConfig) ( - lib.nixvim.modules.applyExtraConfig { + lib.nixvim.plugins.utils.applyExtraConfig { inherit extraConfig cfg opts; } )) diff --git a/lib/plugins/utils.nix b/lib/plugins/utils.nix new file mode 100644 index 00000000..03a2278a --- /dev/null +++ b/lib/plugins/utils.nix @@ -0,0 +1,34 @@ +{ lib }: +{ + + /** + Apply an `extraConfig` definition, which should produce a `config` definition. + As used by `mkVimPlugin` and `mkNeovimPlugin`. + + The result will be wrapped using a `mkIf` definition. + */ + applyExtraConfig = + { + extraConfig, + cfg, + opts, + enabled ? cfg.enable or (throw "`enabled` argument not provided and no `cfg.enable` option found."), + }: + let + maybeApply = x: maybeFn: if builtins.isFunction maybeFn then maybeFn x else maybeFn; + in + lib.pipe extraConfig [ + (maybeApply cfg) + (maybeApply opts) + (lib.mkIf enabled) + ]; + + mkConfigAt = + loc: def: + let + isOrder = loc._type or null == "order"; + withOrder = if isOrder then lib.modules.mkOrder loc.priority else lib.id; + loc' = lib.toList (if isOrder then loc.content else loc); + in + lib.setAttrByPath loc' (withOrder def); +} diff --git a/plugins/by-name/telescope/extensions/_mk-extension.nix b/plugins/by-name/telescope/extensions/_mk-extension.nix index 048c8d33..c115c00d 100644 --- a/plugins/by-name/telescope/extensions/_mk-extension.nix +++ b/plugins/by-name/telescope/extensions/_mk-extension.nix @@ -74,7 +74,7 @@ let options, ... }: - lib.nixvim.modules.applyExtraConfig { + lib.nixvim.plugins.utils.applyExtraConfig { inherit extraConfig; cfg = getPluginAttr config; opts = getPluginAttr options; diff --git a/plugins/lsp/language-servers/_mk-lsp.nix b/plugins/lsp/language-servers/_mk-lsp.nix index 59595be3..95c92265 100644 --- a/plugins/lsp/language-servers/_mk-lsp.nix +++ b/plugins/lsp/language-servers/_mk-lsp.nix @@ -150,7 +150,7 @@ in end '' ); - settings = lib.nixvim.modules.applyExtraConfig { + settings = lib.nixvim.plugins.utils.applyExtraConfig { extraConfig = settings; cfg = cfg.settings; opts = opts.settings; @@ -177,7 +177,7 @@ in ) "You can use `${basePluginPathString}.extraOptions.settings` instead.") ] ++ lib.optional (args ? extraConfig) ( - lib.nixvim.modules.applyExtraConfig { + lib.nixvim.plugins.utils.applyExtraConfig { inherit extraConfig cfg diff --git a/tests/lib-tests.nix b/tests/lib-tests.nix index 98400f85..c3ad7161 100644 --- a/tests/lib-tests.nix +++ b/tests/lib-tests.nix @@ -464,7 +464,7 @@ let }; testMkLuaConfig = { - expr = lib.mapAttrs (_: loc: helpers.modules.mkConfigAt loc "Hello!") { + expr = lib.mapAttrs (_: loc: helpers.plugins.utils.mkConfigAt loc "Hello!") { "simple string" = "foo"; "simple list" = [ "foo"