From 5e7481b89874a5dc17fa644886f68afb75365743 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Thu, 8 Feb 2024 11:07:42 +0800 Subject: [PATCH] nixvim/plugins/lush-nvim: init --- modules/nixvim/default.nix | 1 + modules/nixvim/plugins/lush-nvim.nix | 104 +++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 modules/nixvim/plugins/lush-nvim.nix diff --git a/modules/nixvim/default.nix b/modules/nixvim/default.nix index 73f90821..0ab3bb2b 100644 --- a/modules/nixvim/default.nix +++ b/modules/nixvim/default.nix @@ -2,6 +2,7 @@ imports = [ ./keyunmaps.nix ./plugins/firenvim.nix + ./plugins/lush-nvim.nix ./plugins/nvim-config-local.nix ]; } diff --git a/modules/nixvim/plugins/lush-nvim.nix b/modules/nixvim/plugins/lush-nvim.nix new file mode 100644 index 00000000..cedea3c4 --- /dev/null +++ b/modules/nixvim/plugins/lush-nvim.nix @@ -0,0 +1,104 @@ +{ config, lib, pkgs, helpers, ... }: + +let + cfg = config.colorschemes.lush; + + schemeType = { config, lib, ... }: { + options = { + lushInit = lib.mkOption { + type = lib.types.lines; + default = ""; + description = '' + Theme-specific Lua code to be included for the colorscheme plugin. This + is mainly useful for organizing the palette in your preferred way. + ''; + }; + + highlights = lib.mkOption { + type = with lib.types; attrsOf anything; + default = { }; + description = '' + The highlight group object to be exported with Lush. This is the data + to be exported with `lush()` function from lush.nvim. + ''; + }; + }; + }; + + mkLushColorSchemes = name: theme: + let + # Converts each of the highlight group into a function to be able parsed and + # used by Lush. + highlightList = + lib.mapAttrsToList + (highlight: arguments: "${highlight}(${helpers.toLuaObject arguments})") + theme.highlights; + in + # This is based from rktjmp/lush-template. We'll improve on things from + # here whenever necessary. + lib.nameValuePair "colors/${name}.lua" '' + ${cfg.lushInit} + ${theme.lushInit} + + local theme = lush( + function(injected_functions) + local sym = injected_functions.sym + return { ${lib.concatStringsSep "," highlightList} } + end + ) + + return theme + ''; +in +{ + options.colorschemes.lush = { + enable = lib.mkEnableOption "theming with lush.nvim"; + + package = helpers.mkPackageOption "lush.nvim" pkgs.vimPlugins.lush-nvim; + + lushInit = lib.mkOption { + type = lib.types.lines; + default = '' + local lush = require('lush') + ''; + example = '' + local lush = require('lush') + local hsl = lush.hsl + local hsluv = lush.hsluv + ''; + description = '' + Additional Lua code to be prepended before the Lush theme export. + ''; + }; + + themes = lib.mkOption { + type = with lib.types; attrsOf (submodule schemeType); + description = '' + A set of Lush-created themes. Each of these themes is to be exported as + a colorscheme plugin to NixVim usable with + {option}`colorscheme`. + + It can serve as an alternative to {option}`colorschemes.base16` or the + colorscheme plugins if you want a framework for creating more + expressive colorschemes. + ''; + default = { }; + example = { + "example-theme".highlights = { + Normal = { + fg.__raw = "hsluv('#300000')"; + bg.__raw = "hsluv('#600000')"; + }; + CursorLine.bg.__raw = "Normal.bg.lighten(5)"; + }; + }; + }; + }; + + config = lib.mkIf cfg.enable { + extraPlugins = [ cfg.package ]; + + extraFiles = + lib.mapAttrs' mkLushColorSchemes cfg.themes; + }; +}