nixeovim/modules/fn.nix

62 lines
1.5 KiB
Nix
Raw Normal View History

{ lib, ... }:
let
fnOpts = { name, config, ... }: {
options = with lib; {
args = mkOption {
type = with types; listOf str;
default = [ ];
};
content = mkOption {
type = types.functionTo (lib.types.submoduleWith {
modules = [
{
options.extra = with lib; mkOption {
type = with types; nullOr attrs;
default = null;
};
}
./vim/keymap.nix
# ./vim/opts.nix
];
specialArgs = { inherit lib; };
});
default = { };
};
lambda = mkOption {
type = types.attrs;
readOnly = true;
internal = true;
};
};
config = {
lambda = with lib.nix2lua;
let
fnArgs = builtins.listToAttrs (map (v: { name = v; value = raw v; }) config.args);
innerCfg = config.content fnArgs;
in
lambda config.args (lib.flatten [
innerCfg.extra
(lib.flip map innerCfg.vim.keymap.set ({ mode, lhs, rhs, ... } @ vars:
let
buf = lib.optionalString (vars.buffer != null) vars.buffer.raw;
m = if builtins.isList mode then lib.head mode else mode;
in
if innerCfg.vim.keymap._validate."${buf}"."${m}"."${lhs}" == rhs then vars.genConfig
else abort "This case should never happen."
))
]);
};
};
in
{
options.fn = with lib; mkOption {
type = with types; attrsOf (submodule fnOpts);
default = { };
};
}