mirror of
https://github.com/nix-community/nixvim.git
synced 2025-11-08 19:46:06 +01:00
plugins/alpha: migrate to mkNeovimPlugin
This commit is contained in:
parent
68b07c2c34
commit
deb32aecac
2 changed files with 110 additions and 171 deletions
|
|
@ -1,177 +1,113 @@
|
||||||
{
|
{ lib, ... }:
|
||||||
lib,
|
lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
config,
|
name = "alpha";
|
||||||
pkgs,
|
package = "alpha-nvim";
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
inherit (lib) types mkOption;
|
|
||||||
|
|
||||||
cfg = config.plugins.alpha;
|
maintainers = [ lib.maintainers.HeitorAugustoLN ];
|
||||||
|
|
||||||
sectionType = types.submodule {
|
# TODO Added 2025-10-26: remove after 26.05
|
||||||
freeformType = with types; attrsOf anything;
|
optionsRenamedToSettings = [
|
||||||
options = {
|
"opts"
|
||||||
type = mkOption {
|
"layout"
|
||||||
type = types.enum [
|
];
|
||||||
"button"
|
|
||||||
"group"
|
settingsExample = {
|
||||||
"padding"
|
layout = [
|
||||||
"text"
|
{
|
||||||
"terminal"
|
type = "padding";
|
||||||
|
val = 2;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
type = "text";
|
||||||
|
val = [
|
||||||
|
"███╗ ██╗██╗██╗ ██╗██╗ ██╗██╗███╗ ███╗"
|
||||||
|
"████╗ ██║██║╚██╗██╔╝██║ ██║██║████╗ ████║"
|
||||||
|
"██╔██╗ ██║██║ ╚███╔╝ ██║ ██║██║██╔████╔██║"
|
||||||
|
"██║╚██╗██║██║ ██╔██╗ ╚██╗ ██╔╝██║██║╚██╔╝██║"
|
||||||
|
"██║ ╚████║██║██╔╝ ██╗ ╚████╔╝ ██║██║ ╚═╝ ██║"
|
||||||
|
"╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝"
|
||||||
];
|
];
|
||||||
description = "Type of section";
|
opts = {
|
||||||
};
|
position = "center";
|
||||||
|
hl = "Type";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
{
|
||||||
|
type = "padding";
|
||||||
|
val = 2;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
type = "group";
|
||||||
|
val = [
|
||||||
|
{
|
||||||
|
type = "button";
|
||||||
|
val = " New file";
|
||||||
|
on_press = lib.nixvim.nestedLiteralLua "function() vim.cmd[[ene]] end";
|
||||||
|
opts.shortcut = "n";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
type = "button";
|
||||||
|
val = " Quit Neovim";
|
||||||
|
on_press = lib.nixvim.nestedLiteralLua "function() vim.cmd[[qa]] end";
|
||||||
|
opts.shortcut = "q";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
type = "padding";
|
||||||
|
val = 2;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
type = "text";
|
||||||
|
val = "Inspiring quote here.";
|
||||||
|
opts = {
|
||||||
|
position = "center";
|
||||||
|
hl = "Keyword";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
val = lib.nixvim.mkNullOrOption (
|
extraOptions = {
|
||||||
with types;
|
theme = lib.mkOption {
|
||||||
nullOr (oneOf [
|
type =
|
||||||
|
with lib.types;
|
||||||
# "button", "text"
|
let
|
||||||
(maybeRaw str)
|
# TODO: deprecated 2025-10-30, remove after 26.05
|
||||||
# "padding"
|
old = nullOr (maybeRaw str);
|
||||||
int
|
new = nullOr str;
|
||||||
(listOf (
|
in
|
||||||
either
|
old // { inherit (new) description; };
|
||||||
# "text" (list of strings)
|
default = null;
|
||||||
str
|
example = "dashboard";
|
||||||
# "group"
|
description = "You can directly use a pre-defined theme.";
|
||||||
(attrsOf anything)
|
|
||||||
))
|
|
||||||
])
|
|
||||||
) "Value for section";
|
|
||||||
|
|
||||||
opts = mkOption {
|
|
||||||
type = with types; attrsOf anything;
|
|
||||||
default = { };
|
|
||||||
description = "Additional options for the section";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
|
||||||
{
|
callSetup = false;
|
||||||
options = {
|
extraConfig = cfg: opts: {
|
||||||
|
assertions = lib.nixvim.mkAssertions "plugins.alpha" {
|
||||||
|
assertion = cfg.theme != null -> builtins.isString cfg.theme;
|
||||||
|
message = ''
|
||||||
|
Defining `${opts.theme}` as raw lua is deprecated. You can define `${opts.settings}` as raw lua instead:
|
||||||
|
${opts.settings} = lib.nixvim.mkRaw ${lib.generators.toPretty { } cfg.theme.__raw};
|
||||||
|
'';
|
||||||
|
};
|
||||||
plugins.alpha = {
|
plugins.alpha = {
|
||||||
enable = lib.mkEnableOption "alpha-nvim";
|
settings = lib.mkIf (cfg.theme != null) (
|
||||||
|
lib.mkDerivedConfig opts.theme (
|
||||||
|
value:
|
||||||
|
if builtins.isString value then
|
||||||
|
lib.nixvim.mkRaw "require('alpha.themes.${value}').config"
|
||||||
|
else
|
||||||
|
value
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "alpha-nvim" {
|
luaConfig.content = ''
|
||||||
default = [
|
require('alpha').setup(${lib.nixvim.toLuaObject cfg.settings})
|
||||||
"vimPlugins"
|
require('alpha.term')
|
||||||
"alpha-nvim"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
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 = [
|
|
||||||
{
|
|
||||||
type = "padding";
|
|
||||||
val = 2;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
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";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
opts = lib.nixvim.mkNullOrOption (with types; attrsOf anything) ''
|
|
||||||
Optional global options.
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
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')
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,25 @@
|
||||||
|
{ lib, ... }:
|
||||||
{
|
{
|
||||||
theme = {
|
theme = {
|
||||||
plugins.alpha = {
|
plugins.alpha = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
theme = "dashboard";
|
theme = "dashboard";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
theme-lua = {
|
theme-raw-settings = {
|
||||||
plugins.alpha = {
|
plugins.alpha = {
|
||||||
enable = true;
|
enable = true;
|
||||||
theme.__raw = "require'alpha.themes.startify'.config";
|
|
||||||
|
settings = lib.nixvim.mkRaw "require('alpha.themes.dashboard').config";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
terminal = {
|
terminal = {
|
||||||
plugins.alpha = {
|
plugins.alpha = {
|
||||||
enable = true;
|
enable = true;
|
||||||
layout = [
|
settings.layout = [
|
||||||
{
|
{
|
||||||
type = "terminal";
|
type = "terminal";
|
||||||
command = "echo 'Welcome to Nixvim!'";
|
command = "echo 'Welcome to Nixvim!'";
|
||||||
|
|
@ -34,7 +37,7 @@
|
||||||
plugins.alpha = {
|
plugins.alpha = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
layout = [
|
settings.layout = [
|
||||||
{
|
{
|
||||||
type = "padding";
|
type = "padding";
|
||||||
val = 2;
|
val = 2;
|
||||||
|
|
@ -88,7 +91,7 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
opts = {
|
settings.opts = {
|
||||||
margin = 0;
|
margin = 0;
|
||||||
noautocmd = true;
|
noautocmd = true;
|
||||||
|
|
||||||
|
|
@ -104,7 +107,7 @@
|
||||||
plugins.web-devicons.enable = false;
|
plugins.web-devicons.enable = false;
|
||||||
plugins.alpha = {
|
plugins.alpha = {
|
||||||
enable = true;
|
enable = true;
|
||||||
theme = "dashboard";
|
settings = lib.nixvim.mkRaw "require('alpha.themes.dashboard').config";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue