diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index be904bd619..5768d3b999 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -62,7 +62,7 @@ A template plugin can be found in (plugins/TEMPLATE.nix)[https://github.com/nix- | **url** | The URL of the plugin's repository. | Yes | `package` parameter's `meta.homepage` | | **callSetup** | Indicating whether to call the setup function. Useful when `setup` function needs customizations. | No | `true` | | **colorscheme** | The name of the colorscheme. | No | `name` parameter | -| **configLocation** | The location for the Lua configuration. | No | `"extraConfigLuaPre"` if `isColorscheme` then `extraConfigLuaPre`, otherwise `"extraConfigLua"` | +| **configLocation** | The option location where the lua configuration should be installed. Nested option locations can be represented as a list. The location can also be wrapped using `lib.mkBefore`, `lib.mkAfter`, or `lib.mkOrder`. | No | `"extraConfigLuaPre"` if `isColorscheme` then `extraConfigLuaPre`, otherwise `"extraConfigLua"` | | **deprecateExtraOptions** | Indicating whether to deprecate the `extraOptions` attribute. Mainly used for old plugins. | No | `false` | | **description** | A brief description of the plugin. Can also be used for non-normative documentation, warnings, tips and tricks. | No | `null` | | **extraConfig** | Additional configuration for the plugin. Either an attrset, a function accepting `cfg`, or a function accepting `cfg` and `opts`. | No | `{}` | diff --git a/lib/modules.nix b/lib/modules.nix index bd492c0b43..ff89e1641d 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -58,6 +58,15 @@ in (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/neovim-plugin.nix b/lib/neovim-plugin.nix index e15856d4dc..c4668cb237 100644 --- a/lib/neovim-plugin.nix +++ b/lib/neovim-plugin.nix @@ -71,7 +71,7 @@ }) ''; - setLuaConfig = lib.setAttrByPath (lib.toList configLocation); + luaConfigAtLocation = lib.nixvim.modules.mkConfigAt configLocation cfg.luaConfig.content; in { meta = { @@ -162,8 +162,8 @@ # Add the plugin setup code `require('foo').setup(...)` to the lua configuration (lib.optionalAttrs callSetup { ${namespace}.${name}.luaConfig.content = setupCode; }) - # Write the lua configuration `luaConfig.content` to the config file when lazy loading is not enabled - (lib.mkIf (!cfg.lazyLoad.enable) (setLuaConfig cfg.luaConfig.content)) + # When NOT lazy loading, write `luaConfig.content` to `configLocation` + (lib.mkIf (!cfg.lazyLoad.enable) luaConfigAtLocation) # When lazy loading is enabled for this plugin, route its configuration to the enabled provider (lib.mkIf cfg.lazyLoad.enable { diff --git a/tests/lib-tests.nix b/tests/lib-tests.nix index cc08e08677..dee7dfe334 100644 --- a/tests/lib-tests.nix +++ b/tests/lib-tests.nix @@ -451,6 +451,34 @@ let EOFFF''; }; }; + + testMkLuaConfig = { + expr = lib.mapAttrs (_: loc: helpers.modules.mkConfigAt loc "Hello!") { + "simple string" = "foo"; + "simple list" = [ + "foo" + "bar" + ]; + "mkBefore string" = lib.mkBefore "foo"; + "mkBefore list" = lib.mkBefore [ + "foo" + "bar" + ]; + "mkAfter string" = lib.mkAfter "foo"; + "mkAfter list" = lib.mkAfter [ + "foo" + "bar" + ]; + }; + expected = { + "simple string".foo = "Hello!"; + "simple list".foo.bar = "Hello!"; + "mkBefore string".foo = lib.mkBefore "Hello!"; + "mkBefore list".foo.bar = lib.mkBefore "Hello!"; + "mkAfter string".foo = lib.mkAfter "Hello!"; + "mkAfter list".foo.bar = lib.mkAfter "Hello!"; + }; + }; }; in if results == [ ] then