From 6c361e9755d55df7c7eda10c5c40accdcf39da54 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 5 Jun 2024 03:14:55 +0100 Subject: [PATCH 1/3] nixvim: simplify enable conditions - Use `options.programs` over `config.programs` as it is slightly cheaper. - Prefer using the `?` operator over `builtins.hasAttr` --- modules/nixvim/nixvim.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/nixvim/nixvim.nix b/modules/nixvim/nixvim.nix index 4918c413..4c916a9f 100644 --- a/modules/nixvim/nixvim.nix +++ b/modules/nixvim/nixvim.nix @@ -64,9 +64,9 @@ in ]; config = - lib.mkIf (config.stylix.enable && cfg.enable && (config.programs ? nixvim)) + lib.mkIf (config.stylix.enable && cfg.enable && options.programs ? nixvim) ( - lib.optionalAttrs (builtins.hasAttr "nixvim" options.programs) ( + lib.optionalAttrs (options.programs ? nixvim) ( lib.mkMerge [ (lib.mkIf (cfg.plugin == "base16-nvim") { programs.nixvim.colorschemes.base16 = { From 0a4755b656c28043c52063384fc68bbb30913903 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 5 Jun 2024 03:10:32 +0100 Subject: [PATCH 2/3] nixvim: expose config as read-only option Allow standalone nixvim users to take advantage of stylix by exposing the generated config as `config.lib.stylix.nixvim.config`. This can be passed to the nixvim derivation's `extend` function or used directly in a nixvim configuration. --- modules/nixvim/nixvim.nix | 160 +++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/modules/nixvim/nixvim.nix b/modules/nixvim/nixvim.nix index 4c916a9f..16abd7ce 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 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"; }; @@ -63,80 +129,14 @@ in }) ]; - config = - lib.mkIf (config.stylix.enable && cfg.enable && options.programs ? nixvim) - ( - lib.optionalAttrs (options.programs ? nixvim) ( - 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; + } + )) + ]; } From eab1ecf41f2951e8655e7d66d19f21d5ab5fac4b Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 28 Jan 2025 20:22:14 +0000 Subject: [PATCH 3/3] docs: document configuring Standalone Nixvim --- docs/src/configuration.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/src/configuration.md b/docs/src/configuration.md index 7ce96f9e..b1a813e6 100644 --- a/docs/src/configuration.md +++ b/docs/src/configuration.md @@ -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.