Skip to content

Commit 0337a66

Browse files
plugins/alpha: migrate to mkNeovimPlugin
1 parent 6f8d8f7 commit 0337a66

File tree

1 file changed

+154
-128
lines changed

1 file changed

+154
-128
lines changed

plugins/by-name/alpha/default.nix

Lines changed: 154 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";
@@ -137,75 +125,113 @@ in
137125
];
138126
};
139127

140-
opts = lib.nixvim.mkNullOrOption (with types; attrsOf anything) ''
128+
opts = defaultNullOpts.mkAttrsOf' {
129+
type = types.anything;
130+
description = ''
141131
Optional global options.
142132
'';
143133
};
144134
};
145135

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-
)
136+
settingsExample = {
137+
layout = [
138+
{
139+
type = "padding";
140+
val = 2;
141+
}
142+
{
143+
type = "text";
144+
val = [
145+
"███╗ ██╗██╗██╗ ██╗██╗ ██╗██╗███╗ ███╗"
146+
"████╗ ██║██║╚██╗██╔╝██║ ██║██║████╗ ████║"
147+
"██╔██╗ ██║██║ ╚███╔╝ ██║ ██║██║██╔████╔██║"
148+
"██║╚██╗██║██║ ██╔██╗ ╚██╗ ██╔╝██║██║╚██╔╝██║"
149+
"██║ ╚████║██║██╔╝ ██╗ ╚████╔╝ ██║██║ ╚═╝ ██║"
150+
"╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝"
151+
];
152+
opts = {
153+
position = "center";
154+
hl = "Type";
155+
};
156+
}
157+
{
158+
type = "padding";
159+
val = 2;
160+
}
161+
{
162+
type = "group";
163+
val = [
174164
{
175-
enable = lib.mkOverride 1490 true;
176-
};
165+
type = "button";
166+
val = " New file";
167+
on_press = nestedLiteralLua "function() vim.cmd[[ene]] end";
168+
opts.shortcut = "n";
169+
}
170+
{
171+
type = "button";
172+
val = " Quit Neovim";
173+
on_press = nestedLiteralLua "function() vim.cmd[[qa]] end";
174+
opts.shortcut = "q";
175+
}
176+
];
177+
}
178+
{
179+
type = "padding";
180+
val = 2;
181+
}
182+
{
183+
type = "text";
184+
val = "Inspiring quote here.";
185+
opts = {
186+
position = "center";
187+
hl = "Keyword";
188+
};
189+
}
190+
];
191+
};
192+
193+
extraOptions = {
194+
theme = defaultNullOpts.mkStr' {
195+
description = ''
196+
The theme to use for the dashboard.
197+
'';
198+
example = "dashboard";
199+
apply =
200+
value: if builtins.isString value then mkRaw ''require("alpha.themes.${value}").config'' else value;
201+
};
202+
};
177203

178-
extraPlugins = [ cfg.package ];
204+
optionsRenamedToSettings = [
205+
"opts"
206+
"layout"
207+
];
179208

180-
assertions = lib.nixvim.mkAssertions "plugins.alpha" [
209+
extraConfig =
210+
cfg:
211+
let
212+
layoutDefined = cfg.settings.layout != null;
213+
themeDefined = cfg.theme != null;
214+
in
215+
{
216+
assertions = mkAssertions "plugins.alpha" [
181217
{
182-
assertion = themeDefined || layoutDefined;
218+
assertion = layoutDefined || themeDefined;
183219
message = ''
184220
You have to either set a `theme` or define some sections in `layout`.
185221
'';
186222
}
187223
{
188-
assertion = !(themeDefined && layoutDefined);
224+
assertion = !(themeDefined && toLuaObject cfg.settings != "{}");
189225
message = ''
190226
You can't define both a `theme` and custom options.
191227
Set `plugins.alpha.theme = null` if you want to configure alpha manually using the `layout` option.
192228
'';
193229
}
194230
];
195231

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-
'';
232+
plugins.alpha.luaConfig.content = ''
233+
require('alpha').setup(${toLuaObject (if themeDefined then cfg.theme else cfg.settings)});
234+
require('alpha.term')
235+
'';
210236
};
211237
}

0 commit comments

Comments
 (0)