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

nixvim: expose config for nixvim's standalone mode #415

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions docs/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,35 @@ to customize this.
> Similarly, [`stylix.override`](options/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

In Stylix terms, a target is anything which can have colors, fonts or a
Expand Down
158 changes: 78 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 highlight;

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 highlight;

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";
};
highlight = {
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,12 @@ 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 = {
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;
};
};
}
]
)
);
config = {
programs = lib.mkIf (config.stylix.enable && cfg.enable) (
lib.optionalAttrs (options.programs ? nixvim) {
nixvim = config.lib.stylix.nixvim.config;
}
);
lib.stylix.nixvim.config = pluginConfigs.${cfg.plugin};
};
}