2023-02-20 11:42:13 +01:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
2022-09-18 11:19:23 +01:00
|
|
|
pluginWithConfigType = types.submodule {
|
|
|
|
options = {
|
|
|
|
config = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
description = "vimscript for this plugin to be placed in init.vim";
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
optional =
|
|
|
|
mkEnableOption "optional"
|
|
|
|
// {
|
|
|
|
description = "Don't load by default (load with :packadd)";
|
|
|
|
};
|
2022-09-18 11:19:23 +01:00
|
|
|
|
|
|
|
plugin = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
description = "vim plugin";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-02-20 11:42:13 +01:00
|
|
|
in {
|
2022-09-18 11:19:23 +01:00
|
|
|
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);
|
2023-02-20 11:42:13 +01:00
|
|
|
default = [];
|
2022-09-18 11:19:23 +01:00
|
|
|
description = "List of vim plugins to install";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraPackages = mkOption {
|
|
|
|
type = types.listOf types.package;
|
2023-02-20 11:42:13 +01:00
|
|
|
default = [];
|
2022-09-18 11:19:23 +01:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
config = let
|
|
|
|
defaultPlugin = {
|
|
|
|
plugin = null;
|
|
|
|
config = "";
|
|
|
|
optional = false;
|
|
|
|
};
|
2022-09-18 11:19:23 +01:00
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
normalizedPlugins = map (x:
|
|
|
|
defaultPlugin
|
|
|
|
// (
|
|
|
|
if x ? plugin
|
|
|
|
then x
|
|
|
|
else {plugin = x;}
|
|
|
|
))
|
|
|
|
config.extraPlugins;
|
2022-09-18 11:19:23 +01:00
|
|
|
|
2023-02-20 11:42:13 +01: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) {
|
2023-02-20 11:42:13 +01:00
|
|
|
configure.packages = {
|
|
|
|
nixvim = {
|
|
|
|
start = map (x: x.plugin) normalizedPlugins;
|
|
|
|
opt = [];
|
|
|
|
};
|
|
|
|
};
|
2022-10-07 15:54:04 +02:00
|
|
|
});
|
2022-09-18 11:19:23 +01:00
|
|
|
|
2023-02-20 11:42:13 +01: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}
|
|
|
|
'');
|
|
|
|
|
|
|
|
extraWrapperArgs = builtins.concatStringsSep " " (
|
|
|
|
(optional (config.extraPackages != [])
|
|
|
|
''--prefix PATH : "${makeBinPath config.extraPackages}"'')
|
|
|
|
++ (optional (config.wrapRc)
|
|
|
|
''--add-flags -u --add-flags "${pkgs.writeText "init.lua" customRC}"'')
|
|
|
|
);
|
|
|
|
|
|
|
|
wrappedNeovim = pkgs.wrapNeovimUnstable config.package (neovimConfig
|
|
|
|
// {
|
2022-09-18 11:19:23 +01:00
|
|
|
wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs + " " + extraWrapperArgs;
|
2022-11-07 10:59:10 -05:00
|
|
|
wrapRc = false;
|
2022-09-18 11:19:23 +01:00
|
|
|
});
|
2023-02-20 11:42:13 +01:00
|
|
|
in {
|
|
|
|
finalPackage = wrappedNeovim;
|
|
|
|
initContent = customRC;
|
|
|
|
};
|
2022-09-18 11:19:23 +01:00
|
|
|
}
|