2023-04-20 22:41:37 +02: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 = {
|
|
|
|
viAlias = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2023-09-18 21:38:58 +07:00
|
|
|
Symlink `vi` to `nvim` binary.
|
2023-04-20 22:41:37 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
vimAlias = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2023-09-18 21:38:58 +07:00
|
|
|
Symlink `vim` to `nvim` binary.
|
2023-04-20 22:41:37 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.neovim-unwrapped;
|
|
|
|
description = "Neovim to use for nixvim";
|
|
|
|
};
|
|
|
|
|
|
|
|
wrapRc = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = "Should the config be included in the wrapper script";
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
finalPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
description = "Wrapped neovim";
|
|
|
|
readOnly = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
initContent = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "The content of the init.lua file";
|
|
|
|
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;
|
|
|
|
|
|
|
|
neovimConfig = pkgs.neovimUtils.makeNeovimConfig ({
|
|
|
|
inherit (config) viAlias vimAlias;
|
|
|
|
# inherit customRC;
|
|
|
|
plugins = normalizedPlugins;
|
|
|
|
}
|
|
|
|
# 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 = {
|
|
|
|
nixvim = {
|
|
|
|
start = map (x: x.plugin) normalizedPlugins;
|
|
|
|
opt = [];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
customRC =
|
|
|
|
''
|
|
|
|
vim.cmd([[
|
|
|
|
${neovimConfig.neovimRcContent}
|
|
|
|
]])
|
|
|
|
''
|
|
|
|
+ config.content;
|
|
|
|
|
|
|
|
extraWrapperArgs = builtins.concatStringsSep " " (
|
|
|
|
(optional (config.extraPackages != [])
|
|
|
|
''--prefix PATH : "${makeBinPath config.extraPackages}"'')
|
2023-05-22 15:45:47 +05:30
|
|
|
++ (optional config.wrapRc
|
2023-04-20 22:41:37 +02:00
|
|
|
''--add-flags -u --add-flags "${pkgs.writeText "init.lua" customRC}"'')
|
|
|
|
);
|
|
|
|
|
|
|
|
wrappedNeovim = pkgs.wrapNeovimUnstable config.package (neovimConfig
|
|
|
|
// {
|
|
|
|
wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs + " " + extraWrapperArgs;
|
|
|
|
wrapRc = false;
|
|
|
|
});
|
|
|
|
in {
|
|
|
|
type = lib.mkForce "lua";
|
|
|
|
finalPackage = wrappedNeovim;
|
|
|
|
initContent = customRC;
|
|
|
|
extraPlugins =
|
|
|
|
if config.wrapRc
|
|
|
|
then [config.filesPlugin]
|
|
|
|
else [];
|
|
|
|
};
|
|
|
|
}
|