{neovim,nixvim,nvf}: use mkTarget (#1535)

Link: https://github.com/nix-community/stylix/pull/1535

Tested-by: Adam M. Szalkowski <a.szalkowski@datahow.ch>
Approved-by: Adam M. Szalkowski <a.szalkowski@datahow.ch>
Co-authored-by: Shahar "Dawn" Or <mightyiampresence@gmail.com>
Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
Tested-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
This commit is contained in:
Flameopathic 2025-09-24 02:25:45 -05:00 committed by GitHub
parent ef025b8de3
commit 799c811ac5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 251 additions and 194 deletions

View file

@ -1,6 +1,7 @@
{ mkTarget, lib, ... }:
{
imports = [
./nvf.nix
imports = map (module: lib.modules.importApply module mkTarget) [
./nixvim.nix
./nvf.nix
];
}

View file

@ -1,10 +1,10 @@
{ mkTarget, lib, ... }:
{
imports = [
imports = map (module: lib.modules.importApply module mkTarget) [
./neovim.nix
(lib.modules.importApply ./neovide.nix mkTarget)
./neovide.nix
./nixvim.nix
./nvf.nix
(lib.modules.importApply ./vim.nix mkTarget)
./vim.nix
];
}

View file

@ -38,7 +38,7 @@
as normal. However, when using Nixvim's ["standalone" configuration mode][NixVim Standalone],
you will need to pass Stylix's generated config to Nixvim yourself.
The generated config can be accessed as `config.lib.stylix.nixvim.config`. You
The generated config can be accessed as `config.stylix.targets.nixvim.exportedModule`. You
can use this as a module in your standalone Nixvim Configuration or an
extension of it.
@ -54,7 +54,7 @@
let
inherit (pkgs.stdenv.hostPlatform) system;
nixvim-package = inputs.nixvim-config.packages.''${system}.default;
extended-nixvim = nixvim-package.extend config.lib.stylix.nixvim.config;
extended-nixvim = nixvim-package.extend config.stylix.targets.nixvim.exportedModule;
in
{
environment.systemPackages = [ extended-nixvim ];

View file

@ -1,8 +1,8 @@
# imported from `modules/nixvim/nixvim.nix`
stylix: {
opacity: {
extraConfigLua = ''
if vim.g.neovide then
vim.g.neovide_normal_opacity = ${toString stylix.opacity.terminal}
vim.g.neovide_normal_opacity = ${toString opacity.terminal}
end
'';
}

View file

@ -1,12 +1,13 @@
mkTarget:
{
config,
lib,
pkgs,
...
}:
{
options.stylix.targets.neovim = {
enable = config.lib.stylix.mkEnableTarget "Neovim" true;
mkTarget {
name = "neovim";
humanName = "Neovim";
extraOptions = {
plugin = lib.mkOption {
type = lib.types.enum [
"base16-nvim"
@ -20,14 +21,47 @@
signColumn = lib.mkEnableOption "background transparency for the Neovim sign column";
numberLine = lib.mkEnableOption "background transparency for the NeoVim number/relativenumber column";
};
pluginColorConfig = lib.mkOption {
type = lib.types.lines;
default = "";
internal = true;
};
};
config =
lib.mkIf (config.stylix.enable && config.stylix.targets.neovim.enable)
configElements = [
(
{ colors, cfg }:
{
programs.neovim =
stylix.targets.neovim.pluginColorConfig =
with colors.withHashtag;
if cfg.plugin == "base16-nvim" then
''
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}'
})
''
else
''
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}'
}
})
'';
}
)
(
{ cfg }:
{
programs.neovim.plugins =
let
cfg = config.stylix.targets.neovim;
transparencyCfg = toString (
lib.optional cfg.transparentBackground.main ''
vim.cmd.highlight({ "Normal", "guibg=NONE", "ctermbg=NONE" })
@ -43,39 +77,21 @@
''
);
in
{
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}'
})
${transparencyCfg}
'';
})
(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}'
}
})
${transparencyCfg}
'';
})
];
};
};
[
{
plugin =
if cfg.plugin == "mini.base16" then
pkgs.vimPlugins.mini-nvim
else
pkgs.vimPlugins.base16-nvim;
type = "lua";
config = lib.concatLines [
cfg.pluginColorConfig
transparencyCfg
];
}
];
}
)
];
}

