mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
Set globals before plugin setup (#27)
* Set globals before plugin setup * added extraLuaPreConfig and extraLuaPostConfig * made colorscheme execute in lua
This commit is contained in:
parent
4d573a1e75
commit
b1f99f2f08
1 changed files with 44 additions and 27 deletions
71
nixvim.nix
71
nixvim.nix
|
@ -114,6 +114,18 @@ in
|
|||
description = "Extra contents for init.lua";
|
||||
};
|
||||
|
||||
extraLuaPreConfig = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
description = "Extra contents for init.lua before everything else";
|
||||
};
|
||||
|
||||
extraLuaPostConfig = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
description = "Extra contents for init.lua after everything else";
|
||||
};
|
||||
|
||||
extraConfigVim = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
|
@ -203,30 +215,7 @@ in
|
|||
+ extraWrapperArgs;
|
||||
});
|
||||
|
||||
configure = {
|
||||
customRC = cfg.extraConfigVim + ''
|
||||
lua <<EOF
|
||||
${cfg.extraConfigLua}
|
||||
EOF
|
||||
'' +
|
||||
# Set colorscheme after setting globals.
|
||||
# Some colorschemes depends on variables being set before setting the colorscheme.
|
||||
(optionalString (cfg.colorscheme != "" && cfg.colorscheme != null) ''
|
||||
colorscheme ${cfg.colorscheme}
|
||||
'') ;
|
||||
|
||||
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 != { }) ''
|
||||
luaGlobals = optionalString (cfg.globals != { }) ''
|
||||
-- Set up globals {{{
|
||||
local __nixvim_globals = ${helpers.toLuaObject cfg.globals}
|
||||
|
||||
|
@ -252,6 +241,37 @@ in
|
|||
-- }}}
|
||||
'';
|
||||
|
||||
configure = {
|
||||
# Make sure that globals are set before plugins are setup.
|
||||
# This is becuase you might want to define variables or global functions
|
||||
# that the plugin configuration depend upon.
|
||||
customRC = cfg.extraConfigVim + ''
|
||||
lua <<EOF
|
||||
${cfg.extraLuaPreConfig}
|
||||
${luaGlobals}
|
||||
${cfg.extraConfigLua}
|
||||
'' +
|
||||
# Set colorscheme after setting globals.
|
||||
# Some colorschemes depends on variables being set before setting the colorscheme.
|
||||
(optionalString (cfg.colorscheme != "" && cfg.colorscheme != null) ''
|
||||
vim.cmd([[colorscheme ${cfg.colorscheme}]])
|
||||
'') +
|
||||
''
|
||||
${cfg.extraLuaPostConfig}
|
||||
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);
|
||||
};
|
||||
};
|
||||
|
||||
mappings =
|
||||
(helpers.genMaps "" cfg.maps.normalVisualOp) ++
|
||||
(helpers.genMaps "n" cfg.maps.normal) ++
|
||||
|
@ -272,12 +292,9 @@ in
|
|||
configure = configure;
|
||||
};
|
||||
|
||||
programs.nixvim.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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue