Skip to content

Commit

Permalink
nixvim: expose config for nixvim's standalone mode (#415)
Browse files Browse the repository at this point in the history
Link: #415

Reviewed-by: NAHO <[email protected]>
Tested-by: NAHO <[email protected]>
  • Loading branch information
trueNAHO authored Feb 27, 2025
2 parents 2111394 + eab1ecf commit e7c09d2
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 80 deletions.
29 changes: 29 additions & 0 deletions docs/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,35 @@ to customize this.
> Similarly, [`stylix.override`](options/global/nixos.md#stylixoverride) is not inherited
> if the color scheme is different.
## Standalone Nixvim

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
];
}
```

[Nixvim]: https://nix-community.github.io/nixvim
[Nixvim Standalone]: https://nix-community.github.io/nixvim/user-guide/install.html#standalone-usage

## Turning targets on and off

A target is anything which can have colors, fonts or a wallpaper applied to it.
Expand Down
160 changes: 80 additions & 80 deletions modules/nixvim/nixvim.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,81 @@
}:
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;
};
in
{
options.stylix.targets.nixvim = {
enable = config.lib.stylix.mkEnableTarget "nixvim" true;
plugin = lib.mkOption {
type = lib.types.enum [
"base16-nvim"
"mini.base16"
];
type = lib.types.enum (builtins.attrNames pluginConfigs);
default = "mini.base16";
description = "Plugin used for the colorscheme";
};
Expand Down Expand Up @@ -63,80 +129,14 @@ in
})
];

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
;
};
};
})
(lib.mkIf (cfg.plugin == "mini.base16") {
programs.nixvim.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
;
};
};
})
{
programs.nixvim = {
highlightOverride =
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;
};
};
}
]
)
);
config = lib.mkMerge [
{
lib.stylix.nixvim.config = pluginConfigs.${cfg.plugin};
}
(lib.mkIf (config.stylix.enable && cfg.enable && options.programs ? nixvim) (
lib.optionalAttrs (options.programs ? nixvim) {
programs.nixvim = config.lib.stylix.nixvim.config;
}
))
];
}

0 comments on commit e7c09d2

Please sign in to comment.