nvf/modules/plugins/theme/theme.nix

74 lines
1.9 KiB
Nix
Raw Normal View History

{
config,
lib,
...
}: let
inherit (lib.options) mkOption;
2024-10-07 15:47:08 +00:00
inherit (lib.attrsets) attrNames;
inherit (lib.strings) elemAt;
inherit (lib.types) bool lines enum;
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryBefore;
inherit (lib.nvim.lua) toLuaObject;
2024-10-07 20:24:04 +00:00
cfg = config.vim.theme;
supportedThemes = import ./supported-themes.nix {
inherit lib config;
};
in {
options.vim.theme = {
2024-10-07 20:24:04 +00:00
themes = supportedThemes;
inherit (supportedThemes.${cfg.name}) setupOpts;
enable = mkOption {
type = bool;
description = "Enable theming";
};
name = mkOption {
type = enum (attrNames supportedThemes);
description = ''
Supported themes can be found in {file}`supportedThemes.nix`.
Setting the theme to "base16" enables base16 theming and
requires all of the colors in {option}`vim.theme.base16-colors` to be set.
'';
};
style = mkOption {
type = enum supportedThemes.${cfg.name}.styles;
2024-10-07 08:47:17 +00:00
default = elemAt supportedThemes.${cfg.name}.styles 0;
description = "Specific style for theme if it supports it";
};
transparent = mkOption {
type = bool;
default = false;
description = "Whether or not transparency should be enabled. Has no effect for themes that do not support transparency";
};
extraConfig = mkOption {
type = lines;
description = "Additional lua configuration to add before setup";
};
};
config = mkIf cfg.enable {
vim = let
name' =
if cfg.name == "base16"
then "base16-colorscheme"
else cfg.name;
in {
startPlugins = [cfg.name];
luaConfigRC.theme = entryBefore ["pluginConfigs"] ''
${cfg.extraConfig}
2024-10-07 21:03:59 +00:00
${
if name' != "oxocarbon"
then "require('${name'}').setup(${toLuaObject cfg.setupOpts})"
else ""
}
${supportedThemes.${cfg.name}.setup}
2024-06-14 09:17:06 +00:00
'';
};
};
}