Nix2NVimRc is a set of Nix functions and Nixpkgs module specification to generate a Neovim configuration (nvimrc) from a given module configuration.
The module provides options to configure following items:
Neovim configuration item | Nix2NVimRC module option | used Neovim Lua API |
---|---|---|
Neovim option | opts.<name> = <value> |
vim.opt['<name>'] = <value> |
Neovim keymap (see also helper function toKeymap ) |
keymaps[] |
vim.keymap.set() |
Neovim global variable | vars.<name> = <value> |
vim.api.nvim_set_var(<name>, <value>) |
Neovim treesitter | treesitter.parsers.<name> = <path> |
vim.treesitter.language.add(<name>, { path: <path> }) |
Neovim LSP via plugin nvim-lspconfig | lspconfig. |
passed to nix-lspconfig.lua |
Lua plugin setup | setup. |
require('...').setup() |
Vim expression or file | vim[] |
vim.cmd() |
Lua expression or file | lua[] |
inlined |
Vim plugin as Nix package | plugins[] |
handled by nixpkgs.vimUtils.packDir |
The file ./example-config.nix
contains a minimalistic example configuration.
To generate and use this configuration, execute following steps:
nix-build -I "$NIX_PATH" -E 'with import <nixpkgs> { }; writeText "init.lua" ((import ./lib.nix).toRc pkgs ./example-config.nix)'
nvim -u NORC --cmd "luafile ./result"
To see a more sophisticated example, go to repository ck3d-nvim-configs.
- Output only Lua code for NVim
- Keep dependency to
nixpkgs
as small as possible:lib.
:optional
,optionals
,evalModules
,types
,mkOption
, andtoposort
pkgs.
:vimUtils.packDir
- No dependency in the Nix Flake to avoid a lock file