Skip to content

Commit 0827c5c

Browse files
committed
plugins/notify: migrate to mkNeovimPlugin
1 parent 10ea28f commit 0827c5c

File tree

3 files changed

+123
-97
lines changed

3 files changed

+123
-97
lines changed

plugins/by-name/notify/default.nix

Lines changed: 66 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
11
{
22
lib,
3-
helpers,
4-
config,
5-
pkgs,
63
...
74
}:
8-
with lib;
95
let
10-
cfg = config.plugins.notify;
6+
inherit (lib.nixvim)
7+
defaultNullOpts
8+
mkNullOrOption
9+
;
10+
inherit (lib) types;
1111
in
12-
{
13-
options.plugins.notify = lib.nixvim.plugins.neovim.extraOptionsOptions // {
14-
enable = mkEnableOption "nvim-notify";
15-
16-
package = lib.mkPackageOption pkgs "nvim-notify" {
17-
default = [
18-
"vimPlugins"
19-
"nvim-notify"
20-
];
21-
};
22-
23-
level = helpers.defaultNullOpts.mkLogLevel "info" ''
12+
lib.nixvim.plugins.mkNeovimPlugin {
13+
name = "notify";
14+
packPathName = "nvim-notify";
15+
package = "nvim-notify";
16+
maintainers = [ lib.maintainers.khaneliman ];
17+
18+
description = ''
19+
A fancy, configurable, notification manager for Neovim.
20+
'';
21+
22+
settingsOptions = {
23+
level = defaultNullOpts.mkLogLevel "info" ''
2424
Minimum log level to display. See `vim.log.levels`.
2525
'';
26-
27-
timeout = helpers.defaultNullOpts.mkUnsignedInt 5000 "Default timeout for notification.";
28-
29-
maxWidth = helpers.mkNullOrOption (with types; either ints.unsigned rawLua) ''
26+
timeout = defaultNullOpts.mkUnsignedInt 5000 "Default timeout for notification.";
27+
max_width = mkNullOrOption (with types; either ints.unsigned rawLua) ''
3028
Max number of columns for messages.
3129
'';
32-
33-
maxHeight = helpers.mkNullOrOption (with types; either ints.unsigned rawLua) ''
30+
max_height = mkNullOrOption (with types; either ints.unsigned rawLua) ''
3431
Max number of lines for a message.
3532
'';
36-
3733
stages =
38-
helpers.defaultNullOpts.mkNullable
34+
defaultNullOpts.mkNullable
3935
(
4036
with types;
4137
either (enum [
@@ -50,82 +46,73 @@ in
5046
Animation stages.
5147
Can be either one of the builtin stages or an array of lua functions.
5248
'';
53-
54-
backgroundColour = helpers.defaultNullOpts.mkStr "NotifyBackground" ''
49+
background_colour = defaultNullOpts.mkStr "NotifyBackground" ''
5550
For stages that change opacity this is treated as the highlight behind the window.
5651
Set this to either a highlight group, an RGB hex value e.g. "#000000" or a function
5752
returning an RGB code for dynamic values.
5853
'';
59-
60-
icons =
61-
mapAttrs (name: default: helpers.defaultNullOpts.mkStr default "Icon for the ${name} level.")
62-
{
63-
error = "";
64-
warn = "";
65-
info = "";
66-
debug = "";
67-
trace = "✎";
68-
};
69-
70-
onOpen = helpers.defaultNullOpts.mkLuaFn "nil" ''
54+
icons = lib.mapAttrs (name: default: defaultNullOpts.mkStr default "Icon for the ${name} level.") {
55+
error = "";
56+
warn = "";
57+
info = "";
58+
debug = "";
59+
trace = "✎";
60+
};
61+
on_open = defaultNullOpts.mkLuaFn "nil" ''
7162
Function called when a new window is opened, use for changing win settings/config.
7263
'';
73-
74-
onClose = helpers.defaultNullOpts.mkLuaFn "nil" ''
64+
on_close = defaultNullOpts.mkLuaFn "nil" ''
7565
Function called when a new window is closed.
7666
'';
77-
78-
render = helpers.defaultNullOpts.mkEnumFirstDefault [
67+
render = defaultNullOpts.mkEnumFirstDefault [
7968
"default"
8069
"minimal"
8170
"simple"
8271
"compact"
8372
"wrapped-compact"
8473
] "Function to render a notification buffer or a built-in renderer name.";
85-
86-
minimumWidth = helpers.defaultNullOpts.mkUnsignedInt 50 ''
74+
minimum_width = defaultNullOpts.mkUnsignedInt 50 ''
8775
Minimum width for notification windows.
8876
'';
89-
90-
fps = helpers.defaultNullOpts.mkPositiveInt 30 ''
77+
fps = defaultNullOpts.mkPositiveInt 30 ''
9178
Frames per second for animation stages, higher value means smoother animations but more CPU
9279
usage.
9380
'';
94-
95-
topDown = helpers.defaultNullOpts.mkBool true ''
81+
top_down = defaultNullOpts.mkBool true ''
9682
Whether or not to position the notifications at the top or not.
9783
'';
9884
};
9985

100-
config =
101-
let
102-
setupOptions =
103-
with cfg;
104-
{
105-
inherit level timeout;
106-
max_width = maxWidth;
107-
max_height = maxHeight;
108-
stages = helpers.ifNonNull' stages (if isString stages then stages else map helpers.mkRaw stages);
109-
background_colour = backgroundColour;
110-
icons = mapAttrs' (name: value: {
111-
name = strings.toUpper name;
112-
inherit value;
113-
}) icons;
114-
on_open = onOpen;
115-
on_close = onClose;
116-
inherit render;
117-
minimum_width = minimumWidth;
118-
inherit fps;
119-
top_down = topDown;
120-
}
121-
// cfg.extraOptions;
122-
in
123-
mkIf cfg.enable {
124-
extraPlugins = [ cfg.package ];
125-
126-
extraConfigLua = ''
127-
vim.notify = require('notify');
128-
require('notify').setup(${lib.nixvim.toLuaObject setupOptions})
129-
'';
86+
settingsExample = {
87+
settings = {
88+
level = "info";
89+
timeout = 5000;
90+
max_width = 80;
91+
max_height = 10;
92+
stages = "fade_in_slide_out";
93+
background_colour = "#000000";
94+
icons = {
95+
error = "";
96+
warn = "";
97+
info = "";
98+
debug = "";
99+
trace = "✎";
100+
};
101+
on_open.__raw = "function() print('Window opened') end";
102+
on_close.__raw = "function() print('Window closed') end";
103+
render = "default";
104+
minimum_width = 50;
105+
fps = 30;
106+
top_down = true;
130107
};
108+
};
109+
110+
extraConfig = {
111+
plugins.notify.luaConfig.pre = ''
112+
vim.notify = require('notify');
113+
'';
114+
};
115+
116+
# TODO: Deprecated on 2025-02-01
117+
inherit (import ./deprecations.nix) deprecateExtraOptions optionsRenamedToSettings;
131118
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
deprecateExtraOptions = true;
3+
optionsRenamedToSettings = [
4+
"level"
5+
"timeout"
6+
"maxWidth"
7+
"maxHeight"
8+
"stages"
9+
"backgroundColour"
10+
[
11+
"icons"
12+
"error"
13+
]
14+
[
15+
"icons"
16+
"warn"
17+
]
18+
[
19+
"icons"
20+
"info"
21+
]
22+
[
23+
"icons"
24+
"debug"
25+
]
26+
[
27+
"icons"
28+
"trace"
29+
]
30+
"onOpen"
31+
"onClose"
32+
"render"
33+
"minimumWidth"
34+
"fps"
35+
"topDown"
36+
];
37+
}

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,27 @@
77
plugins.notify = {
88
enable = true;
99

10-
level = "info";
11-
timeout = 5000;
12-
maxWidth = null;
13-
maxHeight = null;
14-
stages = "fade_in_slide_out";
15-
backgroundColour = "NotifyBackground";
16-
icons = {
17-
error = "";
18-
warn = "";
19-
info = "";
20-
debug = "";
21-
trace = "✎";
10+
settings = {
11+
level = "info";
12+
timeout = 5000;
13+
max_width = null;
14+
max_height = null;
15+
stages = "fade_in_slide_out";
16+
background_colour = "NotifyBackground";
17+
icons = {
18+
error = "";
19+
warn = "";
20+
info = "";
21+
debug = "";
22+
trace = "✎";
23+
};
24+
on_open = null;
25+
on_close = null;
26+
render = "default";
27+
minimum_width = 50;
28+
fps = 30;
29+
top_down = true;
2230
};
23-
onOpen = null;
24-
onClose = null;
25-
render = "default";
26-
minimumWidth = 50;
27-
fps = 30;
28-
topDown = true;
2931
};
3032
};
3133
}

0 commit comments

Comments
 (0)