60 lines
1.5 KiB
Nix
60 lines
1.5 KiB
Nix
|
{ lib, ... }:
|
||
|
|
||
|
let
|
||
|
|
||
|
fnOpts = { name, config, ... }: {
|
||
|
options = with lib; {
|
||
|
args = mkOption {
|
||
|
type = with types; listOf str;
|
||
|
default = [ ];
|
||
|
};
|
||
|
content = mkOption {
|
||
|
type = with types; nullOr attrs;
|
||
|
default = null;
|
||
|
};
|
||
|
settings = mkOption {
|
||
|
type = types.functionTo (lib.types.submoduleWith {
|
||
|
modules = [
|
||
|
./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.settings fnArgs;
|
||
|
in
|
||
|
lambda config.args (lib.flatten [
|
||
|
config.content
|
||
|
|
||
|
(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 = { };
|
||
|
};
|
||
|
}
|