neovim: combine Neovim, Neovide, NixVim, nvf, and Vim (#1377)

Closes: https://github.com/nix-community/stylix/issues/1189
Link: https://github.com/nix-community/stylix/pull/1377

Reviewed-by: Adam M. Szalkowski <a.szalkowski@datahow.ch>
Tested-by: Adam M. Szalkowski <a.szalkowski@datahow.ch>
Reviewed-by: Matt Sturgeon <matt@sturgeon.me.uk>
Tested-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
This commit is contained in:
Flameopathic 2025-06-12 17:28:51 +02:00 committed by GitHub
parent e9eb2308ff
commit 1a471ee95e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 184 additions and 216 deletions

View file

@ -29,3 +29,6 @@ enable = true
[output.html.redirect]
"/options/hm.html" = "./platforms/home_manager.html"
"/options/nixos.html" = "./platforms/nixos.html"
"/options/modules/nixvim.html" = "./neovim.html"
"/options/modules/nvf.html" = "./neovim.html"
"/options/modules/vim.html" = "./neovim.html"

View file

@ -3,7 +3,7 @@
// NOTE: This script doesn't run on 404.html, so the old page must still exist.
const redirects = {
"/configuration.html#standalone-nixvim":
"./options/modules/nixvim.html#standalone-mode",
"./options/modules/neovim.html#standalone-mode",
};
const fullPath = window.location.pathname + window.location.hash;

View file

@ -1,6 +0,0 @@
{ lib, ... }:
{
name = "Neovide";
homepage = "https://neovide.dev/";
maintainers = [ lib.maintainers.mightyiam ];
}

View file

@ -0,0 +1,6 @@
{
imports = [
./nvf.nix
./nixvim.nix
];
}

View file

@ -1,81 +1,10 @@
{ mkTarget, lib, ... }:
{
pkgs,
config,
lib,
...
}:
{
options.stylix.targets.neovim = {
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";
numberLine = lib.mkEnableOption "background transparency for the NeoVim number/relativenumber column";
};
};
config =
lib.mkIf (config.stylix.enable && config.stylix.targets.neovim.enable)
{
programs.neovim =
let
cfg = config.stylix.targets.neovim;
transparencyCfg = builtins.toString (
lib.optional cfg.transparentBackground.main ''
vim.cmd.highlight({ "Normal", "guibg=NONE", "ctermbg=NONE" })
vim.cmd.highlight({ "NonText", "guibg=NONE", "ctermbg=NONE" })
''
++ lib.optional cfg.transparentBackground.signColumn ''
vim.cmd.highlight({ "SignColumn", "guibg=NONE", "ctermbg=NONE" })
''
++ lib.optional cfg.transparentBackground.numberLine ''
vim.cmd.highlight({ "LineNr", "guibg=NONE", "ctermbg=NONE" })
vim.cmd.highlight({ "LineNrAbove", "guibg=NONE", "ctermbg=NONE" })
vim.cmd.highlight({ "LineNrBelow", "guibg=NONE", "ctermbg=NONE" })
''
);
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}
'';
})
];
};
};
imports = [
./neovim.nix
(lib.modules.importApply ./neovide.nix mkTarget)
./nixvim.nix
./nvf.nix
(lib.modules.importApply ./vim.nix mkTarget)
];
}

View file

