lib.lua

lib.lua.rawLua

Type: rawLua :: String -> (a -> String)

Embed raw lua code in a nix expression.

code The lua expression to embed

lib.lua.rawLua usage example

x = rawLua "function(msg) print('hello ' .. msg) end"

toLua x
=> _: "function(msg) print('hello ' .. msg) end"

lib.lua.luaFile

Type: luaFile :: String -> (a -> String)

Embed raw lua code from a file into a nix expression.

The contents of file is embedded as-is into the assigned variable.

file Function argument

lib.lua.luaFile usage example

builtins.readFile ./test.lua
=> "function(msg) print('hello ' .. msg) end"

x = luaFile ./test.lua
=> _: "function(msg) print('hello ' .. msg) end"

lib.lua.processPrimitive

Type: processPrimitive :: value -> String

Converts a primitive value to its stringified lua counterpart.

Types nil, boolean, number, string, and table are convertable from their respective nix-equivalents. Functions are supported in limited a fashion; a passed function must be callable with exactly one argument (which should be ignored in the implementation). The function must return raw lua code (stringified). The following lambda is an example of such a valid function:

foo = _: "function(msg) print('hello ' .. msg) end"

The remaining types userdata and thread are not able to be converted to.

value Value to convert to stringified lua representation

lib.lua.processPrimitive usage example

x = { a = "foo"; b = null }
processPrimitive x.a
=> "\"foo\""
processPrimitive x.b
=> "nil"

lib.lua.toLua

Type: toLua :: values -> String

Converts an attribute set, list, or primitive into its stringified lua representation.

Note on converting attribute sets: Since lua supports both named and unnamed table values (but nix attrsets do not), a magic identifier __index__ is used to convert from named values to anonymous ones. This identified may occur anywhere inside the name. Note that since attrsets are implicitly sorted by key names, you will need to lexicographically sort the keys which you want to anonymize by hand, ex: zzz__index__.

values values to convert to lua

lib.lua.toLua usage example

x = { a = { b = 3; }; __index__baz = "some string"; c = "foo"; d = null; }
y = "some string"

toLua x
=> ''
 { "some string", a = { b = 3 }, c = "foo", d = nil }
''

toLua y
=> "\"some string\""

lib.vim

lib.vim.processVimPrefs

processes each vim namespace (for example vim.g or vim.o) into stringified lua code

ns Function argument

values Function argument

lib.vim.mkKeymap

Creates a lua keymap. Note that opts may be omitted when using this function. Although this results in a curried function, the internal keymap module takes care of this by automatically adding an empty option set at eval-time (see modules/core/keymap.nix).

mode Function argument

lhs Function argument

rhs Function argument

opts Function argument

lib.vim.mkSimplePlugin

Type: mkSimplePlugin :: Attrs -> Attrs

Convenience wrapper for creating plugin modules. Note that this function simply returns a standard module, and as such is equivalent to you doing so.

structured function argument

: config

: The top-level config you have access to in your module.

plugin

: The plugin source (for instance a source produced by pkgs.fetchFromGitHub).

category

: The path to expose your module options under. Each element correspons to a level of nesting in the config. For instace, category = ["foo" "bar"] would expose the options: foo.bar = {...}. You may also pass a string where each nested level is separated by a /. For instance, "foo/bar" is equivalent to the example above.

derivePluginNameFunc

: A function to derive the plugin name from the plugin source. The default implementation uses the repo attribute from plugin (assumes structure similar to a source produced by fetchFromGitHub). The input to this function is plugin. The output must be a string.

moduleName

: The name of the plugin to use in the module options. By default, the implmentation uses the result of derivePluginNameFunc to derive the option namespace from the plugin source.

extraPluginConfig

: Extra options to pass to the lazy plugin spec. The function receives the plugin config at evaluation time as its only input. The output must be an attribute set, which is merged with the final spec. Any options which are accepted by layz's plugin spec should be valid.

noSetup

: Omit the opt options from the final module as well as the plugin spec. You may want to use this if the plugin which you specify does not support a conventional setup() function, for example a vimscript plugin which simply gets loaded.

extraModuleOpts

: Any extra module options to generate for this module. Standard option-conventions apply.

extraConfig

: Extra config to generate for this module if it is enabled. This is merged with the final config. You may, for example, use this to set additional pre/post-hooks or set keymaps, etc.

lib.vim.mkSimplePlugin usage example

myPluginSrc = pkgs.fetchFromGitHub {
  owner = "aUser";
  repo = "aRepo";
  # ...
}

# From inside a module, call mkSimplePlugin:

# myModule.nix
{pkgs, config, lib, ...}: lib.mkSimplePlugin {
  inherit config;
  plugin = myPluginSrc;
  category = [ "colorschemes" "myColorscheme"]
}