nix-community.nixvim/modules/output.nix
traxys 5a498edd14
modules/output: Allow to specify text to add as extra files (#343)
To enable some features (like adding tree-sitter queries) we need to add
files to specific directories in the runtime path (queries/lang/file.scm
for tree-sitter queries for example).

This commit adds support for specifying such files. You must be careful
to not have any collisions between `files` and `extraFiles`.
2023-04-21 20:04:58 +02:00

123 lines
2.8 KiB
Nix

{
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 = {
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 the file";
};
extraConfigLuaPre = mkOption {
type = types.lines;
default = "";
description = "Extra contents for the file before everything else";
};
extraConfigLuaPost = mkOption {
type = types.lines;
default = "";
description = "Extra contents for the file after everything else";
};
extraConfigVim = mkOption {
type = types.lines;
default = "";
description = "Extra contents for the file, in vimscript";
};
type = mkOption {
type = types.enum ["vim" "lua"];
default = "lua";
description = "Whether the generated file is a vim or a lua file";
};
path = mkOption {
type = types.str;
description = "Path of the file relative to the config directory";
};
content = mkOption {
type = types.str;
description = "The content of the config file";
readOnly = true;
visible = false;
};
extraLuaPackages = mkOption {
type = types.functionTo (types.listOf types.package);
description = "Extra lua packages to include with neovim";
default = _: [];
};
extraFiles = mkOption {
type = types.attrsOf types.str;
description = "Extra files to add to the runtime path";
default = {};
};
};
config = let
contentLua = ''
${config.extraConfigLuaPre}
vim.cmd([[
${config.extraConfigVim}
]])
${config.extraConfigLua}
${config.extraConfigLuaPost}
'';
contentVim = ''
lua << EOF
${config.extraConfigLuaPre}
EOF
${config.extraConfigVim}
lua << EOF
${config.extraConfigLua}
${config.extraConfigLuaPost}
EOF
'';
in {
content =
if config.type == "lua"
then contentLua
else contentVim;
};
}