From ff38aeb820a9db824c8a383f6c6490a9a1cdb08d Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Sat, 24 Aug 2024 14:28:14 +0200 Subject: [PATCH] lazy: use listOf plugins instead of attr --- modules/plugins/filetree/nvimtree/config.nix | 8 ++++---- modules/wrapper/lazy/config.nix | 15 +++++++++++---- modules/wrapper/lazy/lazy.nix | 16 ++++++++-------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/modules/plugins/filetree/nvimtree/config.nix b/modules/plugins/filetree/nvimtree/config.nix index 5de1817..a2f9811 100644 --- a/modules/plugins/filetree/nvimtree/config.nix +++ b/modules/plugins/filetree/nvimtree/config.nix @@ -21,8 +21,8 @@ in { }; vim.lazy = { - plugins = { - nvim-tree-lua = { + plugins = [ + { package = "nvim-tree-lua"; setupModule = "nvim-tree"; inherit (cfg) setupOpts; @@ -34,8 +34,8 @@ in { (mkLznBinding ["n"] cfg.mappings.findFile ":NvimTreeFindFile" mappings.findFile.description) (mkLznBinding ["n"] cfg.mappings.focus ":NvimTreeFocus" mappings.focus.description) ]; - }; - }; + } + ]; }; vim.pluginRC.nvimtreelua = entryAnywhere '' diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix index 1ad90ee..3965083 100644 --- a/modules/wrapper/lazy/config.nix +++ b/modules/wrapper/lazy/config.nix @@ -3,7 +3,7 @@ config, ... }: let - inherit (builtins) toJSON typeOf head length; + inherit (builtins) toJSON typeOf head length tryEval; inherit (lib.modules) mkIf; inherit (lib.attrsets) mapAttrsToList; inherit (lib.generators) mkLuaInline; @@ -31,7 +31,14 @@ inherit desc noremap expr nowait ft mode; }; - toLuaLznSpec = name: spec: + toLuaLznSpec = spec: let + name = + if typeOf spec.package == "string" + then spec.package + else if (spec.package ? pname && (tryEval spec.package.pname).success) + then spec.package.pname + else spec.package.name; + in (removeAttrs spec ["package" "setupModule" "setupOpts" "keys"]) // { "@1" = name; @@ -64,12 +71,12 @@ then map toLuzLznKeySpec spec.keys else spec.keys; }; - lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins; + lznSpecs = map toLuaLznSpec cfg.plugins; in { config.vim = mkIf cfg.enable { startPlugins = ["lz-n" "lzn-auto-require"]; - optPlugins = mapAttrsToList (_: plugin: plugin.package) cfg.plugins; + optPlugins = map (plugin: plugin.package) cfg.plugins; luaConfigRC.lzn-load = entryBefore ["pluginConfigs"] '' require('lz.n').load(${toLuaObject lznSpecs}) diff --git a/modules/wrapper/lazy/lazy.nix b/modules/wrapper/lazy/lazy.nix index 151c087..77502d4 100644 --- a/modules/wrapper/lazy/lazy.nix +++ b/modules/wrapper/lazy/lazy.nix @@ -1,7 +1,7 @@ {lib, ...}: let inherit (lib.options) mkOption mkEnableOption; - inherit (lib.types) enum; - inherit (lib.nvim.types) lznPluginTableType; + inherit (lib.types) enum listOf; + inherit (lib.nvim.types) lznPluginType; in { options.vim.lazy = { enable = mkEnableOption "plugin lazy-loading" // {default = true;}; @@ -12,17 +12,17 @@ in { }; plugins = mkOption { - default = {}; - type = lznPluginTableType; + default = []; + type = listOf lznPluginType; description = "list of plugins to lazy load"; example = '' - { - toggleterm-nvim = { + [ + { package = "toggleterm-nvim"; after = lib.generators.mkLuaInline "function() require('toggleterm').setup{} end"; cmd = ["ToggleTerm"]; - }; - } + } + ] ''; }; };