From 97fb6d6a29337883843d5edd6b87c4ed260642ec Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Sun, 7 Jan 2024 11:01:13 +0100 Subject: [PATCH] helpers/mkPlugin: add extraConfig option --- lib/helpers.nix | 41 ++++++++++++++++++++++++++++++++++----- plugins/git/fugitive.nix | 2 +- plugins/languages/zig.nix | 3 ++- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/lib/helpers.nix b/lib/helpers.nix index 3962c1e8..b8a9db95 100644 --- a/lib/helpers.nix +++ b/lib/helpers.nix @@ -322,16 +322,27 @@ with lib; rec { ... }: let cfg = config.plugins.${name}; + + description = + if description is null + then name + else description; + # TODO support nested options! - pluginOptions = mapAttrs (k: v: v.option) options; + pluginOptions = + mapAttrs + ( + optName: opt: + opt.option + ) + options; globals = mapAttrs' - (name: opt: { + (optName: opt: { name = globalPrefix + opt.global; value = - if cfg.${name} != null - then opt.value cfg.${name} - else null; + ifNonNull' cfg.${optName} + (opt.value cfg.${optName}); }) options; # does this evaluate package? @@ -341,11 +352,31 @@ with lib; rec { else { package = mkPackageOption name package; }; + + extraConfigOption = + if (isString globalPrefix) && (globalPrefix != "") + then { + extraConfig = mkOption { + type = with types; attrsOf anything; + description = '' + The configuration options for ${name} without the '${globalPrefix}' prefix. + Example: To set '${globalPrefix}_foo_bar' to 1, write + ```nix + extraConfig = { + foo_bar = true; + }; + ``` + ''; + default = {}; + }; + } + else {}; in { options.plugins.${name} = { enable = mkEnableOption description; } + // extraConfigOption // packageOption // pluginOptions; diff --git a/plugins/git/fugitive.nix b/plugins/git/fugitive.nix index d1631016..129f17b3 100644 --- a/plugins/git/fugitive.nix +++ b/plugins/git/fugitive.nix @@ -13,6 +13,6 @@ in package = pkgs.vimPlugins.vim-fugitive; extraPackages = [pkgs.git]; - # In typical tpope fashin, this plugin has no config options + # In typical tpope fashion, this plugin has no config options options = {}; } diff --git a/plugins/languages/zig.nix b/plugins/languages/zig.nix index 7c06565e..d884f825 100644 --- a/plugins/languages/zig.nix +++ b/plugins/languages/zig.nix @@ -11,12 +11,13 @@ in name = "zig"; description = "Enable zig"; package = pkgs.vimPlugins.zig-vim; + globalPrefix = "zig_"; # Possibly add option to disable Treesitter highlighting if this is installed options = { formatOnSave = mkDefaultOpt { type = types.bool; - global = "zig_fmt_autosave"; + global = "fmt_autosave"; description = "Run zig fmt on save"; }; };