diff --git a/module-list.nix b/module-list.nix index 0236701..a5b2c72 100644 --- a/module-list.nix +++ b/module-list.nix @@ -12,6 +12,7 @@ ./modules/plugin.nix ./modules/fn.nix + ./modules/plugins/interface/colorizer.nix ./modules/plugins/interface/lualine.nix ./modules/plugins/language-server/lspconfig.nix ./modules/plugins/navigation/hop-nvim.nix diff --git a/modules/plugin.nix b/modules/plugin.nix index 4796c23..e53ce31 100644 --- a/modules/plugin.nix +++ b/modules/plugin.nix @@ -32,7 +32,7 @@ let default = "setup"; }; setupSettings = mkOption { - type = nullOr attrs; + type = nullOr (either attrs (listOf anything)); default = null; }; afterSetup = mkOption { diff --git a/modules/plugins/interface/colorizer.nix b/modules/plugins/interface/colorizer.nix new file mode 100644 index 0000000..3a66c61 --- /dev/null +++ b/modules/plugins/interface/colorizer.nix @@ -0,0 +1,84 @@ +{ 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 + ]; + }; + }; +} diff --git a/modules/profiles/recommended-plugins.nix b/modules/profiles/recommended-plugins.nix index a09af47..226db7c 100644 --- a/modules/profiles/recommended-plugins.nix +++ b/modules/profiles/recommended-plugins.nix @@ -5,18 +5,37 @@ let inherit (lib.nix2lua) nf; in plugin.editorconfig-nvim.isDependency = lib.mkDefault true; plugins = { - interface.lualine = { - enable = lib.mkDefault true; - settings = lib.mkDefault { - sections = { - lualine_a = [ - [ "filename" (nf "path" 1) ] - ]; - lualine_b = [ "branch" "diff" "diagnostics" ]; - lualine_c = [ "lsp_progress" ]; - lualine_x = [ "filesize" "filetype" ]; - lualine_y = [ "progress" ]; - lualine_z = [ "location" "mode" ]; + interface = { + colorizer = { + enable = lib.mkDefault true; + + filetypes = lib.mkDefault [ "*" ]; + + settings = { + byFiletype = lib.mkDefault { + css = { css = true; }; + scss = { css = true; }; + sass = { css = true; }; + less = { css = true; }; + }; + overrideDefaults = lib.mkDefault { + names = false; + }; + }; + }; + lualine = { + enable = lib.mkDefault true; + settings = lib.mkDefault { + sections = { + lualine_a = [ + [ "filename" (nf "path" 1) ] + ]; + lualine_b = [ "branch" "diff" "diagnostics" ]; + lualine_c = [ "lsp_progress" ]; + lualine_x = [ "filesize" "filetype" ]; + lualine_y = [ "progress" ]; + lualine_z = [ "location" "mode" ]; + }; }; }; };