mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
bugfix: fix #17
This commit is contained in:
parent
d934a33ab5
commit
c298e98002
1 changed files with 137 additions and 130 deletions
267
nixvim.nix
267
nixvim.nix
|
@ -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,63 +23,66 @@ 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; };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
@ -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;
|
|
||||||
|
|
||||||
wrappedNeovim = pkgs.wrapNeovimUnstable package (neovimConfig // {
|
package = if (cfg.package != null) then cfg.package else pkgs.neovim;
|
||||||
wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs + " "
|
|
||||||
+ extraWrapperArgs;
|
|
||||||
});
|
|
||||||
|
|
||||||
configure = {
|
wrappedNeovim = pkgs.wrapNeovimUnstable package (neovimConfig // {
|
||||||
customRC = cfg.extraConfigVim + (optionalString (cfg.colorscheme != "") ''
|
wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs + " "
|
||||||
colorscheme ${cfg.colorscheme}
|
+ extraWrapperArgs;
|
||||||
'') + ''
|
});
|
||||||
lua <<EOF
|
|
||||||
${cfg.extraConfigLua}
|
configure = {
|
||||||
EOF
|
customRC = cfg.extraConfigVim + (optionalString (cfg.colorscheme != "") ''
|
||||||
|
colorscheme ${cfg.colorscheme}
|
||||||
|
'') + ''
|
||||||
|
lua <<EOF
|
||||||
|
${cfg.extraConfigLua}
|
||||||
|
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 {}));
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue