nix-community.nixvim/modules/output.nix
Matt Sturgeon 086873bed9
modules: refactor extraFiles
Moved `extraFiles` from `modules/output.nix` into its own file `modules/files.nix`.

Users should now assign text to a `text` attribute, however they could
also assign a file path to a `source` attribute instead.

The old method of directly assigning a string still works, and is
coerced to the new type along with a deprecation warning.
2024-07-07 16:42:47 +01:00

125 lines
3 KiB
Nix

{ lib, config, ... }:
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 = with types; listOf (nullOr package);
default = [ ];
description = "Extra packages to be made available to neovim";
apply = builtins.filter (p: p != null);
};
extraPython3Packages = mkOption {
type = with types; functionTo (listOf package);
default = p: [ ];
defaultText = literalExpression "p: with p; [ ]";
description = "Python packages to add to the `PYTHONPATH` of neovim.";
example = lib.literalExpression ''
p: [ p.numpy ]
'';
};
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 = _: [ ];
};
};
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;
};
}