Skip to content

Commit

Permalink
lib/vim-plugin: drop config arg
Browse files Browse the repository at this point in the history
Instead, access it via an imported module
  • Loading branch information
MattSturgeon committed Sep 2, 2024
1 parent 9b0e2ba commit 2a054b0
Show file tree
Hide file tree
Showing 45 changed files with 67 additions and 102 deletions.
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/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/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/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/oxocarbon.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 = "oxocarbon";
isColorscheme = true;
originalName = "oxocarbon.nvim";
Expand Down
3 changes: 1 addition & 2 deletions plugins/completion/cmp/sources/_mk-cmp-plugin.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
lib,
helpers,
config,
pkgs,
...
}:
Expand All @@ -13,7 +12,7 @@
imports ? [ ],
...
}@args:
helpers.vim-plugin.mkVimPlugin config (
helpers.vim-plugin.mkVimPlugin (
builtins.removeAttrs args [
"pluginName"
"sourceName"
Expand Down
3 changes: 1 addition & 2 deletions plugins/completion/codeium-vim.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
lib,
helpers,
config,
pkgs,
...
}:
Expand Down Expand Up @@ -35,7 +34,7 @@ let
};
};
in
helpers.vim-plugin.mkVimPlugin config {
helpers.vim-plugin.mkVimPlugin {
name = "codeium-vim";
originalName = "codeium.vim";
defaultPackage = pkgs.vimPlugins.codeium-vim;
Expand Down
3 changes: 1 addition & 2 deletions plugins/completion/copilot-vim.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
lib,
config,
helpers,
pkgs,
...
}:
with lib;
with helpers.vim-plugin;
helpers.vim-plugin.mkVimPlugin config {
helpers.vim-plugin.mkVimPlugin {
name = "copilot-vim";
originalName = "copilot.vim";
defaultPackage = pkgs.vimPlugins.copilot-vim;
Expand Down
3 changes: 1 addition & 2 deletions plugins/git/committia.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
config,
helpers,
pkgs,
...
}:
helpers.vim-plugin.mkVimPlugin config {
helpers.vim-plugin.mkVimPlugin {
name = "committia";
originalName = "committia.vim";
defaultPackage = pkgs.vimPlugins.committia-vim;
Expand Down
3 changes: 1 addition & 2 deletions plugins/git/fugitive.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
config,
lib,
helpers,
pkgs,
...
}:
helpers.vim-plugin.mkVimPlugin config {
helpers.vim-plugin.mkVimPlugin {
name = "fugitive";
originalName = "vim-fugitive";
defaultPackage = pkgs.vimPlugins.vim-fugitive;
Expand Down
3 changes: 1 addition & 2 deletions plugins/git/gitignore.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
# We use `mkVimPlugin` to avoid having a `settings` option.
# Indeed, this plugin is not configurable in the common sense (no `setup` function).
helpers.vim-plugin.mkVimPlugin config {
helpers.vim-plugin.mkVimPlugin {
name = "gitignore";
originalName = "gitignore.nvim";
defaultPackage = pkgs.vimPlugins.gitignore-nvim;
Expand Down
3 changes: 1 addition & 2 deletions plugins/git/lazygit.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
config,
lib,
helpers,
pkgs,
...
}:
with lib;
helpers.vim-plugin.mkVimPlugin config {
helpers.vim-plugin.mkVimPlugin {
name = "lazygit";
originalName = "lazygit.nvim";
defaultPackage = pkgs.vimPlugins.lazygit-nvim;
Expand Down
3 changes: 1 addition & 2 deletions plugins/languages/godot.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
config,
lib,
helpers,
pkgs,
...
}:
with lib;
helpers.vim-plugin.mkVimPlugin config {
helpers.vim-plugin.mkVimPlugin {
name = "godot";
originalName = "vim-godot";
defaultPackage = pkgs.vimPlugins.vim-godot;
Expand Down
2 changes: 1 addition & 1 deletion plugins/languages/haskell-scope-highlighting.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
...
}:
with lib;
helpers.vim-plugin.mkVimPlugin config {
helpers.vim-plugin.mkVimPlugin {
name = "haskell-scope-highlighting";
originalName = "haskell-scope-highlighting.nvim";
defaultPackage = pkgs.vimPlugins.haskell-scope-highlighting-nvim;
Expand Down
3 changes: 1 addition & 2 deletions plugins/languages/julia/julia-cell.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
lib,
helpers,
config,
pkgs,
...
}:
Expand Down Expand Up @@ -37,7 +36,7 @@ let
};
in
with lib;
helpers.vim-plugin.mkVimPlugin config {
helpers.vim-plugin.mkVimPlugin {
name = "julia-cell";
originalName = "vim-julia-cell";
defaultPackage = pkgs.vimPlugins.vim-julia-cell;
Expand Down
3 changes: 1 addition & 2 deletions plugins/languages/ledger.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
lib,
config,
helpers,
pkgs,
...
}:
with lib;
with helpers.vim-plugin;
mkVimPlugin config {
mkVimPlugin {
name = "ledger";
originalName = "vim-ledger";
defaultPackage = pkgs.vimPlugins.vim-ledger;
Expand Down
3 changes: 1 addition & 2 deletions plugins/languages/markdown/markdown-preview.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
lib,
config,
helpers,
pkgs,
...
}:
with lib;
with helpers.vim-plugin;
mkVimPlugin config {
mkVimPlugin {
name = "markdown-preview";
originalName = "markdown-preview.nvim";
defaultPackage = pkgs.vimPlugins.markdown-preview-nvim;
Expand Down
3 changes: 1 addition & 2 deletions plugins/languages/nix.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
config,
lib,
helpers,
pkgs,
...
}:
helpers.vim-plugin.mkVimPlugin config {
helpers.vim-plugin.mkVimPlugin {
name = "nix";
originalName = "vim-nix";
defaultPackage = pkgs.vimPlugins.vim-nix;
Expand Down
3 changes: 1 addition & 2 deletions plugins/languages/parinfer-rust.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
lib,
helpers,
config,
pkgs,
...
}:
helpers.vim-plugin.mkVimPlugin config {
helpers.vim-plugin.mkVimPlugin {
name = "parinfer-rust";
defaultPackage = pkgs.vimPlugins.parinfer-rust;
globalPrefix = "parinfer_";
Expand Down
3 changes: 1 addition & 2 deletions plugins/languages/tagbar.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
helpers,
config,
pkgs,
lib,
...
}:
helpers.vim-plugin.mkVimPlugin config {
helpers.vim-plugin.mkVimPlugin {
name = "tagbar";
defaultPackage = pkgs.vimPlugins.tagbar;
globalPrefix = "tagbar_";
Expand Down
3 changes: 1 addition & 2 deletions plugins/languages/texpresso.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
# This plugin has no configuration, so we use `mkVimPlugin` without the `globalPrefix` argument to
# avoid the creation of the `settings` option.
helpers.vim-plugin.mkVimPlugin config {
helpers.vim-plugin.mkVimPlugin {
name = "texpresso";
originalName = "texpresso.vim";
defaultPackage = pkgs.vimPlugins.texpresso-vim;
Expand Down
3 changes: 1 addition & 2 deletions plugins/languages/typst/typst-vim.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
helpers.vim-plugin.mkVimPlugin config {
helpers.vim-plugin.mkVimPlugin {
name = "typst-vim";
originalName = "typst.vim";
defaultPackage = pkgs.vimPlugins.typst-vim;
Expand Down
3 changes: 1 addition & 2 deletions plugins/languages/vim-slime.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
lib,
config,
helpers,
pkgs,
...
}:
with lib;
with helpers.vim-plugin;
mkVimPlugin config {
mkVimPlugin {
name = "vim-slime";
defaultPackage = pkgs.vimPlugins.vim-slime;
globalPrefix = "slime_";
Expand Down
Loading

0 comments on commit 2a054b0

Please sign in to comment.