From 6019ce784c1a0558a817402e080c0941274928d7 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 18 Dec 2024 19:47:37 +0000 Subject: [PATCH] lib/{neovim,vim}-plugin: use `loc` throughout --- lib/neovim-plugin.nix | 30 ++++++++++++++---------------- lib/vim-plugin.nix | 28 +++++++++++++--------------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/lib/neovim-plugin.nix b/lib/neovim-plugin.nix index 63a40bd5..cdbfb53e 100644 --- a/lib/neovim-plugin.nix +++ b/lib/neovim-plugin.nix @@ -53,6 +53,10 @@ }@args: let namespace = if isColorscheme then "colorschemes" else "plugins"; + loc = [ + namespace + name + ]; module = { @@ -62,8 +66,8 @@ ... }: let - cfg = config.${namespace}.${name}; - opts = options.${namespace}.${name}; + cfg = lib.getAttrFromPath loc config; + opts = lib.getAttrFromPath loc options; setupCode = '' require('${moduleName}')${setup}(${ @@ -79,14 +83,11 @@ nixvimInfo = { inherit description; url = args.url or opts.package.default.meta.homepage; - path = [ - namespace - name - ]; + path = loc; }; }; - options.${namespace}.${name} = + options = lib.setAttrByPath loc ( { enable = lib.mkEnableOption packPathName; lazyLoad = lib.nixvim.mkLazyLoadOption packPathName; @@ -129,7 +130,8 @@ description = "The plugin's lua configuration"; }; } - // extraOptions; + // extraOptions + ); config = assert lib.assertMsg ( @@ -160,7 +162,7 @@ ++ (lib.optionals hasLuaConfig [ # Add the plugin setup code `require('foo').setup(...)` to the lua configuration - (lib.optionalAttrs callSetup { ${namespace}.${name}.luaConfig.content = setupCode; }) + (lib.optionalAttrs callSetup (lib.setAttrByPath loc { luaConfig.content = setupCode; })) # When NOT lazy loading, write `luaConfig.content` to `configLocation` (lib.mkIf (!cfg.lazyLoad.enable) luaConfigAtLocation) @@ -203,17 +205,13 @@ { imports = let - basePluginPath = [ - namespace - name - ]; - settingsPath = basePluginPath ++ [ "settings" ]; + settingsPath = loc ++ [ "settings" ]; in imports ++ [ module ] ++ (lib.optional deprecateExtraOptions ( - lib.mkRenamedOptionModule (basePluginPath ++ [ "extraOptions" ]) settingsPath + lib.mkRenamedOptionModule (loc ++ [ "extraOptions" ]) settingsPath )) - ++ (lib.nixvim.mkSettingsRenamedOptionModules basePluginPath settingsPath optionsRenamedToSettings); + ++ (lib.nixvim.mkSettingsRenamedOptionModules loc settingsPath optionsRenamedToSettings); }; } diff --git a/lib/vim-plugin.nix b/lib/vim-plugin.nix index 6d56aced..c4e97548 100644 --- a/lib/vim-plugin.nix +++ b/lib/vim-plugin.nix @@ -56,6 +56,10 @@ rec { }@args: let namespace = if isColorscheme then "colorschemes" else "plugins"; + loc = [ + namespace + name + ]; createSettingsOption = (lib.isString globalPrefix) && (globalPrefix != ""); @@ -75,8 +79,8 @@ rec { ... }: let - cfg = config.${namespace}.${name}; - opts = options.${namespace}.${name}; + cfg = lib.getAttrFromPath loc config; + opts = lib.getAttrFromPath loc options; in { meta = { @@ -84,14 +88,11 @@ rec { nixvimInfo = { inherit description; url = args.url or opts.package.default.meta.homepage; - path = [ - namespace - name - ]; + path = loc; }; }; - options.${namespace}.${name} = + options = lib.setAttrByPath loc ( { enable = lib.mkEnableOption packPathName; package = @@ -120,7 +121,8 @@ rec { }; } // settingsOption - // extraOptions; + // extraOptions + ); config = lib.mkIf cfg.enable ( lib.mkMerge [ @@ -146,17 +148,13 @@ rec { { imports = let - basePluginPath = [ - namespace - name - ]; - settingsPath = basePluginPath ++ [ "settings" ]; + settingsPath = loc ++ [ "settings" ]; in imports ++ [ module ] ++ (lib.optional (deprecateExtraConfig && createSettingsOption) ( - lib.mkRenamedOptionModule (basePluginPath ++ [ "extraConfig" ]) settingsPath + lib.mkRenamedOptionModule (loc ++ [ "extraConfig" ]) settingsPath )) - ++ (lib.nixvim.mkSettingsRenamedOptionModules basePluginPath settingsPath optionsRenamedToSettings); + ++ (lib.nixvim.mkSettingsRenamedOptionModules loc settingsPath optionsRenamedToSettings); }; }