From e5c11e9cd09c3a1cb542fc3bfda7d6d9e90cee94 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 Checking `config.programs ? nixvim` **and** `options.programs ? nixvim` is redundant; the `mkIf` check had no benefit. This now matches the pattern used elsewhere. --- modules/nixvim/nixvim.nix | 74 +++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/modules/nixvim/nixvim.nix b/modules/nixvim/nixvim.nix index 5366c44c..b6555e0f 100644 --- a/modules/nixvim/nixvim.nix +++ b/modules/nixvim/nixvim.nix @@ -13,46 +13,44 @@ }; }; - config = lib.mkIf ((config.programs ? nixvim) && config.stylix.targets.nixvim.enable) ( - lib.optionalAttrs (builtins.hasAttr "nixvim" options.programs) { - programs.nixvim = { - colorschemes.base16 = { - colorscheme = let - colors = config.lib.stylix.colors.withHashtag; - in { - base00 = colors.base00; - base01 = colors.base01; - base02 = colors.base02; - base03 = colors.base03; - base04 = colors.base04; - base05 = colors.base05; - base06 = colors.base06; - base07 = colors.base07; - base08 = colors.base08; - base09 = colors.base09; - base0A = colors.base0A; - base0B = colors.base0B; - base0C = colors.base0C; - base0D = colors.base0D; - base0E = colors.base0E; - base0F = colors.base0F; - }; - - enable = true; + config = lib.optionalAttrs (options.programs ? nixvim) (lib.mkIf config.stylix.targets.nixvim.enable { + programs.nixvim = { + colorschemes.base16 = { + colorscheme = let + colors = config.lib.stylix.colors.withHashtag; + in { + base00 = colors.base00; + base01 = colors.base01; + base02 = colors.base02; + base03 = colors.base03; + base04 = colors.base04; + base05 = colors.base05; + base06 = colors.base06; + base07 = colors.base07; + base08 = colors.base08; + base09 = colors.base09; + base0A = colors.base0A; + base0B = colors.base0B; + base0C = colors.base0C; + base0D = colors.base0D; + base0E = colors.base0E; + base0F = colors.base0F; }; - highlight = let - cfg = config.stylix.targets.nixvim; - transparent = { - bg = "none"; - ctermbg = "none"; - }; - in { - Normal = lib.mkIf cfg.transparent_bg.main transparent; - NonText = lib.mkIf cfg.transparent_bg.main transparent; - SignColumn = lib.mkIf cfg.transparent_bg.sign_column transparent; + enable = true; + }; + + highlight = let + cfg = config.stylix.targets.nixvim; + transparent = { + bg = "none"; + ctermbg = "none"; }; + in { + Normal = lib.mkIf cfg.transparent_bg.main transparent; + NonText = lib.mkIf cfg.transparent_bg.main transparent; + SignColumn = lib.mkIf cfg.transparent_bg.sign_column transparent; }; - } - ); + }; + }); } From 71c7df9b8d070a3f8b6e304e7e60718d191b12de 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.stylix.targets.nixvim.config`. This can be passed to the nixvim derivation's `extendNixvim` function. --- modules/nixvim/nixvim.nix | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/modules/nixvim/nixvim.nix b/modules/nixvim/nixvim.nix index b6555e0f..54c63538 100644 --- a/modules/nixvim/nixvim.nix +++ b/modules/nixvim/nixvim.nix @@ -11,11 +11,41 @@ main = lib.mkEnableOption "background transparency for the main NeoVim window"; sign_column = lib.mkEnableOption "background transparency for the NeoVim sign column"; }; + config = lib.mkOption { + type = with lib.types; attrsOf anything; + readOnly = true; + + description = '' + The stylix configuration, generated for nixvim. + + If nixvim is installed via nixos, darwin, or home-manager then this will be **automatically** + assigned to `programs.nixvim`. If you're using a "standalone" build of nixvim, then that's + not possible. Instead, you should pass this config to the `nixvimExtend` function. + + For example: + + ```nix + { config, ... }: { + environment.systemPackages = [ + (standalone-nixvim-derivation.nixvimExtend config.stylix.targets.nixvim.config) + ]; + } + ``` + + See nixvim's docs on [extending a standalone configuration](https://nix-community.github.io/nixvim/modules/standalone.html#extending-an-existing-configuration). + ''; + }; }; - config = lib.optionalAttrs (options.programs ? nixvim) (lib.mkIf config.stylix.targets.nixvim.enable { - programs.nixvim = { + config = { + programs = lib.optionalAttrs (options.programs ? nixvim) (lib.mkIf config.stylix.targets.nixvim.enable { + nixvim = config.stylix.targets.nixvim.config; + }); + + stylix.targets.nixvim.config = { colorschemes.base16 = { + enable = true; + colorscheme = let colors = config.lib.stylix.colors.withHashtag; in { @@ -36,8 +66,6 @@ base0E = colors.base0E; base0F = colors.base0F; }; - - enable = true; }; highlight = let @@ -52,5 +80,5 @@ SignColumn = lib.mkIf cfg.transparent_bg.sign_column transparent; }; }; - }); + }; } From 2950c7af3083d4adc5ee5c3321c7edc2fe00690f Mon Sep 17 00:00:00 2001 From: NAHO <90870942+trueNAHO@users.noreply.github.com> Date: Thu, 6 Jun 2024 19:32:13 +0200 Subject: [PATCH 3/3] nixvim: wrap code at 80 characters --- modules/nixvim/nixvim.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/nixvim/nixvim.nix b/modules/nixvim/nixvim.nix index 54c63538..1aa0b4e9 100644 --- a/modules/nixvim/nixvim.nix +++ b/modules/nixvim/nixvim.nix @@ -38,9 +38,12 @@ }; config = { - programs = lib.optionalAttrs (options.programs ? nixvim) (lib.mkIf config.stylix.targets.nixvim.enable { - nixvim = config.stylix.targets.nixvim.config; - }); + programs = + lib.optionalAttrs + (options.programs ? nixvim) + (lib.mkIf config.stylix.targets.nixvim.enable { + nixvim = config.stylix.targets.nixvim.config; + }); stylix.targets.nixvim.config = { colorschemes.base16 = {