Skip to content

Commit 3ea66f1

Browse files
plugins/alpha: migrate to mkNeovimPlugin
1 parent 6f8d8f7 commit 3ea66f1

File tree

1 file changed

+152
-128
lines changed

1 file changed

+152
-128
lines changed

plugins/by-name/alpha/default.nix

Lines changed: 152 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,72 @@
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+
settingsOptions = {
20+
layout =
21+
let
22+
sectionType = types.submodule {
23+
freeformType = with types; attrsOf anything;
24+
options = {
25+
type = mkOption {
26+
type = types.enum [
27+
"button"
28+
"group"
29+
"padding"
30+
"text"
31+
"terminal"
32+
];
33+
example = "button";
34+
description = ''
35+
The type of the section.
36+
'';
37+
};
7138

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-
};
39+
val = defaultNullOpts.mkNullableWithRaw' {
40+
type =
41+
with types;
42+
oneOf [
43+
# button || text
44+
(maybeRaw str)
45+
# padding
46+
int
47+
(listOf (
48+
either str # text (list of strings)
49+
(attrsOf anything) # group
50+
))
51+
];
52+
example = "Some text";
53+
description = ''
54+
The value for the section.
55+
'';
56+
};
7957

80-
layout = mkOption {
81-
type = with types; either (maybeRaw str) (listOf sectionType);
82-
default = [ ];
83-
description = "List of sections to layout for the dashboard";
58+
opts = mkOption {
59+
type = with types; attrsOf anything;
60+
default = { };
61+
description = ''
62+
Additional options for the section.
63+
'';
64+
};
65+
};
66+
};
67+
in
68+
defaultNullOpts.mkNullableWithRaw' {
69+
type = with types; either str (listOf sectionType);
8470
example = [
8571
{
8672
type = "padding";
@@ -137,75 +123,113 @@ in
137123
];
138124
};
139125

140-
opts = lib.nixvim.mkNullOrOption (with types; attrsOf anything) ''
126+
opts = defaultNullOpts.mkAttrsOf' {
127+
type = types.anything;
128+
description = ''
141129
Optional global options.
142130
'';
143131
};
144132
};
145133

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

178-
extraPlugins = [ cfg.package ];
202+
optionsRenamedToSettings = [
203+
"opts"
204+
"layout"
205+
];
179206

180-
assertions = lib.nixvim.mkAssertions "plugins.alpha" [
207+
extraConfig =
208+
cfg:
209+
let
210+
layoutDefined = cfg.settings.layout != null;
211+
themeDefined = cfg.theme != null;
212+
in
213+
{
214+
assertions = mkAssertions "plugins.alpha" [
181215
{
182-
assertion = themeDefined || layoutDefined;
216+
assertion = layoutDefined || themeDefined;
183217
message = ''
184218
You have to either set a `theme` or define some sections in `layout`.
185219
'';
186220
}
187221
{
188-
assertion = !(themeDefined && layoutDefined);
222+
assertion = !(themeDefined && cfg.settings != { });
189223
message = ''
190224
You can't define both a `theme` and custom options.
191225
Set `plugins.alpha.theme = null` if you want to configure alpha manually using the `layout` option.
192226
'';
193227
}
194228
];
195229

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

0 commit comments

Comments
 (0)