nixeovim/modules/build/neovim.nix

77 lines
1.9 KiB
Nix
Raw Normal View History

2024-04-30 00:48:10 +03:00
{ config, lib, pkgs, ... }:
2024-04-26 02:08:23 +03:00
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 = {
2024-04-30 00:48:10 +03:00
luaConfig = with lib.nix2lua; toLua (spaceBetween (lib.flatten [
2024-04-26 02:08:23 +03:00
# 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))
2024-05-03 17:50:57 +03:00
# Autocommands
(lib.flip lib.mapAttrsToList config.vim.augroup (k: v: v.genConfig))
2024-04-26 10:35:27 +03:00
# Keymaps
(lib.flip map config.vim.keymap.set ({ mode, lhs, rhs, ... } @ vars:
let
m = if builtins.isList mode then lib.head mode else mode;
in
if config.vim.keymap._validate."${m}"."${lhs}" == rhs then vars.genConfig
else abort "This case should never happen."
2024-04-26 10:35:27 +03:00
))
2024-04-26 02:08:23 +03:00
]));
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; };
};
};
};
}