{ lib , stdenv , writeShellScriptBin , writeTextFile , neovim-unwrapped , makeWrapper , fd , ripgrep , node-lsp , vimPlugins , fetchFromGitHub , withPlayground ? false , withLuadev ? false }: let buildNeovimPlugin = attrs: stdenv.mkDerivation ({ forceShare= [ "man" "info" ]; installPhase = '' cp -r . $out if [ -d "$out/doc" ]; then ${neovim-unwrapped}/bin/nvim -N -u NONE -i NONE -n -E -s -V1 -c "helptags $out/doc" +quit! fi ''; } // attrs); extra-treesitter-textobjects = writeTextFile { name = "extra-treesitter-textobjects"; destination = "/queries/ecma/textobjects.scm"; text = '' ;; extends ; consider array elements as @parameter text objects too (array "," @_start . (_) @parameter.inner (#make-range! "parameter.outer" @_start @parameter.inner)) (array . (_) @parameter.inner . ","? @_end (#make-range! "parameter.outer" @parameter.inner @_end)) ''; }; tsc = writeShellScriptBin "tsc" '' if [ -x "./node_modules/.bin/tsc" ]; then exec ./node_modules/.bin/tsc "$@" else exec ${node-lsp}/lib/node_modules/node-lsp/node_modules/.bin/tsc "$@" fi ''; extraPath = [ fd ripgrep node-lsp tsc ]; nixpkgsPlugins = let # we take nvim-treesitter from nixpkgs as the plugin and grammar versions # must match exactly nvim-treesitter = (vimPlugins.nvim-treesitter.withPlugins (p: with p; [ tree-sitter-bash tree-sitter-css tree-sitter-elvish tree-sitter-go tree-sitter-javascript tree-sitter-json tree-sitter-lua tree-sitter-nix tree-sitter-ruby tree-sitter-tsx tree-sitter-typescript ] ++ lib.optionals withPlayground [ tree-sitter-query ])); in [ nvim-treesitter ] ++ nvim-treesitter.dependencies ++ (lib.optionals withPlayground [ vimPlugins.playground ]) ++ (lib.optionals withLuadev [ vimPlugins.nvim-luadev ]); pinnedPlugins = import ./plugins { inherit buildNeovimPlugin fetchFromGitHub; }; plugins = (lib.attrValues pinnedPlugins) ++ nixpkgsPlugins ++ [ extra-treesitter-textobjects ]; in stdenv.mkDerivation { pname = "nvim"; version = neovim-unwrapped.version; initVim = '' let g:loaded_python3_provider = 0 let g:loaded_ruby_provider = 0 let g:loaded_node_provider = 0 let g:loaded_perl_provider = 0 set runtimepath^=${placeholder "out"}/lib set packpath^=${placeholder "out"}/lib source ${./settings.lua} source ${./plugins.lua} source ${./mappings.lua} source ${./autocmd.lua} source ${./lsp.lua} source ${./make.lua} source ${./theme.lua} '' + lib.optionalString withPlayground '' source ${./playground.lua} '' + lib.optionalString withLuadev '' source ${./luadev.lua} ''; passAsFile = [ "initVim" ]; nativeBuildInputs = [ makeWrapper ]; unpackPhase = ":"; buildPhase = '' # build pack / runtime dir mkdir -p lib/pack/nixpkgs/start ${lib.concatMapStringsSep "\n" (p: '' ln -s "${p}" "lib/pack/nixpkgs/start/${lib.getName p}" '') plugins} # create config file mkdir etc cp "$initVimPath" etc/init.vim # symlink in man pages mkdir -p share ln -s ${neovim-unwrapped}/share/man share/man # make bin mkdir bin makeWrapper ${neovim-unwrapped}/bin/nvim bin/nvim \ --prefix PATH : ${lib.makeBinPath extraPath} \ --add-flags -u \ --add-flags $out/etc/init.vim ''; installPhase = '' mkdir $out cp -r * $out ''; }