From 3c9a4b67ae624be73b55765162d45e8e0a75a18e Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Fri, 8 Mar 2024 11:44:10 +0100 Subject: [PATCH] helpers/neovim-plugin/mkNeovimPlugin: add a colorscheme argument and factor out logic --- lib/neovim-plugin.nix | 20 +++++++++++++++++--- plugins/colorschemes/ayu.nix | 5 ++++- plugins/colorschemes/gruvbox.nix | 6 +----- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/neovim-plugin.nix b/lib/neovim-plugin.nix index f093b13e..58d04cb2 100644 --- a/lib/neovim-plugin.nix +++ b/lib/neovim-plugin.nix @@ -32,7 +32,7 @@ with lib; rec { mkNeovimPlugin = config: { name, - namespace ? "plugins", + colorscheme ? false, maintainers, url ? defaultPackage.meta.homepage, imports ? [], @@ -51,7 +51,12 @@ with lib; rec { extraPlugins ? [], extraPackages ? [], callSetup ? true, - }: { + }: let + namespace = + if colorscheme + then "colorschemes" + else "plugins"; + in { meta = { inherit maintainers; nixvimInfo = { @@ -108,6 +113,10 @@ with lib; rec { config = let cfg = config.${namespace}.${name}; + extraConfigNamespace = + if colorscheme + then "extraConfigLuaPre" + else "extraConfigLua"; in mkIf cfg.enable ( mkMerge [ @@ -115,10 +124,15 @@ with lib; rec { extraPlugins = [cfg.package] ++ extraPlugins; inherit extraPackages; - extraConfigLua = optionalString callSetup '' + ${extraConfigNamespace} = optionalString callSetup '' require('${luaName}').setup(${toLuaObject cfg.settings}) ''; } + (optionalAttrs colorscheme { + # We use `mkDefault` here to let individual plugins override this option. + # For instance, setting it to `null` a specific way of setting the coloscheme. + colorscheme = lib.mkDefault name; + }) (extraConfig cfg) ] ); diff --git a/plugins/colorschemes/ayu.nix b/plugins/colorschemes/ayu.nix index fde0dded..1806af1c 100644 --- a/plugins/colorschemes/ayu.nix +++ b/plugins/colorschemes/ayu.nix @@ -8,7 +8,7 @@ with lib; helpers.neovim-plugin.mkNeovimPlugin config { name = "ayu"; - namespace = "colorschemes"; + colorscheme = true; originalName = "neovim-ayu"; defaultPackage = pkgs.vimPlugins.neovim-ayu; callSetup = false; @@ -42,6 +42,9 @@ with lib; }; extraConfig = cfg: { + # The colorscheme option is set by the `setup` function. + colorscheme = null; + extraConfigLuaPre = '' local ayu = require("ayu") ayu.setup(${helpers.toLuaObject cfg.settings}) diff --git a/plugins/colorschemes/gruvbox.nix b/plugins/colorschemes/gruvbox.nix index cb7d237f..1cfdc5f7 100644 --- a/plugins/colorschemes/gruvbox.nix +++ b/plugins/colorschemes/gruvbox.nix @@ -7,7 +7,7 @@ }: helpers.neovim-plugin.mkNeovimPlugin config { name = "gruvbox"; - namespace = "colorschemes"; + colorscheme = true; originalName = "gruvbox.nvim"; defaultPackage = pkgs.vimPlugins.gruvbox-nvim; @@ -57,8 +57,4 @@ helpers.neovim-plugin.mkNeovimPlugin config { bright_purple = "#fb4934"; }; }; - - extraConfig = cfg: { - colorscheme = "gruvbox"; - }; }