diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix index a76a5cd6..01deeb0f 100644 --- a/modules/wrapper/lazy/config.nix +++ b/modules/wrapper/lazy/config.nix @@ -76,7 +76,13 @@ then [] else [spec.keys]; - notLazyConfig = concatStringsSep "\n" (mapAttrsToList specToNotLazyConfig cfg.plugins); + notLazyConfig = + concatStringsSep "\n" + (mapAttrsToList specToNotLazyConfig cfg.plugins); + + beforeAllJoined = + concatStringsSep "\n" + (filter (x: x != null) (mapAttrsToList (_: spec: spec.beforeAll) cfg.plugins)); in { config.vim = mkMerge [ (mkIf cfg.enable { @@ -84,17 +90,18 @@ in { optPlugins = pluginPackages; - luaConfigRC.lzn-load = entryBefore ["pluginConfigs"] '' + lazy.builtLazyConfig = '' require('lz.n').load(${toLuaObject lznSpecs}) + ${optionalString cfg.enableLznAutoRequire "require('lzn-auto-require').enable()"} ''; }) (mkIf (!cfg.enable) { startPlugins = pluginPackages; - luaConfigPre = - concatStringsSep "\n" - (filter (x: x != null) (mapAttrsToList (_: spec: spec.beforeAll) cfg.plugins)); - luaConfigRC.unlazy = entryAfter ["pluginConfigs"] notLazyConfig; + lazy.builtLazyConfig = '' + ${beforeAllJoined} + ${notLazyConfig} + ''; keymaps = concatLists (mapAttrsToList specToKeymaps cfg.plugins); }) ]; diff --git a/modules/wrapper/lazy/lazy.nix b/modules/wrapper/lazy/lazy.nix index fc130afc..5b2c53d1 100644 --- a/modules/wrapper/lazy/lazy.nix +++ b/modules/wrapper/lazy/lazy.nix @@ -181,7 +181,7 @@ }; in { options.vim.lazy = { - enable = mkEnableOption "plugin lazy-loading" // {default = true;}; + enable = mkEnableOption "plugin lazy-loading via lz.n and lzn-auto-require" // {default = true;}; loader = mkOption { description = "Lazy loader to use"; type = enum ["lz.n"]; @@ -215,5 +215,23 @@ in { } ''; }; + + enableLznAutoRequire = mkOption { + description = '' + Enable lzn-auto-require. Since builtin plugins rely on this, only turn + off for debugging. + ''; + type = bool; + default = true; + }; + + builtLazyConfig = mkOption { + internal = true; + type = lines; + description = '' + The built config for lz.n, or if `vim.lazy.enable` is false, the + individual plugin configs. + ''; + }; }; } diff --git a/modules/wrapper/rc/config.nix b/modules/wrapper/rc/config.nix index 25fc9bcf..627fd05b 100644 --- a/modules/wrapper/rc/config.nix +++ b/modules/wrapper/rc/config.nix @@ -52,11 +52,10 @@ in { optionsScript = entryAfter ["basic"] (concatLines optionsScript); # Basic - pluginConfigs = entryAfter ["optionsScript"] pluginConfigs; + lazyConfigs = entryAfter ["optionsScript"] cfg.lazy.builtLazyConfig; + pluginConfigs = entryAfter ["lazyConfigs"] pluginConfigs; extraPluginConfigs = entryAfter ["pluginConfigs"] extraPluginConfigs; mappings = entryAfter ["extraPluginConfigs"] keymaps; - # FIXME: put this somewhere less stupid - footer = entryAfter ["mappings"] (optionalString config.vim.lazy.enable "require('lzn-auto-require').enable()"); }; builtLuaConfigRC = let