Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 63 additions & 165 deletions plugins/by-name/alpha/default.nix
Original file line number Diff line number Diff line change
@@ -1,177 +1,75 @@
{
lib,
config,
pkgs,
...
}:
let
inherit (lib) types mkOption;
{ lib, ... }:
lib.nixvim.plugins.mkNeovimPlugin {
name = "alpha";
package = "alpha-nvim";

cfg = config.plugins.alpha;
maintainers = [ lib.maintainers.HeitorAugustoLN ];

sectionType = types.submodule {
freeformType = with types; attrsOf anything;
options = {
type = mkOption {
type = types.enum [
"button"
"group"
"padding"
"text"
"terminal"
];
description = "Type of section";
};

val = lib.nixvim.mkNullOrOption (
with types;
nullOr (oneOf [

# "button", "text"
(maybeRaw str)
# "padding"
int
(listOf (
either
# "text" (list of strings)
str
# "group"
(attrsOf anything)
))
])
) "Value for section";

opts = mkOption {
type = with types; attrsOf anything;
default = { };
description = "Additional options for the section";
};
};
};
in
{
options = {
plugins.alpha = {
enable = lib.mkEnableOption "alpha-nvim";
# TODO Added 2025-10-26: remove after 26.05
inherit (import ./deprecations.nix lib) imports optionsRenamedToSettings;

package = lib.mkPackageOption pkgs "alpha-nvim" {
default = [
"vimPlugins"
"alpha-nvim"
settingsExample = {
layout = [
{
type = "padding";
val = 2;
}
{
type = "text";
val = [
"███╗ ██╗██╗██╗ ██╗██╗ ██╗██╗███╗ ███╗"
"████╗ ██║██║╚██╗██╔╝██║ ██║██║████╗ ████║"
"██╔██╗ ██║██║ ╚███╔╝ ██║ ██║██║██╔████╔██║"
"██║╚██╗██║██║ ██╔██╗ ╚██╗ ██╔╝██║██║╚██╔╝██║"
"██║ ╚████║██║██╔╝ ██╗ ╚████╔╝ ██║██║ ╚═╝ ██║"
"╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝"
];
};

theme = mkOption {
type = with types; nullOr (maybeRaw str);
apply = v: if lib.isString v then lib.nixvim.mkRaw "require'alpha.themes.${v}'.config" else v;
default = null;
example = "dashboard";
description = "You can directly use a pre-defined theme.";
};

layout = mkOption {
type = with types; either (maybeRaw str) (listOf sectionType);
default = [ ];
description = "List of sections to layout for the dashboard";
example = [
opts = {
position = "center";
hl = "Type";
};
}
{
type = "padding";
val = 2;
}
{
type = "group";
val = [
{
type = "padding";
val = 2;
type = "button";
val = " New file";
on_press = lib.nixvim.nestedLiteralLua "function() vim.cmd[[ene]] end";
opts.shortcut = "n";
}
{
type = "text";
val = [
"███╗ ██╗██╗██╗ ██╗██╗ ██╗██╗███╗ ███╗"
"████╗ ██║██║╚██╗██╔╝██║ ██║██║████╗ ████║"
"██╔██╗ ██║██║ ╚███╔╝ ██║ ██║██║██╔████╔██║"
"██║╚██╗██║██║ ██╔██╗ ╚██╗ ██╔╝██║██║╚██╔╝██║"
"██║ ╚████║██║██╔╝ ██╗ ╚████╔╝ ██║██║ ╚═╝ ██║"
"╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝"
];
opts = {
position = "center";
hl = "Type";
};
}
{
type = "padding";
val = 2;
}
{
type = "group";
val = [
{
type = "button";
val = " New file";
on_press.__raw = "function() vim.cmd[[ene]] end";
opts.shortcut = "n";
}
{
type = "button";
val = " Quit Neovim";
on_press.__raw = "function() vim.cmd[[qa]] end";
opts.shortcut = "q";
}
];
}
{
type = "padding";
val = 2;
}
{
type = "text";
val = "Inspiring quote here.";
opts = {
position = "center";
hl = "Keyword";
};
type = "button";
val = " Quit Neovim";
on_press = lib.nixvim.nestedLiteralLua "function() vim.cmd[[qa]] end";
opts.shortcut = "q";
}
];
};

opts = lib.nixvim.mkNullOrOption (with types; attrsOf anything) ''
Optional global options.
'';
};
}
{
type = "padding";
val = 2;
}
{
type = "text";
val = "Inspiring quote here.";
opts = {
position = "center";
hl = "Keyword";
};
}
];
};

config =
let
layoutDefined = cfg.layout != [ ];
themeDefined = cfg.theme != null;
in
lib.mkIf cfg.enable {
extraPlugins = [ cfg.package ];

assertions = lib.nixvim.mkAssertions "plugins.alpha" [
{
assertion = themeDefined || layoutDefined;
message = ''
You have to either set a `theme` or define some sections in `layout`.
'';
}
{
assertion = !(themeDefined && layoutDefined);
message = ''
You can't define both a `theme` and custom options.
Set `plugins.alpha.theme = null` if you want to configure alpha manually using the `layout` option.
'';
}
];

extraConfigLua =
let
setupOptions =
if themeDefined then
cfg.theme
else
(with cfg; {
inherit layout opts;
});
in
''
require('alpha').setup(${lib.nixvim.toLuaObject setupOptions})
require('alpha.term')
'';
};
callSetup = false;
extraConfig = cfg: {
plugins.alpha.luaConfig.content = ''
require('alpha').setup(${lib.nixvim.toLuaObject cfg.settings})
require('alpha.term')
'';
};
}
17 changes: 17 additions & 0 deletions plugins/by-name/alpha/deprecations.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
lib: {
imports = [
(lib.mkRemovedOptionModule [ "plugins" "alpha" "theme" ] ''
Directly use `settings` to set the theme.
Example:

plugins.alpha = {
enable = true;
settings.__raw = "require('alpha.themes.dashboard').config"
}
'')
];
optionsRenamedToSettings = [
"opts"
"layout"
];
}
17 changes: 6 additions & 11 deletions tests/test-sources/plugins/by-name/alpha/default.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
{ lib, ... }:
{
theme = {
plugins.alpha = {
enable = true;
theme = "dashboard";
};
};

theme-lua = {
plugins.alpha = {
enable = true;
theme.__raw = "require'alpha.themes.startify'.config";
settings = lib.nixvim.mkRaw "require('alpha.themes.dashboard').config";
};
};

terminal = {
plugins.alpha = {
enable = true;
layout = [
settings.layout = [
{
type = "terminal";
command = "echo 'Welcome to Nixvim!'";
Expand All @@ -34,7 +29,7 @@
plugins.alpha = {
enable = true;

layout = [
settings.layout = [
{
type = "padding";
val = 2;
Expand Down Expand Up @@ -88,7 +83,7 @@
};
}
];
opts = {
settings.opts = {
margin = 0;
noautocmd = true;

Expand All @@ -104,7 +99,7 @@
plugins.web-devicons.enable = false;
plugins.alpha = {
enable = true;
theme = "dashboard";
settings = lib.nixvim.mkRaw "require('alpha.themes.dashboard').config";
};
};
}