{ config, lib, pkgs, ... }: let inherit (builtins) attrNames hasAttr; inherit (lib.nix2lua) nf; cfg = config.plugins.interface.colorizer; pkgs'.nvim-colorizer-lua = pkgs.vimUtils.buildVimPlugin { name = "nvim-colorizer-lua"; version = "2020-06-11"; src = pkgs.fetchFromGitHub { owner = "norcalli"; repo = "nvim-colorizer.lua"; rev = "36c610a9717cc9ec426a07c8e6bf3b3abcb139d6"; hash = "sha256-6YrnItxExL2C8pNIdLd+hXCjsB2MbZANwWkah6dreD8="; }; }; allFiletypes = lib.unique (cfg.filetypes ++ (attrNames cfg.settings.byFiletype)); allFiletypesWithSettings = map (ft: if ft != "*" && !(lib.hasPrefix "!" ft) && hasAttr ft cfg.settings.byFiletype then nf ft cfg.settings.byFiletype.${ft} else ft ) allFiletypes; in { options.plugins.interface.colorizer = with lib; { enable = mkEnableOption "nvim-colorizer-lua"; package = mkPackageOption pkgs' "nvim-colorizer-lua" { }; filetypes = mkOption { type = with types; listOf str; default = [ ]; example = [ "*" "!vim" ]; description = '' See: https://github.com/norcalli/nvim-colorizer.lua?tab=readme-ov-file#customization ''; }; settings = { byFiletype = mkOption { type = with types; attrsOf attrs; default = { }; example = { css = { rgb_fn = true; }; html = { names = false; }; }; description = '' See: https://github.com/norcalli/nvim-colorizer.lua?tab=readme-ov-file#customization ''; }; overrideDefaults = mkOption { type = types.attrs; default = { }; example = { mode = "foreground"; }; description = '' See: https://github.com/norcalli/nvim-colorizer.lua?tab=readme-ov-file#customization ''; }; }; }; config = lib.mkIf cfg.enable { # Plugin is required to enable 24-bit color vim.opt.termguicolors = true; plugin.nvim-colorizer-lua = { name = "colorizer"; package = cfg.package; setupSettings = [ (if allFiletypesWithSettings == [ ] then [ "*" ] else allFiletypesWithSettings) cfg.settings.overrideDefaults ]; }; }; }