@ -1,20 +1,87 @@
{ lib, ... }:
{
name = "Neovim";
homepage = "https://www.neovim.io/";
maintainers = [ ];
name = "Neovim, Neovide, NixVim, nvf, and Vim";
homepage = {
Neovim = "https://www.neovim.io/";
Neovide = "https://neovide.dev/";
NixVim = "https://github.com/nix-community/nixvim";
nvf = "https://github.com/NotAShelf/nvf";
Vim = "http://www.vim.org/";
};
maintainers = with lib.maintainers; [
butzist
mightyiam
naho
];
description = ''
This module themes [Neovim] using the standard Home Manager options.
### Neovim
### Related modules
This target themes [Neovim] using the standard Home Manager options.
<!-- If updating this section, make sure to update it on the linked pages too. -->
### NixVim
- [Vim](vim.md): themes Vim using the standard Home Manager options.
- [Nixvim](nixvim.md): themes Neovim using the options provided by [Nixvim].
- [nvf](nvf.md): themes Neovim using the options provided by [nvf].
This target themes [Neovim] using the options provided by [NixVim].
> [!IMPORTANT]
> This target will have no effect unless the desired Nixvim module is properly
> [installed](https://github.com/nix-community/nixvim?tab=readme-ov-file#installation)
> and
> [imported](https://github.com/nix-community/nixvim?tab=readme-ov-file#usage)
> into your configuration.
>
> Ensure you are configuring this target on the same platform (NixOS, Home
> Manager, Darwin) as where you installed Nixvim.
#### Standalone Mode
When using a NixOS or home-manager installation of [NixVim], you can use Stylix
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
can use this as a module in your standalone Nixvim Configuration or an
extension of it.
For example:
```nix
{
inputs,
config,
pkgs,
...
}:
let
inherit (pkgs.stdenv.hostPlatform) system;
nixvim-package = inputs.nixvim-config.packages.''${system}.default;
extended-nixvim = nixvim-package.extend config.lib.stylix.nixvim.config;
in
{
environment.systemPackages = [ extended-nixvim ];
}
```
### nvf
This target themes [Neovim] using the options provided by [nvf].
> [!IMPORTANT]
> This target will have no effect unless the desired nvf module is properly
> [installed](https://notashelf.github.io/nvf/index.xhtml#ch-installation)
> and
> [imported](https://notashelf.github.io/nvf/index.xhtml#ch-module-installation)
> into your configuration.
>
> Ensure you are configuring this target on the same platform (NixOS, Home
> Manager, Darwin) as where you installed nvf.
### Vim
This target themes [Vim] using the standard Home Manager options.
[Neovim]: https://neovim.io
[Nixvim]: https://github.com/nix-community/nixvim#readme
[nvf]: https://github.com/NotAShelf/nvf#readme
[Vim]: https://www.vim.org
'';
}

View file

@ -1,4 +1,4 @@
{ mkTarget, ... }:
mkTarget:
mkTarget {
name = "neovide";
humanName = "Neovide";

81
modules/neovim/neovim.nix Normal file
View file

@ -0,0 +1,81 @@
{
config,
lib,
pkgs,
...
}:
{
options.stylix.targets.neovim = {
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";
numberLine = lib.mkEnableOption "background transparency for the NeoVim number/relativenumber column";
};
};
config =
lib.mkIf (config.stylix.enable && config.stylix.targets.neovim.enable)
{
programs.neovim =
let
cfg = config.stylix.targets.neovim;
transparencyCfg = builtins.toString (
lib.optional cfg.transparentBackground.main ''
vim.cmd.highlight({ "Normal", "guibg=NONE", "ctermbg=NONE" })
vim.cmd.highlight({ "NonText", "guibg=NONE", "ctermbg=NONE" })
''
++ lib.optional cfg.transparentBackground.signColumn ''
vim.cmd.highlight({ "SignColumn", "guibg=NONE", "ctermbg=NONE" })
''
++ lib.optional cfg.transparentBackground.numberLine ''
vim.cmd.highlight({ "LineNr", "guibg=NONE", "ctermbg=NONE" })
vim.cmd.highlight({ "LineNrAbove", "guibg=NONE", "ctermbg=NONE" })
vim.cmd.highlight({ "LineNrBelow", "guibg=NONE", "ctermbg=NONE" })
''
);
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}
'';
})
];
};
};
}

6
modules/neovim/nixos.nix Normal file
View file

@ -0,0 +1,6 @@
{
imports = [
./nvf.nix
./nixvim.nix
];
}

View file

