In our basic template we used to provide a check based on `mkTestDerivationFromNvim`. The issue with this check (that is handled correctly internally) is that some plugins _can't_ be used in the test environment, for example image.nvim like in #1085. This commit introduces a new function to generate such checks, `mkTestDerivationFromNixvimModule`, that wraps a nixvim configuration instead of a built nvim instance. Then a configuration can rely on the newly added `helpers.enableExceptInTests` attribute to disable parts of the configuration depending if it is evaluated in tests or in a real final configuration. Resolves #1085
1.3 KiB
Helpers
Regardless of the way NixVim is used (as a home-manager module, a nixos module, or as a standalone module), helpers can be included in the same way.
You can simply use:
{
helpers,
...
}: {
# Your config
}
A certain number of helpers are defined that can be useful:
-
helpers.emptyTable
: An empty lua table{}
that will be included in the final lua configuration. This is equivalent to{__empty = {};}
. This form can allow to dooption.__empty = {}
. -
helpers.mkRaw str
: Write the stringstr
as raw lua in the final lua configuration. This is equivalent to{__raw = "lua code";}
. This form can allow to dooption.__raw = "lua code"
. -
helpers.toLuaObject obj
: Create a string representation of the Nix object. Useful to define your own plugins. -
helpers.listToUnkeyedAttrs list
: Transforms a list to an "unkeyed" attribute set.This allows to define mixed table/list in lua:
(listToUnkeyedAttrs ["a", "b"]) // {foo = "bar";}
Resulting in the following lua:
{"a", "b", [foo] = "bar"}
-
helpers.enableExceptInTests
: Evaluates totrue
, except inmkTestDerivationFromNixvimModule
where it evaluates tofalse
. This allows to skip instantiating plugins that can't be run in tests.