nixeovim/modules/build/neovim.nix

75 lines
1.9 KiB
Nix

{ config, lib, pkgs, nix2lua, ... }:
let
inherit (builtins) filter attrValues;
cfg = config.build.neovim;
in
{
options.build.neovim = with lib; with types; {
luaConfig = mkOption {
type = lines;
readOnly = true;
internal = true;
description = ''
Neovim editor lua configuration.
'';
};
plugins = mkOption {
type = listOf package;
readOnly = true;
internal = true;
};
package = mkOption {
type = types.package;
readOnly = true;
internal = true;
description = ''
Neovim editor derivation with plugins and configurations.
'';
};
};
config.build.neovim = {
luaConfig = with nix2lua; toLua (spaceBetween (lib.flatten [
# Global Opts
(lib.flip lib.mapAttrsToList config.vim.g (k: set "vim.g.${k}"))
# Opts
(lib.flip lib.mapAttrsToList config.vim.opt (k: set "vim.opt.${k}"))
# Plugins
(map (v: v.genConfig) (filter (v: !v.isDependency) (attrValues config.plugin)))
# Cmd
(lib.optional (config.vim.cmd != "") (call "vim.cmd" config.vim.cmd))
# Keymaps
(lib.flip map config.vim.keymap.set ({ mode, lhs, rhs, ... } @ vars:
let
buf = lib.optionalString (vars.buffer != null) vars.buffer;
m = if builtins.isList mode then lib.head mode else mode;
in
if config.vim.keymap._validate."${buf}"."${m}"."${lhs}" == rhs then vars.genConfig
else abort "This case should never happen."
))
]));
plugins = lib.mapAttrsToList (k: v: v.package) config.plugin;
package = pkgs.wrapNeovim pkgs.neovim-unwrapped {
viAlias = false;
vimAlias = false;
withPython3 = false;
withNodeJs = false;
withRuby = false;
configure = {
customRC = ''
lua << EOF
${cfg.luaConfig}
EOF
'';
packages.myVimPackages = { start = cfg.plugins; };
};
};
};
}