diff --git a/docs/src/configuration.md b/docs/src/configuration.md index 9f51a1cad..31300562f 100644 --- a/docs/src/configuration.md +++ b/docs/src/configuration.md @@ -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 diff --git a/modules/nixvim/nixvim.nix b/modules/nixvim/nixvim.nix index b87fb7c9e..a6264ad83 100644 --- a/modules/nixvim/nixvim.nix +++ b/modules/nixvim/nixvim.nix @@ -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"; }; @@ -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}; + }; }