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
|
|
|
|
{
|
2024-05-05 17:53:47 +03:00
|
|
|
imports = [
|
|
|
|
(lib.mkRenamedOptionModule [ "build" "neovim" "package" ] [ "build" "neovim" "toplevel" ])
|
|
|
|
];
|
|
|
|
|
2024-04-26 02:08:23 +03:00
|
|
|
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;
|
|
|
|
};
|
2024-05-05 17:53:47 +03:00
|
|
|
toplevel = mkOption {
|
2024-04-26 02:08:23 +03:00
|
|
|
type = types.package;
|
|
|
|
internal = true;
|
|
|
|
description = ''
|
|
|
|
Neovim editor derivation with plugins and configurations.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config.build.neovim = {
|
2024-05-09 02:28:24 +03:00
|
|
|
luaConfig = with lib; with nix2lua; toLua (spaceBetween (flatten [
|
2024-04-26 02:08:23 +03:00
|
|
|
# Global Opts
|
2024-05-09 02:28:24 +03:00
|
|
|
(flip mapAttrsToList config.vim.g (k: set "vim.g.${k}"))
|
2024-04-26 02:08:23 +03:00
|
|
|
# Opts
|
2024-05-20 14:25:39 +03:00
|
|
|
(flip mapAttrsToList config.vim.opt (k: set "vim.opt.${k}"))
|
2024-04-26 02:08:23 +03:00
|
|
|
# Plugins
|
2024-05-10 01:31:47 +03:00
|
|
|
(map (v: v.genConfig) (filter (v: v.enable) (attrValues config.plugin)))
|
2024-04-26 02:08:23 +03:00
|
|
|
# Cmd
|
2024-05-09 02:28:24 +03:00
|
|
|
(optional (config.vim.cmd != "") (call "vim.cmd" config.vim.cmd))
|
2024-05-03 17:50:57 +03:00
|
|
|
# Autocommands
|
2024-05-09 02:28:24 +03:00
|
|
|
(flip mapAttrsToList config.vim.augroup (k: v: v.genConfig))
|
2024-04-26 10:35:27 +03:00
|
|
|
# Keymaps
|
2024-05-09 02:28:24 +03:00
|
|
|
(flip map config.vim.keymap.set ({ mode, lhs, rhs, ... } @ vars:
|
|
|
|
let m = if builtins.isList mode then head mode else mode; in
|
2024-05-01 14:56:36 +03:00
|
|
|
if config.vim.keymap._validate."${m}"."${lhs}" == rhs then vars.genConfig
|
2024-04-29 15:47:56 +03:00
|
|
|
else abort "This case should never happen."
|
2024-04-26 10:35:27 +03:00
|
|
|
))
|
2024-04-26 02:08:23 +03:00
|
|
|
]));
|
|
|
|
|
2024-05-10 01:31:47 +03:00
|
|
|
plugins = map (v: v.package) (filter (v: v.enable) (attrValues config.plugin));
|
2024-04-26 02:08:23 +03:00
|
|
|
|
2024-05-05 17:53:47 +03:00
|
|
|
toplevel = pkgs.wrapNeovim pkgs.neovim-unwrapped {
|
2024-04-26 02:08:23 +03:00
|
|
|
viAlias = false;
|
|
|
|
vimAlias = false;
|
|
|
|
|
|
|
|
withPython3 = false;
|
|
|
|
withNodeJs = false;
|
|
|
|
withRuby = false;
|
|
|
|
|
|
|
|
configure = {
|
|
|
|
customRC = ''
|
|
|
|
lua << EOF
|
|
|
|
${cfg.luaConfig}
|
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
|
|
|
|
packages.myVimPackages = { start = cfg.plugins; };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|