2024-05-10 18:47:54 +03:00
|
|
|
{ lib, pkgs, ... }:
|
2024-04-30 16:54:48 +03:00
|
|
|
|
|
|
|
let
|
2024-05-09 02:28:24 +03:00
|
|
|
inherit (lib.nix2lua) lambda raw;
|
|
|
|
|
2024-04-30 16:54:48 +03:00
|
|
|
fnOpts = { name, config, ... }: {
|
|
|
|
options = with lib; {
|
|
|
|
args = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [ ];
|
|
|
|
};
|
|
|
|
content = mkOption {
|
|
|
|
type = types.functionTo (lib.types.submoduleWith {
|
|
|
|
modules = [
|
2024-05-01 02:01:47 +03:00
|
|
|
{
|
|
|
|
options.extra = with lib; mkOption {
|
|
|
|
type = with types; nullOr attrs;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
}
|
2024-04-30 16:54:48 +03:00
|
|
|
./vim/keymap.nix
|
2024-05-10 18:47:54 +03:00
|
|
|
./vim/augroup.nix
|
2024-04-30 16:54:48 +03:00
|
|
|
# ./vim/opts.nix
|
2024-05-10 18:47:54 +03:00
|
|
|
|
|
|
|
##################################################
|
|
|
|
(pkgs.path + "/nixos/modules/misc/assertions.nix")
|
2024-04-30 16:54:48 +03:00
|
|
|
];
|
|
|
|
specialArgs = { inherit lib; };
|
|
|
|
});
|
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
|
|
|
|
lambda = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
readOnly = true;
|
|
|
|
internal = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
2024-05-09 02:28:24 +03:00
|
|
|
lambda =
|
2024-04-30 16:54:48 +03:00
|
|
|
let
|
2024-05-24 15:23:38 +03:00
|
|
|
inherit (builtins) listToAttrs attrValues;
|
|
|
|
fnArgs = listToAttrs (map (v: { name = v; value = raw v; }) config.args);
|
2024-05-01 02:01:47 +03:00
|
|
|
innerCfg = config.content fnArgs;
|
2024-04-30 16:54:48 +03:00
|
|
|
in
|
|
|
|
lambda config.args (lib.flatten [
|
2024-05-01 02:01:47 +03:00
|
|
|
innerCfg.extra
|
2024-05-24 15:23:38 +03:00
|
|
|
# Autocommands
|
|
|
|
(map (v: v.genConfig) (attrValues innerCfg.vim.augroup))
|
|
|
|
# Keymaps
|
2024-04-30 16:54:48 +03:00
|
|
|
(lib.flip map innerCfg.vim.keymap.set ({ mode, lhs, rhs, ... } @ vars:
|
2024-05-24 15:23:38 +03:00
|
|
|
let m = if builtins.isList mode then lib.head mode else mode; in
|
2024-05-01 14:56:36 +03:00
|
|
|
if innerCfg.vim.keymap._validate."${m}"."${lhs}" == rhs then vars.genConfig
|
2024-04-30 16:54:48 +03:00
|
|
|
else abort "This case should never happen."
|
|
|
|
))
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.fn = with lib; mkOption {
|
|
|
|
type = with types; attrsOf (submodule fnOpts);
|
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
}
|