@ -137,7 +137,7 @@ in
{
lib.stylix.nixvim.config = {
imports = [
(lib.modules.importApply ../neovide/nixvim.nix config.stylix)
(lib.modules.importApply ./neovide-common.nix config.stylix)
];
config = lib.mkMerge [
pluginConfigs.${cfg.plugin}

View file

@ -1,5 +1,5 @@
mkTarget:
{
mkTarget,
lib,
pkgs,
...

View file

@ -1 +0,0 @@
import ./nixvim.nix

View file

@ -1 +0,0 @@
import ./nixvim.nix

View file

@ -1,61 +0,0 @@
{ lib, ... }:
{
name = "NixVim";
homepage = "https://github.com/nix-community/nixvim";
maintainers = [ lib.maintainers.naho ];
description = ''
This module themes [Neovim] using the options provided by [NixVim].
> [!IMPORTANT]
> This module will have no effect unless the desired Nixvim module is properly
> [installed](https://github.com/nix-community/nixvim?tab=readme-ov-file#installation)
> and
> [imported](https://github.com/nix-community/nixvim?tab=readme-ov-file#usage)
> into your configuration.
>
> Ensure you are configuring this module on the same platform (NixOS, Home
> Manager, Darwin) as where you installed Nixvim.
### Standalone Mode
When using a NixOS or home-manager installation of [NixVim], you can use Stylix
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
can use this as a module in your standalone Nixvim Configuration or an
extension of it.
For example:
```nix
{
inputs,
config,
pkgs,
...
}:
let
inherit (pkgs.stdenv.hostPlatform) system;
nixvim-package = inputs.nixvim-config.packages.''${system}.default;
extended-nixvim = nixvim-package.extend config.lib.stylix.nixvim.config;
in
{
environment.systemPackages = [ extended-nixvim ];
}
```
### Related modules
<!-- If updating this section, make sure to update it on the linked pages too. -->
- [Vim](vim.md): themes Vim using the standard Home Manager options.
- [Neovim](neovim.md): themes Neovim using the standard Home Manager options.
- [nvf](nvf.md): themes Neovim using the options provided by [nvf].
[Neovim]: https://neovim.io
[NixVim]: https://github.com/nix-community/nixvim#readme
[NixVim Standalone]: https://nix-community.github.io/nixvim/user-guide/install.html#standalone-usage
[nvf]: https://github.com/NotAShelf/nvf#readme
'';
}

View file

@ -1 +0,0 @@
import ./nixvim.nix

View file

@ -1 +0,0 @@
import ./nvf.nix

View file

@ -1 +0,0 @@
import ./nvf.nix

View file

@ -1,31 +0,0 @@
{ lib, ... }:
{
name = "nvf";
homepage = "https://github.com/NotAShelf/nvf";
maintainers = [ lib.maintainers.butzist ];
description = ''
This module themes [Neovim] using the options provided by [nvf].
> [!IMPORTANT]
> This module will have no effect unless the desired nvf module is properly
> [installed](https://notashelf.github.io/nvf/index.xhtml#ch-installation)
> and
> [imported](https://notashelf.github.io/nvf/index.xhtml#ch-module-installation)
> into your configuration.
>
> Ensure you are configuring this module on the same platform (NixOS, Home
> Manager, Darwin) as where you installed nvf.
### Related modules
<!-- If updating this section, make sure to update it on the linked pages too. -->
- [Vim](vim.md): themes Vim using the standard Home Manager options.
- [Neovim](neovim.md): themes Neovim using the standard Home Manager options.
- [Nixvim](nixvim.md): themes Neovim using the options provided by [Nixvim].
[Neovim]: https://neovim.io
[Nixvim]: https://github.com/nix-community/nixvim#readme
[nvf]: https://github.com/NotAShelf/nvf#readme
'';
}

View file

@ -1 +0,0 @@
import ./nvf.nix

View file

@ -1,20 +0,0 @@
{
name = "Vim";
homepage = "http://www.vim.org/";
maintainers = [ ];
description = ''
This module themes [Vim] using the standard Home Manager options.
### Related modules
<!-- If updating this section, make sure to update it on the linked pages too. -->
- [Neovim](neovim.md): themes Neovim using the standard Home Manager options.
- [Nixvim](nixvim.md): themes Neovim using the options provided by [Nixvim].
- [nvf](nvf.md): themes Neovim using the options provided by [nvf].
[Vim]: https://www.vim.org
[Nixvim]: https://github.com/nix-community/nixvim#readme
[nvf]: https://github.com/NotAShelf/nvf#readme
'';
}