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.lib.stylix.nixvim.config`.

This can be passed to the nixvim derivation's `extend` function or used
directly in a nixvim configuration.
  • Loading branch information
MattSturgeon committed Jan 23, 2025
1 parent 617d1c0 commit 81100bf
Showing 1 changed file with 95 additions and 69 deletions.
164 changes: 95 additions & 69 deletions modules/nixvim/nixvim.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@ in
};
};

options.lib.stylix.nixvim.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).
'';
};

imports = [
(lib.mkRenamedOptionModuleWith {
from = [
Expand Down Expand Up @@ -65,78 +90,79 @@ in

config = {
programs = lib.mkIf (config.stylix.enable && cfg.enable) (
lib.optionalAttrs (options.programs ? nixvim) (
lib.mkMerge [
(lib.mkIf (cfg.plugin == "base16-nvim") {
nixvim.colorschemes.base16 = {
enable = true;
lib.optionalAttrs (options.programs ? nixvim) {
nixvim = config.lib.stylix.nixvim.config;
}
);
lib.stylix.nixvim.config = lib.mkMerge [
(lib.mkIf (cfg.plugin == "base16-nvim") {
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") {
nixvim.plugins.mini = {
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") {
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
;
};
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
{
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;
};
};
}
]
)
);
Normal = lib.mkIf cfg.transparentBackground.main transparent;
NonText = lib.mkIf cfg.transparentBackground.main transparent;
SignColumn = lib.mkIf cfg.transparentBackground.signColumn transparent;
};
};
}
];
};
}

0 comments on commit 81100bf

Please sign in to comment.