diff --git a/default.nix b/default.nix index 8b4b180..f7df7d9 100644 --- a/default.nix +++ b/default.nix @@ -3,20 +3,23 @@ , nix2lua ? import }: + +let nix2lua' = nix2lua; in let inherit (pkgs.lib) evalModules filter concatMapStringsSep showWarnings; - extendedLib = import ./lib { inherit (pkgs) lib; }; + nix2lua = nix2lua'.lib; + + lib = import ./lib { + inherit (pkgs) lib; + inherit nix2lua; + }; allModules = import ./module-list.nix { inherit pkgs; }; rawModule = evalModules { modules = [ config ] ++ allModules; - specialArgs = { - inherit pkgs; - lib = extendedLib; - nix2lua = nix2lua.lib; - }; + specialArgs = { inherit pkgs lib nix2lua; }; }; failedAssertions = map (x: x.message) (filter (x: !x.assertion) rawModule.config.assertions); diff --git a/lib/default.nix b/lib/default.nix index 152ec54..1864d13 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,7 +1,7 @@ -{ lib }: +{ lib, nix2lua }: let - types = import ./types.nix { inherit lib; }; + types = import ./types.nix { inherit lib nix2lua; }; in lib // { types = lib.types // types; diff --git a/lib/types.nix b/lib/types.nix index 66d7ac2..5b4ae7f 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -1,4 +1,4 @@ -{ lib }: +{ lib, nix2lua }: let modeEnum = lib.types.enum [ "" "n" "!" "i" "c" "v" "x" "s" "o" "t" "l" ]; @@ -126,6 +126,21 @@ let Human-readable description. ''; }; + + genConfig = mkOption { + type = types.attrs; + readOnly = true; + internal = true; + }; + }; + + config = { + genConfig = with nix2lua; call "vim.keymap.set" [ + config.mode + config.lhs + config.rhs + { inherit (config) buffer nowait silent script expr unique remap desc; } + ]; }; }); in diff --git a/modules/build/neovim.nix b/modules/build/neovim.nix index b473240..7be2a5e 100644 --- a/modules/build/neovim.nix +++ b/modules/build/neovim.nix @@ -46,8 +46,7 @@ in buf = lib.optionalString (vars.buffer != null) vars.buffer; m = if builtins.isList mode then lib.head mode else mode; in - if config.vim.keymap._validate."${buf}"."${m}"."${lhs}" == rhs then - call "vim.keymap.set" [ mode lhs rhs (removeAttrs vars [ "mode" "lhs" "rhs" ]) ] + if config.vim.keymap._validate."${buf}"."${m}"."${lhs}" == rhs then vars.genConfig else abort "This case should never happen." )) ]));