Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

neovim: use mini.base16 for colorscheme #536

Merged
merged 2 commits into from
Oct 19, 2024
Merged
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
56 changes: 38 additions & 18 deletions modules/neovim/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

{
options.stylix.targets.neovim = {
enable =
config.lib.stylix.mkEnableTarget "Neovim" true;

enable = config.lib.stylix.mkEnableTarget "Neovim" true;
plugin = lib.mkOption {
type = lib.types.enum [ "base16-nvim" "mini.base16" ];
default = "mini.base16";
description = "Plugin used for the colorscheme";
};
transparentBackground = {
main = lib.mkEnableOption "background transparency for the main Neovim window";
signColumn = lib.mkEnableOption "background transparency for the Neovim sign column";
Expand All @@ -17,27 +20,44 @@
cfg = config.stylix.targets.neovim;
in
{
plugins = lib.singleton {
plugin = pkgs.vimPlugins.base16-nvim;
type = "lua";
config = lib.mkMerge [
(with config.lib.stylix.colors.withHashtag; ''
plugins = [
(lib.mkIf (cfg.plugin == "base16-nvim") {
plugin = pkgs.vimPlugins.base16-nvim;
type = "lua";
config = with config.lib.stylix.colors.withHashtag; ''
require('base16-colorscheme').setup({
base00 = '${base00}', base01 = '${base01}', base02 = '${base02}', base03 = '${base03}',
base04 = '${base04}', base05 = '${base05}', base06 = '${base06}', base07 = '${base07}',
base08 = '${base08}', base09 = '${base09}', base0A = '${base0A}', base0B = '${base0B}',
base0C = '${base0C}', base0D = '${base0D}', base0E = '${base0E}', base0F = '${base0F}'
})
'')
(lib.mkIf cfg.transparentBackground.main ''
vim.cmd.highlight({ "Normal", "guibg=NONE", "ctermbg=NONE" })
vim.cmd.highlight({ "NonText", "guibg=NONE", "ctermbg=NONE" })
'')
(lib.mkIf cfg.transparentBackground.signColumn ''
vim.cmd.highlight({ "SignColumn", "guibg=NONE", "ctermbg=NONE" })
'')
];
};
'';
})
(lib.mkIf (cfg.plugin == "mini.base16") {
plugin = pkgs.vimPlugins.mini-nvim;
type = "lua";
config = with config.lib.stylix.colors.withHashtag; ''
require('mini.base16').setup({
palette = {
base00 = '${base00}', base01 = '${base01}', base02 = '${base02}', base03 = '${base03}',
base04 = '${base04}', base05 = '${base05}', base06 = '${base06}', base07 = '${base07}',
base08 = '${base08}', base09 = '${base09}', base0A = '${base0A}', base0B = '${base0B}',
base0C = '${base0C}', base0D = '${base0D}', base0E = '${base0E}', base0F = '${base0F}'
}
})
'';
})
];

extraLuaConfig = lib.mkMerge [
(lib.mkIf cfg.transparentBackground.main ''
vim.cmd.highlight({ "Normal", "guibg=NONE", "ctermbg=NONE" })
vim.cmd.highlight({ "NonText", "guibg=NONE", "ctermbg=NONE" })
'')
(lib.mkIf cfg.transparentBackground.signColumn ''
vim.cmd.highlight({ "SignColumn", "guibg=NONE", "ctermbg=NONE" })
'')
];
};
};
}
59 changes: 39 additions & 20 deletions modules/nixvim/nixvim.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
lib,
options,
...
}: {
}: let
cfg = config.stylix.targets.nixvim;
in {
options.stylix.targets.nixvim = {
enable =
config.lib.stylix.mkEnableTarget "nixvim" true;
enable = config.lib.stylix.mkEnableTarget "nixvim" true;
plugin = lib.mkOption {
type = lib.types.enum [ "base16-nvim" "mini.base16" ];
default = "mini.base16";
description = "Plugin used for the colorscheme";
};
transparentBackground = {
main = lib.mkEnableOption "background transparency for the main NeoVim window";
signColumn = lib.mkEnableOption "background transparency for the NeoVim sign column";
Expand Down Expand Up @@ -38,31 +44,44 @@
)
];

config = lib.mkIf (config.stylix.enable && config.stylix.targets.nixvim.enable && (config.programs ? nixvim)) (
lib.optionalAttrs (builtins.hasAttr "nixvim" options.programs) {
programs.nixvim = {
colorschemes.base16 = {
config = lib.mkIf (config.stylix.enable && cfg.enable && (config.programs ? nixvim)) (
lib.optionalAttrs (builtins.hasAttr "nixvim" options.programs) (lib.mkMerge [
(lib.mkIf (cfg.plugin == "base16-nvim") {
programs.nixvim.colorschemes.base16 = {
enable = true;

colorscheme = {
inherit (config.lib.stylix.colors.withHashtag)
base00 base01 base02 base03 base04 base05 base06 base07
base08 base09 base0A base0B base0C base0D base0E base0F;
};

enable = true;
};
})
(lib.mkIf (cfg.plugin == "mini.base16") {
programs.nixvim.plugins.mini = {
enable = true;

highlight = let
cfg = config.stylix.targets.nixvim;
transparent = {
bg = "none";
ctermbg = "none";
modules.base16.palette = {
inherit (config.lib.stylix.colors.withHashtag)
base00 base01 base02 base03 base04 base05 base06 base07
base08 base09 base0A base0B base0C base0D base0E base0F;
};
in {
Normal = lib.mkIf cfg.transparentBackground.main transparent;
NonText = lib.mkIf cfg.transparentBackground.main transparent;
SignColumn = lib.mkIf cfg.transparentBackground.signColumn transparent;
};
};
}
})
{
programs.nixvim = {
highlight = let
transparent = {
bg = "none";
ctermbg = "none";
};
in {
Normal = lib.mkIf cfg.transparentBackground.main transparent;
NonText = lib.mkIf cfg.transparentBackground.main transparent;
SignColumn = lib.mkIf cfg.transparentBackground.signColumn transparent;
};
};
}
])
);
}