Skip to content

Commit 03a6663

Browse files
plugins/alpha: migrate to mkNeovimPlugin
1 parent 6f8d8f7 commit 03a6663

File tree

1 file changed

+157
-128
lines changed

1 file changed

+157
-128
lines changed

plugins/by-name/alpha/default.nix

Lines changed: 157 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,74 @@
1-
{
2-
lib,
3-
config,
4-
options,
5-
pkgs,
6-
...
7-
}:
1+
{ lib, ... }:
82
let
9-
inherit (lib) types mkOption;
10-
11-
cfg = config.plugins.alpha;
12-
13-
sectionType = types.submodule {
14-
freeformType = with types; attrsOf anything;
15-
options = {
16-
type = mkOption {
17-
type = types.enum [
18-
"button"
19-
"group"
20-
"padding"
21-
"text"
22-
"terminal"
23-
];
24-
description = "Type of section";
25-
};
26-
27-
val = lib.nixvim.mkNullOrOption (
28-
with types;
29-
nullOr (oneOf [
30-
31-
# "button", "text"
32-
(maybeRaw str)
33-
# "padding"
34-
int
35-
(listOf (
36-
either
37-
# "text" (list of strings)
38-
str
39-
# "group"
40-
(attrsOf anything)
41-
))
42-
])
43-
) "Value for section";
44-
45-
opts = mkOption {
46-
type = with types; attrsOf anything;
47-
default = { };
48-
description = "Additional options for the section";
49-
};
50-
};
51-
};
3+
inherit (lib) mkOption types;
4+
inherit (lib.nixvim)
5+
defaultNullOpts
6+
mkAssertions
7+
mkRaw
8+
nestedLiteralLua
9+
toLuaObject
10+
;
5211
in
53-
{
54-
options = {
55-
plugins.alpha = {
56-
enable = lib.mkEnableOption "alpha-nvim";
57-
58-
package = lib.mkPackageOption pkgs "alpha-nvim" {
59-
default = [
60-
"vimPlugins"
61-
"alpha-nvim"
62-
];
63-
};
64-
65-
# TODO: deprecated 2024-08-29 remove after 24.11
66-
iconsEnabled = mkOption {
67-
type = types.bool;
68-
description = "Toggle icon support. Installs nvim-web-devicons.";
69-
visible = false;
70-
};
12+
lib.nixvim.plugins.mkNeovimPlugin {
13+
name = "alpha";
14+
packPathName = "alpha-nvim";
15+
package = "alpha-nvim";
16+
17+
maintainers = [ lib.maintainers.HeitorAugustoLN ];
18+
19+
callSetup = false;
20+
21+
settingsOptions = {
22+
layout =
23+
let
24+
sectionType = types.submodule {
25+
freeformType = with types; attrsOf anything;
26+
options = {
27+
type = mkOption {
28+
type = types.enum [
29+
"button"
30+
"group"
31+
"padding"
32+
"text"
33+
"terminal"
34+
];
35+
example = "button";
36+
description = ''
37+
The type of the section.
38+
'';
39+
};
7140

72-
theme = mkOption {
73-
type = with types; nullOr (maybeRaw str);
74-
apply = v: if lib.isString v then lib.nixvim.mkRaw "require'alpha.themes.${v}'.config" else v;
75-
default = null;
76-
example = "dashboard";
77-
description = "You can directly use a pre-defined theme.";
78-
};
41+
val = defaultNullOpts.mkNullableWithRaw' {
42+
type =
43+
with types;
44+
oneOf [
45+
# button || text
46+
(maybeRaw str)
47+
# padding
48+
int
49+
(listOf (
50+
either str # text (list of strings)
51+
(attrsOf anything) # group
52+
))
53+
];
54+
example = "Some text";
55+
description = ''
56+
The value for the section.
57+
'';
58+
};
7959

80-
layout = mkOption {
81-
type = with types; either (maybeRaw str) (listOf sectionType);
82-
default = [ ];
83-
description = "List of sections to layout for the dashboard";
60+
opts = mkOption {
61+
type = with types; attrsOf anything;
62+
default = { };
63+
description = ''
64+
Additional options for the section.
65+
'';
66+
};
67+
};
68+
};
69+
in
70+
defaultNullOpts.mkNullableWithRaw' {
71+
type = with types; either str (listOf sectionType);
8472
example = [
8573
{
8674
type = "padding";
@@ -135,77 +123,118 @@ in
135123
};
136124
}
137125
];
126+
description = ''
127+
List of sections to layout for the dashboard
128+
'';
138129
};
139130

140-
opts = lib.nixvim.mkNullOrOption (with types; attrsOf anything) ''
131+
opts = defaultNullOpts.mkAttrsOf' {
132+
type = types.anything;
133+
description = ''
141134
Optional global options.
142135
'';
143136
};
144137
};
145138

146-
config =
147-
let
148-
layoutDefined = cfg.layout != [ ];
149-
themeDefined = cfg.theme != null;
150-
151-
opt = options.plugins.alpha;
152-
in
153-
lib.mkIf cfg.enable {
154-
155-
# TODO: added 2024-09-20 remove after 24.11
156-
warnings = lib.nixvim.mkWarnings "plugins.alpha" {
157-
when = opt.iconsEnabled.isDefined;
158-
message = ''
159-
The option definition `plugins.alpha.iconsEnabled' in ${lib.showFiles opt.iconsEnabled.files} has been deprecated; please remove it.
160-
'';
161-
};
162-
163-
plugins.web-devicons =
164-
lib.mkIf
165-
(
166-
opt.iconsEnabled.isDefined
167-
&& cfg.iconsEnabled
168-
&& !(
169-
config.plugins.mini.enable
170-
&& config.plugins.mini.modules ? icons
171-
&& config.plugins.mini.mockDevIcons
172-
)
173-
)
139+
settingsExample = {
140+
layout = [
141+
{
142+
type = "padding";
143+
val = 2;
144+
}
145+
{
146+
type = "text";
147+
val = [
148+
"███╗ ██╗██╗██╗ ██╗██╗ ██╗██╗███╗ ███╗"
149+
"████╗ ██║██║╚██╗██╔╝██║ ██║██║████╗ ████║"
150+
"██╔██╗ ██║██║ ╚███╔╝ ██║ ██║██║██╔████╔██║"
151+
"██║╚██╗██║██║ ██╔██╗ ╚██╗ ██╔╝██║██║╚██╔╝██║"
152+
"██║ ╚████║██║██╔╝ ██╗ ╚████╔╝ ██║██║ ╚═╝ ██║"
153+
"╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝"
154+
];
155+
opts = {
156+
position = "center";
157+
hl = "Type";
158+
};
159+
}
160+
{
161+
type = "padding";
162+
val = 2;
163+
}
164+
{
165+
type = "group";
166+
val = [
174167
{
175-
enable = lib.mkOverride 1490 true;
176-
};
168+
type = "button";
169+
val = " New file";
170+
on_press = nestedLiteralLua "function() vim.cmd[[ene]] end";
171+
opts.shortcut = "n";
172+
}
173+
{
174+
type = "button";
175+
val = " Quit Neovim";
176+
on_press = nestedLiteralLua "function() vim.cmd[[qa]] end";
177+
opts.shortcut = "q";
178+
}
179+
];
180+
}
181+
{
182+
type = "padding";
183+
val = 2;
184+
}
185+
{
186+
type = "text";
187+
val = "Inspiring quote here.";
188+
opts = {
189+
position = "center";
190+
hl = "Keyword";
191+
};
192+
}
193+
];
194+
};
195+
196+
extraOptions = {
197+
theme = defaultNullOpts.mkStr' {
198+
description = ''
199+
The theme to use for the dashboard.
200+
'';
201+
example = "dashboard";
202+
apply =
203+
value: if builtins.isString value then mkRaw ''require("alpha.themes.${value}").config'' else value;
204+
};
205+
};
177206

178-
extraPlugins = [ cfg.package ];
207+
optionsRenamedToSettings = [
208+
"opts"
209+
"layout"
210+
];
179211

180-
assertions = lib.nixvim.mkAssertions "plugins.alpha" [
212+
extraConfig =
213+
cfg:
214+
let
215+
layoutDefined = cfg.settings.layout != null;
216+
themeDefined = cfg.theme != null;
217+
in
218+
{
219+
assertions = mkAssertions "plugins.alpha" [
181220
{
182-
assertion = themeDefined || layoutDefined;
221+
assertion = layoutDefined || themeDefined;
183222
message = ''
184223
You have to either set a `theme` or define some sections in `layout`.
185224
'';
186225
}
187226
{
188-
assertion = !(themeDefined && layoutDefined);
227+
assertion = !(themeDefined && toLuaObject cfg.settings != "{}");
189228
message = ''
190229
You can't define both a `theme` and custom options.
191230
Set `plugins.alpha.theme = null` if you want to configure alpha manually using the `layout` option.
192231
'';
193232
}
194233
];
195234

196-
extraConfigLua =
197-
let
198-
setupOptions =
199-
if themeDefined then
200-
cfg.theme
201-
else
202-
(with cfg; {
203-
inherit layout opts;
204-
});
205-
in
206-
''
207-
require('alpha').setup(${lib.nixvim.toLuaObject setupOptions})
208-
require('alpha.term')
209-
'';
235+
plugins.alpha.luaConfig.content = ''
236+
require('alpha').setup(${toLuaObject (if themeDefined then cfg.theme else cfg.settings)});
237+
require('alpha.term')
238+
'';
210239
};
211240
}

0 commit comments

Comments
 (0)