diff --git a/modules/plugins/default.nix b/modules/plugins/default.nix index de0191e..227924c 100644 --- a/modules/plugins/default.nix +++ b/modules/plugins/default.nix @@ -7,6 +7,10 @@ with lib; let inherit (flake-parts-lib) mkPerSystemOption; pluginSpec = with types; { options = { + enabled = mkOption { + type = nullOr (oneOf [bool str]); + default = null; + }; src = mkOption { type = nullOr (oneOf [attrs path]); default = null; @@ -15,6 +19,10 @@ with lib; let type = nullOr package; default = null; }; + dev = mkOption { + type = nullOr bool; + default = null; + }; name = mkOption { type = nullOr str; default = null; @@ -43,12 +51,20 @@ with lib; let type = nullOr (oneOf [str (listOf str)]); default = null; }; + cmd = mkOption { + type = nullOr (oneOf [str (listOf str)]); + default = null; + }; ft = mkOption { type = nullOr (oneOf [str (listOf str)]); default = null; }; keys = mkOption { - type = nullOr (oneOf [str (listOf str)]); + type = nullOr str; + default = null; + }; + main = mkOption { + type = nullOr str; default = null; }; priority = mkOption { @@ -106,17 +122,10 @@ in { }; build = { - lazy = { - spec = mkOption { - type = str; - internal = true; - }; - opts = mkOption { - type = str; - internal = true; - }; + lazy = mkOption { + type = str; + internal = true; }; - plugins = mkOption { type = package; internal = true; @@ -160,6 +169,13 @@ in { inherit name; dir = "${package}"; } + // optionalAttrs (isBool attrs.enabled) {inherit (attrs) enabled;} + // optionalAttrs (isString attrs.enabled) { + enabled = lib.generators.mkLuaInline attrs.enabled; + } + // optionalAttrs (isBool attrs.dev && attrs.dev && isString cfg.settings.dev.path) { + dir = "${cfg.settings.dev.path}/${name}"; + } // optionalAttrs (attrs.lazy != null) {inherit (attrs) lazy;} // optionalAttrs (attrs.dependencies != {}) { dependencies = let @@ -187,15 +203,18 @@ in { opts = attrs.config; } // optionalAttrs (attrs.event != null) {inherit (attrs) event;} + // optionalAttrs (attrs.cmd != null) {inherit (attrs) cmd;} // optionalAttrs (attrs.ft != null) {inherit (attrs) ft;} - // optionalAttrs (attrs.keys != null) {inherit (attrs) keys;} + // optionalAttrs (attrs.keys != null) { + keys = lib.generators.mkLuaInline attrs.keys; + } + // optionalAttrs (attrs.main != null) {inherit (attrs) main;} // optionalAttrs (attrs.priority != null) {inherit (attrs) priority;}; - - spec = lib.generators.toLua {} (mapAttrsToList toPlugin' cfg.plugins); - opts = lib.generators.toLua {} ({performance.rtp.reset = false;} // cfg.settings); - in { - inherit spec opts; - }; + in + lib.generators.toLua {} (lib.recursiveUpdate cfg.settings { + spec = mapAttrsToList toPlugin' cfg.plugins; + performance.rtp.reset = false; + }); plugins = pkgs.runCommand "plugins.lua" { @@ -206,7 +225,7 @@ in { text = '' -- Generated by Nix (via github:willruggiano/neovim.nix) vim.opt.rtp:prepend "${cfg.package}" - require("lazy").setup(${build.lazy.spec}, ${build.lazy.opts}) + require("lazy").setup(${build.lazy}) ''; } '' target=$out