Skip to content

Commit

Permalink
feat: add more plugin spec fields
Browse files Browse the repository at this point in the history
Adds `enabled`, `dev`, `cmd`, `main`.
Implements `dev` by setting the prepending `dir` with `cfg.settings.dev.path`.
  • Loading branch information
nekowinston committed Aug 30, 2024
1 parent b522ae1 commit 5ba4e69
Showing 1 changed file with 39 additions and 19 deletions.
58 changes: 39 additions & 19 deletions modules/plugins/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -187,15 +203,19 @@ 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 {} (cfg.settings
// {
spec = mapAttrsToList toPlugin' cfg.plugins;
performance.rtp.reset = false;
});

plugins =
pkgs.runCommand "plugins.lua" {
Expand All @@ -206,7 +226,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
Expand Down

0 comments on commit 5ba4e69

Please sign in to comment.