View file

@ -1,6 +1,7 @@
{ mkTarget, lib, ... }:
{
imports = [
./nvf.nix
imports = map (module: lib.modules.importApply module mkTarget) [
./nixvim.nix
./nvf.nix
];
}

View file

@ -1,89 +1,19 @@
mkTarget:
{
config,
lib,
options,
config,
...
}:
let
cfg = config.stylix.targets.nixvim;
# Maps `stylix.targets.plugin` values to the appropriate nixvim configuration
pluginConfigs = {
"base16-nvim" = {
inherit highlightOverride;
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
;
};
};
};
"mini.base16" = {
inherit highlightOverride;
plugins.mini = {
enable = true;
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
;
};
};
};
};
# Transparent is used a few times below
transparent = {
bg = "none";
ctermbg = "none";
};
highlightOverride = {
Normal = lib.mkIf cfg.transparentBackground.main transparent;
NonText = lib.mkIf cfg.transparentBackground.main transparent;
SignColumn = lib.mkIf cfg.transparentBackground.signColumn transparent;
LineNr = lib.mkIf cfg.transparentBackground.numberLine transparent;
LineNrAbove = lib.mkIf cfg.transparentBackground.numberLine transparent;
LineNrBelow = lib.mkIf cfg.transparentBackground.numberLine transparent;
};
in
{
options.stylix.targets.nixvim = {
enable = config.lib.stylix.mkEnableTarget "nixvim" true;
mkTarget {
name = "nixvim";
humanName = "NixVim";
extraOptions = {
plugin = lib.mkOption {
type = lib.types.enum (builtins.attrNames pluginConfigs);
type = lib.types.enum [
"base16-nvim"
"mini.base16"
];
default = "mini.base16";
description = "Plugin used for the colorscheme";
};
@ -92,8 +22,127 @@ in
signColumn = lib.mkEnableOption "background transparency for the NeoVim sign column";
numberLine = lib.mkEnableOption "background transparency for the NeoVim number/relativenumber column";
};
module = lib.mkOption {
type = lib.types.deferredModule;
internal = true;
};
pluginConfigs = lib.mkOption {
type = lib.types.anything;
default = { };
internal = true;
};
exportedModule = lib.mkOption {
type = lib.types.deferredModule;
description = ''
Theming configuration which can be merged with your own. See
[Standalone Mode](#standalone-mode) documentation.
'';
readOnly = true;
};
};
configElements = [
(
{ colors }:
{
stylix.targets.nixvim.pluginConfigs = {
"base16-nvim".colorschemes.base16.colorscheme = {
inherit (colors.withHashtag)
base00
base01
base02
base03
base04
base05
base06
base07
base08
base09
base0A
base0B
base0C
base0D
base0E
base0F
;
};
"mini.base16".plugins.mini.modules.base16.palette = {
inherit (colors.withHashtag)
base00
base01
base02
base03
base04
base05
base06
base07
base08
base09
base0A
base0B
base0C
base0D
base0E
base0F
;
};
};
}
)
(
{ fonts }:
{
stylix.targets.nixvim.module.opts.guifont =
"${fonts.monospace.name}:h${toString fonts.sizes.terminal}";
}
)
(
{ opacity }:
{
stylix.targets.nixvim.module = lib.modules.importApply ./neovide-common.nix opacity;
}
)
(
{ cfg }:
{
stylix.targets.nixvim = {
pluginConfigs =
let
# Transparent is used a few times below
transparent = {
bg = "none";
ctermbg = "none";
};
highlightOverride = {
Normal = lib.mkIf cfg.transparentBackground.main transparent;
NonText = lib.mkIf cfg.transparentBackground.main transparent;
SignColumn = lib.mkIf cfg.transparentBackground.signColumn transparent;
LineNr = lib.mkIf cfg.transparentBackground.numberLine transparent;
LineNrAbove = lib.mkIf cfg.transparentBackground.numberLine transparent;
LineNrBelow = lib.mkIf cfg.transparentBackground.numberLine transparent;
};
in
{
"base16-nvim" = {
colorschemes.enable = true;
inherit highlightOverride;
};
"mini.base16" = {
plugins.mini.enable = true;
inherit highlightOverride;
};
};
module = cfg.pluginConfigs.${cfg.plugin};
exportedModule = cfg.module;
};
programs = lib.optionalAttrs (options.programs ? nixvim) {
nixvim = cfg.module;
};
}
)
];
imports = [
(lib.mkRenamedOptionModuleWith {
from = [
@ -131,26 +180,12 @@ in
"signColumn"
];
})
];
config = lib.mkMerge [
{
lib.stylix.nixvim.config = {
imports = [
(lib.modules.importApply ./neovide-common.nix config.stylix)
];
config = lib.mkMerge [
pluginConfigs.${cfg.plugin}
{
opts.guifont = "${config.stylix.fonts.monospace.name}:h${toString config.stylix.fonts.sizes.terminal}";
}
];
};
}
(lib.mkIf (config.stylix.enable && cfg.enable && options.programs ? nixvim) (
lib.optionalAttrs (options.programs ? nixvim) {
programs.nixvim = config.lib.stylix.nixvim.config;
(
{ config, ... }:
{
lib.stylix.nixvim.config = lib.warn "stylix: `config.lib.stylix.nixvim.config` has been renamed to `config.stylix.targets.nixvim.exportedModule` and will be removed after 26.11" config.stylix.targets.nixvim.exportedModule;
}
))
)
];
}

View file

@ -1,15 +1,13 @@
mkTarget:
{
config,
lib,
options,
...
}:
let
cfg = config.stylix.targets.nvf;
in
{
options.stylix.targets.nvf = {
enable = config.lib.stylix.mkEnableTarget "nvf" true;
mkTarget {
name = "nvf";
humanName = "nvf";
extraOptions = {
plugin = lib.mkOption {
type = lib.types.enum [
"base16"
@ -21,40 +19,46 @@ in
transparentBackground = lib.mkEnableOption "background transparency for the main Neovim window";
};
config =
lib.mkIf (config.stylix.enable && cfg.enable && options.programs ? nvf)
(
lib.optionalAttrs (options.programs ? nvf) {
programs.nvf.settings.vim = {
theme = {
enable = true;
name = cfg.plugin;
base16-colors = {
inherit (config.lib.stylix.colors.withHashtag)
base00
base01
base02
base03
base04
base05
base06
base07
base08
base09
base0A
base0B
base0C
base0D
base0E
base0F
;
};
transparent = cfg.transparentBackground;
};
statusline = lib.mkIf (cfg.plugin == "base16") {
lualine.theme = "base16";
configElements = lib.optionals (options.programs ? nvf) [
(
{ colors, cfg }:
{
programs.nvf.settings.vim = {
theme = {
enable = true;
name = cfg.plugin;
base16-colors = {
inherit (colors.withHashtag)
base00
base01
base02
base03
base04
base05
base06
base07
base08
base09
base0A
base0B
base0C
base0D
base0E
base0F
;
};
};
}
);
statusline = lib.mkIf (cfg.plugin == "base16") {
lualine.theme = "base16";
};
};
}
)
(
{ cfg }:
{
programs.nvf.settings.vim.theme.transparent = cfg.transparentBackground;
}
)
];
}