Skip to content

Commit c83415c

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

File tree

1 file changed

+155
-128
lines changed

1 file changed

+155
-128
lines changed

plugins/by-name/alpha/default.nix

Lines changed: 155 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,71 @@
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 optionalString types;
4+
inherit (lib.nixvim)
5+
defaultNullOpts
6+
mkAssertions
7+
nestedLiteralLua
8+
toLuaObject
9+
;
5210
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-
};
11+
lib.nixvim.plugins.mkNeovimPlugin {
12+
name = "alpha";
13+
packPathName = "alpha-nvim";
14+
package = "alpha-nvim";
15+
16+
maintainers = [ lib.maintainers.HeitorAugustoLN ];
17+
18+
settingsOptions = {
19+
layout =
20+
let
21+
sectionType = types.submodule {
22+
freeformType = with types; attrsOf anything;
23+
options = {
24+
type = mkOption {
25+
type = types.enum [
26+
"button"
27+
"group"
28+
"padding"
29+
"text"
30+
"terminal"
31+
];
32+
example = "button";
33+
description = ''
34+
The type of the section.
35+
'';
36+
};
7137

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

80-
layout = mkOption {
81-
type = with types; either (maybeRaw str) (listOf sectionType);
82-
default = [ ];
83-
description = "List of sections to layout for the dashboard";
57+
opts = mkOption {
58+
type = with types; attrsOf anything;
59+
default = { };
60+
description = ''
61+
Additional options for the section.
62+
'';
63+
};
64+
};
65+
};
66+
in
67+
defaultNullOpts.mkNullableWithRaw' {
68+
type = with types; either str (listOf sectionType);
8469
example = [
8570
{
8671
type = "padding";
@@ -137,75 +122,117 @@ in
137122
];
138123
};
139124

140-
opts = lib.nixvim.mkNullOrOption (with types; attrsOf anything) ''
125+
opts = defaultNullOpts.mkAttrsOf' {
126+
type = types.anything;
127+
description = ''
141128
Optional global options.
142129
'';
143130
};
144131
};
145132

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

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

180-
assertions = lib.nixvim.mkAssertions "plugins.alpha" [
210+
extraConfig =
211+
cfg:
212+
let
213+
layoutDefined = cfg.settings.layout != null;
214+
themeDefined = cfg.theme != null;
215+
in
216+
{
217+
assertions = mkAssertions "plugins.alpha" [
181218
{
182-
assertion = themeDefined || layoutDefined;
219+
assertion = layoutDefined || themeDefined;
183220
message = ''
184221
You have to either set a `theme` or define some sections in `layout`.
185222
'';
186223
}
187224
{
188-
assertion = !(themeDefined && layoutDefined);
225+
assertion = !(themeDefined && cfg.settings != { });
189226
message = ''
190227
You can't define both a `theme` and custom options.
191228
Set `plugins.alpha.theme = null` if you want to configure alpha manually using the `layout` option.
192229
'';
193230
}
194231
];
195232

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

0 commit comments

Comments
 (0)