Skip to content
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

feat: add more plugin spec fields #13

Merged
Merged
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
57 changes: 38 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,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" {
Expand All @@ -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
Expand Down