Skip to content

lib/*-plugin: drop config arg #2140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions lib/neovim-plugin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ with lib;
};

mkNeovimPlugin =
config:
{
name,
maintainers,
Expand Down Expand Up @@ -71,7 +70,32 @@ with lib;
++ (optional deprecateExtraOptions (
mkRenamedOptionModule (basePluginPath ++ [ "extraOptions" ]) settingsPath
))
++ (nixvim.mkSettingsRenamedOptionModules basePluginPath settingsPath optionsRenamedToSettings);
++ (nixvim.mkSettingsRenamedOptionModules basePluginPath settingsPath optionsRenamedToSettings)
++ [
(
{ config, ... }:
{
config =
let
cfg = config.${namespace}.${name};
extraConfigNamespace = if isColorscheme then "extraConfigLuaPre" else "extraConfigLua";
in
mkIf cfg.enable (mkMerge [
{
extraPlugins = (optional installPackage cfg.package) ++ extraPlugins;
inherit extraPackages;
}
(optionalAttrs callSetup {
${extraConfigNamespace} = ''
require('${luaName}')${setup}(${optionalString (cfg ? settings) (helpers.toLuaObject cfg.settings)})
'';
})
(optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; })
(extraConfig cfg)
]);
}
)
];

options.${namespace}.${name} =
{
Expand All @@ -87,24 +111,5 @@ with lib;
};
}
// extraOptions;

config =
let
cfg = config.${namespace}.${name};
extraConfigNamespace = if isColorscheme then "extraConfigLuaPre" else "extraConfigLua";
in
mkIf cfg.enable (mkMerge [
{
extraPlugins = (optional installPackage cfg.package) ++ extraPlugins;
inherit extraPackages;
}
(optionalAttrs callSetup {
${extraConfigNamespace} = ''
require('${luaName}')${setup}(${optionalString (cfg ? settings) (helpers.toLuaObject cfg.settings)})
'';
})
(optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; })
(extraConfig cfg)
]);
};
}
39 changes: 23 additions & 16 deletions lib/vim-plugin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
with lib;
{
mkVimPlugin =
config:
{
name,
url ? if defaultPackage != null then defaultPackage.meta.homepage else null,
Expand Down Expand Up @@ -30,10 +29,6 @@ with lib;
let
namespace = if isColorscheme then "colorschemes" else "plugins";

cfg = config.${namespace}.${name};

globals = cfg.settings or { };

# does this evaluate package?
packageOption =
if defaultPackage == null then
Expand All @@ -58,6 +53,27 @@ with lib;
'';
};
};

modules = [
(
{ config, ... }:
let
cfg = config.${namespace}.${name};
in
{
config = mkIf cfg.enable (mkMerge [
{
inherit extraPackages;
globals = mapAttrs' (n: nameValuePair (globalPrefix + n)) (cfg.settings or { });
# does this evaluate package? it would not be desired to evaluate package if we use another package.
extraPlugins = extraPlugins ++ optional (defaultPackage != null) cfg.package;
}
(optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; })
(extraConfig cfg)
]);
}
)
];
in
{
meta = {
Expand Down Expand Up @@ -86,17 +102,8 @@ with lib;
++ (optional (deprecateExtraConfig && createSettingsOption) (
mkRenamedOptionModule (basePluginPath ++ [ "extraConfig" ]) settingsPath
))
++ (nixvim.mkSettingsRenamedOptionModules basePluginPath settingsPath optionsRenamedToSettings);
++ (nixvim.mkSettingsRenamedOptionModules basePluginPath settingsPath optionsRenamedToSettings)
++ modules;

config = mkIf cfg.enable (mkMerge [
{
inherit extraPackages;
globals = mapAttrs' (n: nameValuePair (globalPrefix + n)) globals;
# does this evaluate package? it would not be desired to evaluate package if we use another package.
extraPlugins = extraPlugins ++ optional (defaultPackage != null) cfg.package;
}
(optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; })
(extraConfig cfg)
]);
};
}
3 changes: 1 addition & 2 deletions plugins/TEMPLATE.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
lib,
config,
pkgs,
...
}:
let
inherit (lib.nixvim) defaultNullOpts;
in
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "my-plugin";
originalName = "my-plugin.nvim"; # TODO replace (or remove entirely if it is the same as `name`)
defaultPackage = pkgs.vimPlugins.my-plugin-nvim; # TODO replace
Expand Down
3 changes: 1 addition & 2 deletions plugins/ai/chatgpt.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
helpers.neovim-plugin.mkNeovimPlugin config {
helpers.neovim-plugin.mkNeovimPlugin {
name = "chatgpt";
originalName = "ChatGPT.nvim";
defaultPackage = pkgs.vimPlugins.ChatGPT-nvim;
Expand Down
3 changes: 1 addition & 2 deletions plugins/ai/copilot-chat.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
helpers.neovim-plugin.mkNeovimPlugin config {
helpers.neovim-plugin.mkNeovimPlugin {
name = "copilot-chat";
originalName = "CopilotChat.nvim";
luaName = "CopilotChat";
Expand Down
3 changes: 1 addition & 2 deletions plugins/bufferlines/barbar.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
lib,
config,
pkgs,
...
}:
Expand Down Expand Up @@ -51,7 +50,7 @@ let
orderByWindowNumber = "OrderByWindowNumber";
};
in
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "barbar";
originalName = "barbar.nvim";
defaultPackage = pkgs.vimPlugins.barbar-nvim;
Expand Down
3 changes: 1 addition & 2 deletions plugins/bufferlines/bufferline.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
lib,
config,
pkgs,
...
}:
let
inherit (lib.nixvim) defaultNullOpts nixvimTypes mkSettingsRenamedOptionModules;
types = nixvimTypes;
in
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "bufferline";
originalName = "bufferline.nvim";
defaultPackage = pkgs.vimPlugins.bufferline-nvim;
Expand Down
3 changes: 1 addition & 2 deletions plugins/colorschemes/ayu.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
lib,
config,
pkgs,
...
}:
let
inherit (lib.nixvim) defaultNullOpts toLuaObject;
in
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "ayu";
isColorscheme = true;
originalName = "neovim-ayu";
Expand Down
3 changes: 1 addition & 2 deletions plugins/colorschemes/base16/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
lib,
config,
pkgs,
...
}:
Expand All @@ -11,7 +10,7 @@ let
luaName = "base16-colorscheme";
originalName = "base16.nvim";
in
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
lib.nixvim.neovim-plugin.mkNeovimPlugin {
inherit name luaName originalName;
setup = ".with_config";
defaultPackage = pkgs.vimPlugins.base16-nvim;
Expand Down
3 changes: 1 addition & 2 deletions plugins/colorschemes/catppuccin.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
lib,
config,
pkgs,
...
}:
let
inherit (lib.nixvim) defaultNullOpts mkNullOrOption mkNullOrStrLuaFnOr;
inherit (lib) types;
in
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "catppuccin";
isColorscheme = true;
defaultPackage = pkgs.vimPlugins.catppuccin-nvim;
Expand Down
3 changes: 1 addition & 2 deletions plugins/colorschemes/cyberdream.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
config,
lib,
pkgs,
...
}:
let
inherit (lib.nixvim) defaultNullOpts;
in
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "cyberdream";
isColorscheme = true;
originalName = "cyberdream.nvim";
Expand Down
3 changes: 1 addition & 2 deletions plugins/colorschemes/everforest.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
lib,
config,
pkgs,
...
}:
Expand All @@ -15,7 +14,7 @@ let
] pluginDefault desc;

in
lib.nixvim.vim-plugin.mkVimPlugin config {
lib.nixvim.vim-plugin.mkVimPlugin {
name = "everforest";
isColorscheme = true;
defaultPackage = pkgs.vimPlugins.everforest;
Expand Down
3 changes: 1 addition & 2 deletions plugins/colorschemes/gruvbox.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
lib,
config,
pkgs,
...
}:
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "gruvbox";
isColorscheme = true;
originalName = "gruvbox.nvim";
Expand Down
3 changes: 1 addition & 2 deletions plugins/colorschemes/kanagawa.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
lib,
pkgs,
config,
...
}:
let
inherit (lib.nixvim) defaultNullOpts;
inherit (lib) types;
in
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "kanagawa";
isColorscheme = true;
originalName = "kanagawa.nvim";
Expand Down
3 changes: 1 addition & 2 deletions plugins/colorschemes/melange.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
lib,
config,
pkgs,
...
}:
lib.nixvim.vim-plugin.mkVimPlugin config {
lib.nixvim.vim-plugin.mkVimPlugin {
name = "melange";
isColorscheme = true;
originalName = "melange-nvim";
Expand Down
3 changes: 1 addition & 2 deletions plugins/colorschemes/modus.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
lib,
config,
pkgs,
...
}:
let
inherit (lib.nixvim) defaultNullOpts;
in
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "modus";
luaName = "modus-themes";
originalName = "modus-themes.nvim";
Expand Down
3 changes: 1 addition & 2 deletions plugins/colorschemes/nightfox.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
lib,
pkgs,
config,
...
}:
let
inherit (lib.nixvim) defaultNullOpts mkNullOrOption;
inherit (lib) types;
in
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "nightfox";
isColorscheme = true;
originalName = "nightfox.nvim";
Expand Down
3 changes: 1 addition & 2 deletions plugins/colorschemes/nord.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
lib,
config,
pkgs,
...
}:
let
inherit (lib.nixvim) defaultNullOpts;
in
lib.nixvim.vim-plugin.mkVimPlugin config {
lib.nixvim.vim-plugin.mkVimPlugin {
name = "nord";
isColorscheme = true;
originalName = "nord.nvim";
Expand Down
3 changes: 1 addition & 2 deletions plugins/colorschemes/one.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
lib,
config,
pkgs,
...
}:
lib.nixvim.vim-plugin.mkVimPlugin config {
lib.nixvim.vim-plugin.mkVimPlugin {
name = "one";
isColorscheme = true;
originalName = "vim-one";
Expand Down
3 changes: 1 addition & 2 deletions plugins/colorschemes/onedark.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
lib,
config,
pkgs,
...
}:
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "onedark";
isColorscheme = true;
originalName = "onedark.nvim";
Expand Down
Loading