1 { config, lib, pkgs, ... }:
4 cfg = config.programs.neovim;
7 options.programs.neovim = {
8 enable = lib.mkOption {
13 Whether to enable Neovim.
15 When enabled through this option, Neovim is wrapped to use a
16 configuration managed by this module. The configuration file in the
17 user's home directory at {file}`~/.config/nvim/init.vim` is no longer
22 defaultEditor = lib.mkOption {
23 type = lib.types.bool;
26 When enabled, installs neovim and configures neovim to be the default editor
27 using the EDITOR environment variable.
31 viAlias = lib.mkOption {
32 type = lib.types.bool;
35 Symlink {command}`vi` to {command}`nvim` binary.
39 vimAlias = lib.mkOption {
40 type = lib.types.bool;
43 Symlink {command}`vim` to {command}`nvim` binary.
47 withRuby = lib.mkOption {
48 type = lib.types.bool;
50 description = "Enable Ruby provider.";
53 withPython3 = lib.mkOption {
54 type = lib.types.bool;
56 description = "Enable Python 3 provider.";
59 withNodeJs = lib.mkOption {
60 type = lib.types.bool;
62 description = "Enable Node provider.";
65 configure = lib.mkOption {
66 type = lib.types.attrs;
68 example = lib.literalExpression ''
71 " here your custom configuration goes!
73 packages.myVimPackage = with pkgs.vimPlugins; {
76 # manually loadable by calling `:packadd $plugin-name`
82 Generate your init file from your list of plugins and custom commands.
83 Neovim will then be wrapped to load {command}`nvim -u /nix/store/«hash»-vimrc`
87 package = lib.mkPackageOption pkgs "neovim-unwrapped" { };
89 finalPackage = lib.mkOption {
90 type = lib.types.package;
93 description = "Resulting customized neovim package.";
96 runtime = lib.mkOption {
98 example = lib.literalExpression ''
99 { "ftplugin/c.vim".text = "setlocal omnifunc=v:lua.vim.lsp.omnifunc"; }
102 Set of files that have to be linked in {file}`runtime`.
105 type = with lib.types; attrsOf (submodule (
106 { name, config, ... }:
110 enable = lib.mkOption {
111 type = lib.types.bool;
114 Whether this runtime directory should be generated. This
115 option allows specific runtime files to be disabled.
119 target = lib.mkOption {
120 type = lib.types.str;
122 Name of symlink. Defaults to the attribute
127 text = lib.mkOption {
129 type = lib.types.nullOr lib.types.lines;
130 description = "Text of the file.";
133 source = lib.mkOption {
135 type = lib.types.nullOr lib.types.path;
136 description = "Path of the source file.";
141 config.target = lib.mkDefault name;
148 config = lib.mkIf cfg.enable {
149 environment.systemPackages = [
152 environment.variables.EDITOR = lib.mkIf cfg.defaultEditor (lib.mkOverride 900 "nvim");
153 # On most NixOS configurations /share is already included, so it includes
154 # this directory as well. But This makes sure that /share/nvim/site paths
155 # from other packages will be used by neovim.
156 environment.pathsToLink = [ "/share/nvim" ];
158 environment.etc = builtins.listToAttrs (builtins.attrValues (builtins.mapAttrs
160 name = "xdg/nvim/${name}";
161 value = builtins.removeAttrs
163 target = "xdg/nvim/${value.target}";
165 (lib.optionals (builtins.isNull value.source) [ "source" ]);
169 programs.neovim.finalPackage = pkgs.wrapNeovim cfg.package {
170 inherit (cfg) viAlias vimAlias withPython3 withNodeJs withRuby configure;