This commit is contained in:
Heitor Augusto 2025-06-18 23:50:34 +01:00 committed by GitHub
commit 9af4b90430
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,86 +1,74 @@
{ { lib, ... }:
lib,
config,
options,
pkgs,
...
}:
let let
inherit (lib) types mkOption; inherit (lib) mkOption types;
inherit (lib.nixvim)
cfg = config.plugins.alpha; defaultNullOpts
mkAssertions
sectionType = types.submodule { mkRaw
freeformType = with types; attrsOf anything; nestedLiteralLua
options = { toLuaObject
type = mkOption { ;
type = types.enum [
"button"
"group"
"padding"
"text"
"terminal"
];
description = "Type of section";
};
val = lib.nixvim.mkNullOrOption (
with types;
nullOr (oneOf [
# "button", "text"
(maybeRaw str)
# "padding"
int
(listOf (
either
# "text" (list of strings)
str
# "group"
(attrsOf anything)
))
])
) "Value for section";
opts = mkOption {
type = with types; attrsOf anything;
default = { };
description = "Additional options for the section";
};
};
};
in in
{ lib.nixvim.plugins.mkNeovimPlugin {
options = { name = "alpha";
plugins.alpha = { packPathName = "alpha-nvim";
enable = lib.mkEnableOption "alpha-nvim"; package = "alpha-nvim";
package = lib.mkPackageOption pkgs "alpha-nvim" { maintainers = [ lib.maintainers.HeitorAugustoLN ];
default = [
"vimPlugins"
"alpha-nvim"
];
};
# TODO: deprecated 2024-08-29 remove after 24.11 callSetup = false;
iconsEnabled = mkOption {
type = types.bool;
description = "Toggle icon support. Installs nvim-web-devicons.";
visible = false;
};
theme = mkOption { settingsOptions = {
type = with types; nullOr (maybeRaw str); layout =
apply = v: if lib.isString v then lib.nixvim.mkRaw "require'alpha.themes.${v}'.config" else v; let
default = null; sectionType = types.submodule {
example = "dashboard"; freeformType = with types; attrsOf anything;
description = "You can directly use a pre-defined theme."; options = {
}; type = mkOption {
type = types.enum [
"button"
"group"
"padding"
"text"
"terminal"
];
example = "button";
description = ''
The type of the section.
'';
};
layout = mkOption { val = defaultNullOpts.mkNullableWithRaw' {
type = with types; either (maybeRaw str) (listOf sectionType); type =
default = [ ]; with types;
description = "List of sections to layout for the dashboard"; oneOf [
# button || text
(maybeRaw str)
# padding
int
(listOf (
either str # text (list of strings)
(attrsOf anything) # group
))
];
example = "Some text";
description = ''
The value for the section.
'';
};
opts = mkOption {
type = with types; attrsOf anything;
default = { };
description = ''
Additional options for the section.
'';
};
};
};
in
defaultNullOpts.mkNullableWithRaw' {
type = with types; either str (listOf sectionType);
example = [ example = [
{ {
type = "padding"; type = "padding";
@ -135,57 +123,108 @@ in
}; };
} }
]; ];
description = ''
List of sections to layout for the dashboard
'';
}; };
opts = lib.nixvim.mkNullOrOption (with types; attrsOf anything) '' opts = defaultNullOpts.mkAttrsOf' {
type = types.anything;
description = ''
Optional global options. Optional global options.
''; '';
}; };
}; };
config = settingsExample = {
let layout = [
layoutDefined = cfg.layout != [ ]; {
themeDefined = cfg.theme != null; type = "padding";
val = 2;
opt = options.plugins.alpha; }
in {
lib.mkIf cfg.enable { type = "text";
val = [
# TODO: added 2024-09-20 remove after 24.11 " "
warnings = lib.nixvim.mkWarnings "plugins.alpha" { " "
when = opt.iconsEnabled.isDefined; " "
message = '' " "
The option definition `plugins.alpha.iconsEnabled' in ${lib.showFiles opt.iconsEnabled.files} has been deprecated; please remove it. " "
''; " "
}; ];
opts = {
plugins.web-devicons = position = "center";
lib.mkIf hl = "Type";
( };
opt.iconsEnabled.isDefined }
&& cfg.iconsEnabled {
&& !( type = "padding";
config.plugins.mini.enable val = 2;
&& config.plugins.mini.modules ? icons }
&& config.plugins.mini.mockDevIcons {
) type = "group";
) val = [
{ {
enable = lib.mkOverride 1490 true; type = "button";
}; val = " New file";
on_press = nestedLiteralLua "function() vim.cmd[[ene]] end";
opts.shortcut = "n";
}
{
type = "button";
val = " Quit Neovim";
on_press = nestedLiteralLua "function() vim.cmd[[qa]] end";
opts.shortcut = "q";
}
];
}
{
type = "padding";
val = 2;
}
{
type = "text";
val = "Inspiring quote here.";
opts = {
position = "center";
hl = "Keyword";
};
}
];
};
extraPlugins = [ cfg.package ]; extraOptions = {
theme = defaultNullOpts.mkStr' {
description = ''
The theme to use for the dashboard.
'';
example = "dashboard";
apply =
value: if builtins.isString value then mkRaw ''require("alpha.themes.${value}").config'' else value;
};
};
assertions = lib.nixvim.mkAssertions "plugins.alpha" [ optionsRenamedToSettings = [
"opts"
"layout"
];
extraConfig =
cfg:
let
layoutDefined = cfg.settings.layout != null;
themeDefined = cfg.theme != null;
in
{
assertions = mkAssertions "plugins.alpha" [
{ {
assertion = themeDefined || layoutDefined; assertion = layoutDefined || themeDefined;
message = '' message = ''
You have to either set a `theme` or define some sections in `layout`. You have to either set a `theme` or define some sections in `layout`.
''; '';
} }
{ {
assertion = !(themeDefined && layoutDefined); assertion = !(themeDefined && toLuaObject cfg.settings != "{}");
message = '' message = ''
You can't define both a `theme` and custom options. 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. Set `plugins.alpha.theme = null` if you want to configure alpha manually using the `layout` option.
@ -193,19 +232,9 @@ in
} }
]; ];
extraConfigLua = plugins.alpha.luaConfig.content = ''
let require('alpha').setup(${toLuaObject (if themeDefined then cfg.theme else cfg.settings)});
setupOptions = require('alpha.term')
if themeDefined then '';
cfg.theme
else
(with cfg; {
inherit layout opts;
});
in
''
require('alpha').setup(${lib.nixvim.toLuaObject setupOptions})
require('alpha.term')
'';
}; };
} }