2022-09-18 11:19:23 +01:00
|
|
|
{ pkgs, config, lib, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
pluginWithConfigType = types.submodule {
|
|
|
|
options = {
|
|
|
|
config = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
description = "vimscript for this plugin to be placed in init.vim";
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
optional = mkEnableOption "optional" // {
|
|
|
|
description = "Don't load by default (load with :packadd)";
|
|
|
|
};
|
|
|
|
|
|
|
|
plugin = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
description = "vim plugin";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2022-12-08 12:12:57 -05:00
|
|
|
viAlias = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Symlink <command>vi</command> to <command>nvim</command> binary.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
vimAlias = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Symlink <command>vim</command> to <command>nvim</command> binary.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-09-18 11:19:23 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.neovim-unwrapped;
|
|
|
|
description = "Neovim to use for nixvim";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraPlugins = mkOption {
|
|
|
|
type = with types; listOf (either package pluginWithConfigType);
|
|
|
|
default = [ ];
|
|
|
|
description = "List of vim plugins to install";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraPackages = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [ ];
|
|
|
|
description = "Extra packages to be made available to neovim";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfigLua = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Extra contents for init.lua";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfigLuaPre = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Extra contents for init.lua before everything else";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfigLuaPost = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Extra contents for init.lua after everything else";
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
extraConfigVim = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Extra contents for init.vim";
|
|
|
|
};
|
|
|
|
|
2022-10-17 15:08:17 +02:00
|
|
|
wrapRc = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = "Should the config be included in the wrapper script";
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
finalPackage = mkOption {
|
2022-09-18 11:19:23 +01:00
|
|
|
type = types.package;
|
2022-10-17 15:08:17 +02:00
|
|
|
description = "Wrapped neovim";
|
|
|
|
readOnly = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
initContent = mkOption {
|
|
|
|
type = types.str;
|
2022-11-07 10:59:10 -05:00
|
|
|
description = "The content of the init.lua file";
|
2022-09-18 11:19:23 +01:00
|
|
|
readOnly = true;
|
|
|
|
visible = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config =
|
|
|
|
let
|
|
|
|
|
|
|
|
defaultPlugin = {
|
|
|
|
plugin = null;
|
|
|
|
config = "";
|
|
|
|
optional = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
normalizedPlugins = map (x: defaultPlugin // (if x ? plugin then x else { plugin = x; })) config.extraPlugins;
|
|
|
|
|
2022-10-07 15:54:04 +02:00
|
|
|
neovimConfig = pkgs.neovimUtils.makeNeovimConfig ({
|
2022-12-08 12:12:57 -05:00
|
|
|
inherit (config) viAlias vimAlias;
|
2022-11-07 10:59:10 -05:00
|
|
|
# inherit customRC;
|
2022-09-18 11:19:23 +01:00
|
|
|
plugins = normalizedPlugins;
|
2022-10-07 15:54:04 +02:00
|
|
|
}
|
|
|
|
# Necessary to make sure the runtime path is set properly in NixOS 22.05,
|
|
|
|
# or more generally before the commit:
|
|
|
|
# cda1f8ae468 - neovim: pass packpath via the wrapper
|
|
|
|
// optionalAttrs (functionArgs pkgs.neovimUtils.makeNeovimConfig ? configure) {
|
|
|
|
configure.packages =
|
2022-10-17 10:21:37 +01:00
|
|
|
{ nixvim = { start = map (x: x.plugin) normalizedPlugins; opt = [ ]; }; };
|
2022-10-07 15:54:04 +02:00
|
|
|
});
|
2022-09-18 11:19:23 +01:00
|
|
|
|
2022-11-08 11:19:38 +00:00
|
|
|
customRC =
|
|
|
|
''
|
|
|
|
vim.cmd([[
|
|
|
|
${neovimConfig.neovimRcContent}
|
|
|
|
]])
|
|
|
|
'' +
|
|
|
|
(optionalString (config.extraConfigLuaPre != "") ''
|
|
|
|
${config.extraConfigLuaPre}
|
|
|
|
'') +
|
|
|
|
(optionalString (config.extraConfigVim != "") ''
|
|
|
|
vim.cmd([[
|
|
|
|
${config.extraConfigVim}
|
|
|
|
]])
|
|
|
|
'') +
|
|
|
|
(optionalString (config.extraConfigLua != "" || config.extraConfigLuaPost != "") ''
|
|
|
|
${config.extraConfigLua}
|
|
|
|
${config.extraConfigLuaPost}
|
|
|
|
'');
|
|
|
|
|
2022-11-07 10:59:10 -05:00
|
|
|
extraWrapperArgs = builtins.concatStringsSep " " (
|
|
|
|
(optional (config.extraPackages != [ ])
|
|
|
|
''--prefix PATH : "${makeBinPath config.extraPackages}"'')
|
|
|
|
++
|
|
|
|
(optional (config.wrapRc)
|
|
|
|
''--add-flags -u --add-flags "${pkgs.writeText "init.lua" customRC}"'')
|
|
|
|
);
|
2022-09-18 11:19:23 +01:00
|
|
|
|
|
|
|
wrappedNeovim = pkgs.wrapNeovimUnstable config.package (neovimConfig // {
|
|
|
|
wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs + " " + extraWrapperArgs;
|
2022-11-07 10:59:10 -05:00
|
|
|
wrapRc = false;
|
2022-09-18 11:19:23 +01:00
|
|
|
});
|
2022-10-18 23:23:49 +01:00
|
|
|
in
|
|
|
|
{
|
2022-10-17 15:08:17 +02:00
|
|
|
finalPackage = wrappedNeovim;
|
2022-11-08 11:19:38 +00:00
|
|
|
initContent = customRC;
|
2022-09-18 11:19:23 +01:00
|
|
|
};
|
|
|
|
}
|