bugfix: fix #17

This commit is contained in:
Pedro Alves 2022-05-03 17:43:52 +01:00
parent d934a33ab5
commit c298e98002

View file

@ -1,5 +1,5 @@
{ nixos ? false, nixOnDroid ? false, homeManager ? false }: { nixos ? false, nixOnDroid ? false, homeManager ? false }:
{ pkgs , lib, config, ... }: { pkgs, lib, config, ... }:
with lib; with lib;
let let
cfg = config.programs.nixvim; cfg = config.programs.nixvim;
@ -23,61 +23,64 @@ let
}; };
}; };
mapOption = types.oneOf [ types.str (types.submodule { mapOption = types.oneOf [
options = { types.str
silent = mkOption { (types.submodule {
type = types.bool; options = {
description = "Whether this mapping should be silent. Equivalent to adding <silent> to a map."; silent = mkOption {
default = false; type = types.bool;
}; description = "Whether this mapping should be silent. Equivalent to adding <silent> to a map.";
default = false;
};
nowait = mkOption { nowait = mkOption {
type = types.bool; type = types.bool;
description = "Whether to wait for extra input on ambiguous mappings. Equivalent to adding <nowait> to a map."; description = "Whether to wait for extra input on ambiguous mappings. Equivalent to adding <nowait> to a map.";
default = false; default = false;
}; };
script = mkOption { script = mkOption {
type = types.bool; type = types.bool;
description = "Equivalent to adding <script> to a map."; description = "Equivalent to adding <script> to a map.";
default = false; default = false;
}; };
expr = mkOption { expr = mkOption {
type = types.bool; type = types.bool;
description = "Means that the action is actually an expression. Equivalent to adding <expr> to a map."; description = "Means that the action is actually an expression. Equivalent to adding <expr> to a map.";
default = false; default = false;
}; };
unique = mkOption { unique = mkOption {
type = types.bool; type = types.bool;
description = "Whether to fail if the map is already defined. Equivalent to adding <unique> to a map."; description = "Whether to fail if the map is already defined. Equivalent to adding <unique> to a map.";
default = false; default = false;
}; };
noremap = mkOption { noremap = mkOption {
type = types.bool; type = types.bool;
description = "Whether to use the 'noremap' variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default."; description = "Whether to use the 'noremap' variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default.";
default = true; default = true;
}; };
action = mkOption { action = mkOption {
type = types.str; type = types.str;
description = "The action to execute."; description = "The action to execute.";
}; };
description = mkOption { description = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
description = "A textual description of this keybind, to be shown in which-key, if you have it."; description = "A textual description of this keybind, to be shown in which-key, if you have it.";
default = null; default = null;
};
}; };
}; })
}) ]; ];
mapOptions = mode: mkOption { mapOptions = mode: mkOption {
description = "Mappings for ${mode} mode"; description = "Mappings for ${mode} mode";
type = types.attrsOf mapOption; type = types.attrsOf mapOption;
default = {}; default = { };
}; };
helpers = import ./plugins/helpers.nix { lib = lib; }; helpers = import ./plugins/helpers.nix { lib = lib; };
@ -183,97 +186,101 @@ in
./plugins ./plugins
]; ];
config = let config =
neovimConfig = pkgs.neovimUtils.makeNeovimConfig { let
configure = cfg.configure; neovimConfig = pkgs.neovimUtils.makeNeovimConfig {
plugins = cfg.extraPlugins; configure = cfg.configure;
}; plugins = cfg.extraPlugins;
};
extraWrapperArgs = optionalString (cfg.extraPackages != []) extraWrapperArgs = optionalString (cfg.extraPackages != [ ])
''--prefix PATH : "${makeBinPath cfg.extraPackages}"''; ''--prefix PATH : "${makeBinPath cfg.extraPackages}"'';
package = if (cfg.package != null) then cfg.package else pkgs.neovim; package = if (cfg.package != null) then cfg.package else pkgs.neovim;
wrappedNeovim = pkgs.wrapNeovimUnstable package (neovimConfig // { wrappedNeovim = pkgs.wrapNeovimUnstable package (neovimConfig // {
wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs + " " wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs + " "
+ extraWrapperArgs; + extraWrapperArgs;
}); });
configure = { configure = {
customRC = cfg.extraConfigVim + (optionalString (cfg.colorscheme != "") '' customRC = cfg.extraConfigVim + (optionalString (cfg.colorscheme != "") ''
colorscheme ${cfg.colorscheme} colorscheme ${cfg.colorscheme}
'') + '' '') + ''
lua <<EOF lua <<EOF
${cfg.extraConfigLua} ${cfg.extraConfigLua}
EOF EOF
'';
packages.nixvim = {
start = filter (f: f != null) (map
(x:
if x ? plugin && x.optional == true then null else (x.plugin or x))
cfg.extraPlugins);
opt = filter (f: f != null)
(map (x: if x ? plugin && x.optional == true then x.plugin else null)
cfg.extraPlugins);
};
};
extraConfigLua = optionalString (cfg.globals != { }) ''
-- Set up globals {{{
local __nixvim_globals = ${helpers.toLuaObject cfg.globals}
for k,v in pairs(__nixvim_globals) do
vim.g[k] = v
end
-- }}}
'' + optionalString (cfg.options != { }) ''
-- Set up options {{{
local __nixvim_options = ${helpers.toLuaObject cfg.options}
for k,v in pairs(__nixvim_options) do
vim.o[k] = v
end
-- }}}
'' + optionalString (mappings != [ ]) ''
-- Set up keybinds {{{
local __nixvim_binds = ${helpers.toLuaObject mappings}
for i, map in ipairs(__nixvim_binds) do
vim.api.nvim_set_keymap(map.mode, map.key, map.action, map.config)
end
-- }}}
''; '';
packages.nixvim = { mappings =
start = filter (f: f != null) (map (x: (helpers.genMaps "" cfg.maps.normalVisualOp) ++
if x ? plugin && x.optional == true then null else (x.plugin or x)) (helpers.genMaps "n" cfg.maps.normal) ++
cfg.extraPlugins); (helpers.genMaps "i" cfg.maps.insert) ++
opt = filter (f: f!= null) (helpers.genMaps "v" cfg.maps.visual) ++
(map (x: if x ? plugin && x.optional == true then x.plugin else null) (helpers.genMaps "x" cfg.maps.visualOnly) ++
cfg.extraPlugins); (helpers.genMaps "s" cfg.maps.select) ++
(helpers.genMaps "t" cfg.maps.terminal) ++
(helpers.genMaps "o" cfg.maps.operator) ++
(helpers.genMaps "l" cfg.maps.lang) ++
(helpers.genMaps "!" cfg.maps.insertCommand) ++
(helpers.genMaps "c" cfg.maps.command);
in
mkIf cfg.enable (if nixos then {
environment.systemPackages = [ wrappedNeovim ];
programs.neovim = {
configure = configure;
}; };
};
extraConfigLua = optionalString (cfg.globals != {}) '' programs.nixvim.extraConfigLua = extraConfigLua;
-- Set up globals {{{
local __nixvim_globals = ${helpers.toLuaObject cfg.globals}
for k,v in pairs(__nixvim_globals) do environment.etc."xdg/nvim/sysinit.vim".text = neovimConfig.neovimRcContent;
vim.g[k] = v } else
end (if homeManager then {
-- }}} programs.nixvim.extraConfigLua = extraConfigLua;
'' + optionalString (cfg.options != {}) '' programs.neovim = {
-- Set up options {{{ enable = true;
local __nixvim_options = ${helpers.toLuaObject cfg.options} package = mkIf (cfg.package != null) cfg.package;
extraPackages = cfg.extraPackages;
for k,v in pairs(__nixvim_options) do extraConfig = configure.customRC;
vim.o[k] = v plugins = cfg.extraPlugins;
end };
-- }}} } else { }));
'' + optionalString (mappings != []) ''
-- Set up keybinds {{{
local __nixvim_binds = ${helpers.toLuaObject mappings}
for i, map in ipairs(__nixvim_binds) do
vim.api.nvim_set_keymap(map.mode, map.key, map.action, map.config)
end
-- }}}
'';
mappings =
(helpers.genMaps "" cfg.maps.normalVisualOp) ++
(helpers.genMaps "n" cfg.maps.normal) ++
(helpers.genMaps "i" cfg.maps.insert) ++
(helpers.genMaps "v" cfg.maps.visual) ++
(helpers.genMaps "x" cfg.maps.visualOnly) ++
(helpers.genMaps "s" cfg.maps.select) ++
(helpers.genMaps "t" cfg.maps.terminal) ++
(helpers.genMaps "o" cfg.maps.operator) ++
(helpers.genMaps "l" cfg.maps.lang) ++
(helpers.genMaps "!" cfg.maps.insertCommand) ++
(helpers.genMaps "c" cfg.maps.command);
in mkIf cfg.enable (if nixos then {
environment.systemPackages = [ wrappedNeovim ];
programs.neovim = {
configure = configure;
extraConfigLua = extraConfigLua;
};
environment.etc."xdg/nvim/sysinit.vim".text = neovimConfig.neovimRcContent;
} else (if homeManager then {
programs.nixvim.extraConfigLua = extraConfigLua;
programs.neovim = {
enable = true;
package = mkIf (cfg.package != null) cfg.package;
extraPackages = cfg.extraPackages;
extraConfig = configure.customRC;
plugins = cfg.extraPlugins;
};
} else {}));
} }