Skip to content

Commit

Permalink
nixvim: expose config as read-only option
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MattSturgeon committed Jun 5, 2024
1 parent 85a0a92 commit b7bde26
Showing 1 changed file with 65 additions and 38 deletions.
103 changes: 65 additions & 38 deletions modules/nixvim/nixvim.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,75 @@
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.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 = {
programs = lib.mkIf ((config.programs ? nixvim) && config.stylix.targets.nixvim.enable) (
lib.optionalAttrs (builtins.hasAttr "nixvim" options.programs) {
nixvim = config.stylix.targets.nixvim.config;
}
);
stylix.targets.nixvim.config = {
colorschemes.base16 = {
enable = true;

highlight = let
cfg = config.stylix.targets.nixvim;
transparent = {
bg = "none";
ctermbg = "none";
};
colorscheme = let
colors = config.lib.stylix.colors.withHashtag;
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;
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;
};
}
);
};
};
}

0 comments on commit b7bde26

Please sign in to comment.