Skip to content

Commit caaa371

Browse files
HeitorAugustoLNGaetanLepage
authored andcommitted
plugins/alpha: migrate to mkNeovimPlugin
1 parent 5da3805 commit caaa371

File tree

3 files changed

+86
-176
lines changed

3 files changed

+86
-176
lines changed

plugins/by-name/alpha/default.nix

Lines changed: 63 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -1,177 +1,75 @@
1-
{
2-
lib,
3-
config,
4-
pkgs,
5-
...
6-
}:
7-
let
8-
inherit (lib) types mkOption;
1+
{ lib, ... }:
2+
lib.nixvim.plugins.mkNeovimPlugin {
3+
name = "alpha";
4+
package = "alpha-nvim";
95

10-
cfg = config.plugins.alpha;
6+
maintainers = [ lib.maintainers.HeitorAugustoLN ];
117

12-
sectionType = types.submodule {
13-
freeformType = with types; attrsOf anything;
14-
options = {
15-
type = mkOption {
16-
type = types.enum [
17-
"button"
18-
"group"
19-
"padding"
20-
"text"
21-
"terminal"
22-
];
23-
description = "Type of section";
24-
};
25-
26-
val = lib.nixvim.mkNullOrOption (
27-
with types;
28-
nullOr (oneOf [
29-
30-
# "button", "text"
31-
(maybeRaw str)
32-
# "padding"
33-
int
34-
(listOf (
35-
either
36-
# "text" (list of strings)
37-
str
38-
# "group"
39-
(attrsOf anything)
40-
))
41-
])
42-
) "Value for section";
43-
44-
opts = mkOption {
45-
type = with types; attrsOf anything;
46-
default = { };
47-
description = "Additional options for the section";
48-
};
49-
};
50-
};
51-
in
52-
{
53-
options = {
54-
plugins.alpha = {
55-
enable = lib.mkEnableOption "alpha-nvim";
8+
# TODO Added 2025-10-26: remove after 26.05
9+
inherit (import ./deprecations.nix lib) imports optionsRenamedToSettings;
5610

57-
package = lib.mkPackageOption pkgs "alpha-nvim" {
58-
default = [
59-
"vimPlugins"
60-
"alpha-nvim"
11+
settingsExample = {
12+
layout = [
13+
{
14+
type = "padding";
15+
val = 2;
16+
}
17+
{
18+
type = "text";
19+
val = [
20+
"███╗ ██╗██╗██╗ ██╗██╗ ██╗██╗███╗ ███╗"
21+
"████╗ ██║██║╚██╗██╔╝██║ ██║██║████╗ ████║"
22+
"██╔██╗ ██║██║ ╚███╔╝ ██║ ██║██║██╔████╔██║"
23+
"██║╚██╗██║██║ ██╔██╗ ╚██╗ ██╔╝██║██║╚██╔╝██║"
24+
"██║ ╚████║██║██╔╝ ██╗ ╚████╔╝ ██║██║ ╚═╝ ██║"
25+
"╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝"
6126
];
62-
};
63-
64-
theme = mkOption {
65-
type = with types; nullOr (maybeRaw str);
66-
apply = v: if lib.isString v then lib.nixvim.mkRaw "require'alpha.themes.${v}'.config" else v;
67-
default = null;
68-
example = "dashboard";
69-
description = "You can directly use a pre-defined theme.";
70-
};
71-
72-
layout = mkOption {
73-
type = with types; either (maybeRaw str) (listOf sectionType);
74-
default = [ ];
75-
description = "List of sections to layout for the dashboard";
76-
example = [
27+
opts = {
28+
position = "center";
29+
hl = "Type";
30+
};
31+
}
32+
{
33+
type = "padding";
34+
val = 2;
35+
}
36+
{
37+
type = "group";
38+
val = [
7739
{
78-
type = "padding";
79-
val = 2;
40+
type = "button";
41+
val = " New file";
42+
on_press = lib.nixvim.nestedLiteralLua "function() vim.cmd[[ene]] end";
43+
opts.shortcut = "n";
8044
}
8145
{
82-
type = "text";
83-
val = [
84-
"███╗ ██╗██╗██╗ ██╗██╗ ██╗██╗███╗ ███╗"
85-
"████╗ ██║██║╚██╗██╔╝██║ ██║██║████╗ ████║"
86-
"██╔██╗ ██║██║ ╚███╔╝ ██║ ██║██║██╔████╔██║"
87-
"██║╚██╗██║██║ ██╔██╗ ╚██╗ ██╔╝██║██║╚██╔╝██║"
88-
"██║ ╚████║██║██╔╝ ██╗ ╚████╔╝ ██║██║ ╚═╝ ██║"
89-
"╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝"
90-
];
91-
opts = {
92-
position = "center";
93-
hl = "Type";
94-
};
95-
}
96-
{
97-
type = "padding";
98-
val = 2;
99-
}
100-
{
101-
type = "group";
102-
val = [
103-
{
104-
type = "button";
105-
val = " New file";
106-
on_press.__raw = "function() vim.cmd[[ene]] end";
107-
opts.shortcut = "n";
108-
}
109-
{
110-
type = "button";
111-
val = " Quit Neovim";
112-
on_press.__raw = "function() vim.cmd[[qa]] end";
113-
opts.shortcut = "q";
114-
}
115-
];
116-
}
117-
{
118-
type = "padding";
119-
val = 2;
120-
}
121-
{
122-
type = "text";
123-
val = "Inspiring quote here.";
124-
opts = {
125-
position = "center";
126-
hl = "Keyword";
127-
};
46+
type = "button";
47+
val = " Quit Neovim";
48+
on_press = lib.nixvim.nestedLiteralLua "function() vim.cmd[[qa]] end";
49+
opts.shortcut = "q";
12850
}
12951
];
130-
};
131-
132-
opts = lib.nixvim.mkNullOrOption (with types; attrsOf anything) ''
133-
Optional global options.
134-
'';
135-
};
52+
}
53+
{
54+
type = "padding";
55+
val = 2;
56+
}
57+
{
58+
type = "text";
59+
val = "Inspiring quote here.";
60+
opts = {
61+
position = "center";
62+
hl = "Keyword";
63+
};
64+
}
65+
];
13666
};
13767

138-
config =
139-
let
140-
layoutDefined = cfg.layout != [ ];
141-
themeDefined = cfg.theme != null;
142-
in
143-
lib.mkIf cfg.enable {
144-
extraPlugins = [ cfg.package ];
145-
146-
assertions = lib.nixvim.mkAssertions "plugins.alpha" [
147-
{
148-
assertion = themeDefined || layoutDefined;
149-
message = ''
150-
You have to either set a `theme` or define some sections in `layout`.
151-
'';
152-
}
153-
{
154-
assertion = !(themeDefined && layoutDefined);
155-
message = ''
156-
You can't define both a `theme` and custom options.
157-
Set `plugins.alpha.theme = null` if you want to configure alpha manually using the `layout` option.
158-
'';
159-
}
160-
];
161-
162-
extraConfigLua =
163-
let
164-
setupOptions =
165-
if themeDefined then
166-
cfg.theme
167-
else
168-
(with cfg; {
169-
inherit layout opts;
170-
});
171-
in
172-
''
173-
require('alpha').setup(${lib.nixvim.toLuaObject setupOptions})
174-
require('alpha.term')
175-
'';
176-
};
68+
callSetup = false;
69+
extraConfig = cfg: {
70+
plugins.alpha.luaConfig.content = ''
71+
require('alpha').setup(${lib.nixvim.toLuaObject cfg.settings})
72+
require('alpha.term')
73+
'';
74+
};
17775
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
lib: {
2+
imports = [
3+
(lib.mkRemovedOptionModule [ "plugins" "alpha" "theme" ] ''
4+
Directly use `settings` to set the theme.
5+
Example:
6+
7+
plugins.alpha = {
8+
enable = true;
9+
settings.__raw = "require('alpha.themes.dashboard').config"
10+
}
11+
'')
12+
];
13+
optionsRenamedToSettings = [
14+
"opts"
15+
"layout"
16+
];
17+
}

tests/test-sources/plugins/by-name/alpha/default.nix

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1+
{ lib, ... }:
12
{
23
theme = {
34
plugins.alpha = {
45
enable = true;
5-
theme = "dashboard";
6-
};
7-
};
86

9-
theme-lua = {
10-
plugins.alpha = {
11-
enable = true;
12-
theme.__raw = "require'alpha.themes.startify'.config";
7+
settings = lib.nixvim.mkRaw "require('alpha.themes.dashboard').config";
138
};
149
};
1510

1611
terminal = {
1712
plugins.alpha = {
1813
enable = true;
19-
layout = [
14+
settings.layout = [
2015
{
2116
type = "terminal";
2217
command = "echo 'Welcome to Nixvim!'";
@@ -34,7 +29,7 @@
3429
plugins.alpha = {
3530
enable = true;
3631

37-
layout = [
32+
settings.layout = [
3833
{
3934
type = "padding";
4035
val = 2;
@@ -88,7 +83,7 @@
8883
};
8984
}
9085
];
91-
opts = {
86+
settings.opts = {
9287
margin = 0;
9388
noautocmd = true;
9489

@@ -104,7 +99,7 @@
10499
plugins.web-devicons.enable = false;
105100
plugins.alpha = {
106101
enable = true;
107-
theme = "dashboard";
102+
settings = lib.nixvim.mkRaw "require('alpha.themes.dashboard').config";
108103
};
109104
};
110105
}

0 commit comments

Comments
 (0)