nix-community.nixvim/plugins/by-name/alpha/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

210 lines
5.7 KiB
Nix
Raw Normal View History

{
lib,
config,
2024-08-29 09:54:31 -05:00
options,
pkgs,
...
}:
let
inherit (lib) types mkOption;
cfg = config.plugins.alpha;
2024-01-12 23:13:04 +01:00
sectionType = types.submodule {
freeformType = with types; attrsOf anything;
options = {
type = mkOption {
type = types.enum [
"button"
"group"
"padding"
"text"
"terminal"
];
description = "Type of section";
};
val = lib.nixvim.mkNullOrOption (
with types;
nullOr (oneOf [
2024-09-18 21:31:19 -05:00
2024-01-12 23:13:04 +01:00
# "button", "text"
2024-09-18 21:31:19 -05:00
(maybeRaw str)
2024-01-12 23:13:04 +01:00
# "padding"
int
(listOf (
either
# "text" (list of strings)
str
# "group"
(attrsOf anything)
))
])
) "Value for section";
2024-01-12 23:13:04 +01:00
opts = mkOption {
type = with types; attrsOf anything;
default = { };
description = "Additional options for the section";
};
};
2024-01-12 23:13:04 +01:00
};
in
{
options = {
plugins.alpha = {
enable = lib.mkEnableOption "alpha-nvim";
package = lib.mkPackageOption pkgs "alpha-nvim" {
default = [
"vimPlugins"
"alpha-nvim"
];
};
2024-08-29 09:54:31 -05:00
# TODO: deprecated 2024-08-29 remove after 24.11
iconsEnabled = mkOption {
type = types.bool;
description = "Toggle icon support. Installs nvim-web-devicons.";
2024-08-29 09:54:31 -05:00
visible = false;
};
2024-01-12 23:13:04 +01:00
theme = mkOption {
type = with types; nullOr (maybeRaw str);
apply = v: if lib.isString v then lib.nixvim.mkRaw "require'alpha.themes.${v}'.config" else v;
2024-01-12 23:13:04 +01:00
default = null;
example = "dashboard";
description = "You can directly use a pre-defined theme.";
};
layout = mkOption {
2024-09-18 21:31:19 -05:00
type = with types; either (maybeRaw str) (listOf sectionType);
2024-01-12 23:13:04 +01:00
default = [ ];
description = "List of sections to layout for the dashboard";
example = [
{
type = "padding";
val = 2;
}
{
type = "text";
val = [
2024-01-12 23:13:04 +01:00
" "
" "
" "
" "
" "
" "
];
opts = {
position = "center";
hl = "Type";
};
}
{
type = "padding";
val = 2;
}
{
type = "group";
val = [
{
type = "button";
2024-01-16 00:02:22 +01:00
val = " New file";
on_press.__raw = "function() vim.cmd[[ene]] end";
opts.shortcut = "n";
}
{
type = "button";
2024-01-16 00:02:22 +01:00
val = " Quit Neovim";
on_press.__raw = "function() vim.cmd[[qa]] end";
opts.shortcut = "q";
}
];
}
{
type = "padding";
val = 2;
}
{
type = "text";
val = "Inspiring quote here.";
opts = {
position = "center";
hl = "Keyword";
};
}
];
};
2024-01-12 23:13:04 +01:00
opts = lib.nixvim.mkNullOrOption (with types; attrsOf anything) ''
2024-01-12 23:13:04 +01:00
Optional global options.
'';
};
};
config =
let
2024-01-12 23:13:04 +01:00
layoutDefined = cfg.layout != [ ];
themeDefined = cfg.theme != null;
2024-08-29 09:54:31 -05:00
opt = options.plugins.alpha;
in
lib.mkIf cfg.enable {
2024-08-29 09:54:31 -05:00
# TODO: added 2024-09-20 remove after 24.11
warnings = lib.optionals opt.iconsEnabled.isDefined [
''
The option definition `plugins.alpha.iconsEnabled' in ${lib.showFiles opt.iconsEnabled.files} has been deprecated; please remove it.
''
];
plugins.web-devicons =
lib.mkIf
(
opt.iconsEnabled.isDefined
&& cfg.iconsEnabled
&& !(
config.plugins.mini.enable
&& config.plugins.mini.modules ? icons
&& config.plugins.mini.mockDevIcons
)
)
{
enable = lib.mkOverride 1490 true;
};
extraPlugins = [ cfg.package ];
2024-01-12 23:13:04 +01:00
assertions = [
{
assertion = themeDefined || layoutDefined;
message = ''
Nixvim (plugins.alpha): You have to either set a `theme` or define some sections in `layout`.
'';
}
{
assertion = !(themeDefined && layoutDefined);
message = ''
Nixvim (plugins.alpha): You can't define both a `theme` and custom options.
Set `plugins.alpha.theme = null` if you want to configure alpha manually using the `layout` option.
'';
}
2024-01-12 23:13:04 +01:00
];
extraConfigLua =
let
setupOptions =
if themeDefined then
cfg.theme
else
(with cfg; {
inherit layout opts;
});
in
''
require('alpha').setup(${lib.nixvim.toLuaObject setupOptions})
2024-09-18 22:05:48 -05:00
require('alpha.term')
'';
};
}