{ lib , stdenv , writeTextFile , neovim-unwrapped , makeWrapper , fd , ripgrep , node-lsp , vimPlugins , fetchFromGitHub , withPlayground ? 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 = "/after/queries/javascript/textobjects.scm"; text = '' ; support swapping elements inside arrays too (array "," . (_) @parameter.inner) (array . (_) @parameter.inner ",") ''; }; extra-tsc-compiler = writeTextFile { name = "extra-tsc-compiler"; destination = "/after/compiler/tsc.vim"; text = '' CompilerSet makeprg=node_modules/.bin/tsc\ --incremental\ --noEmit ''; }; extraPath = [ fd ripgrep node-lsp ]; 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 ]; plugins = (import ./plugins.nix { inherit buildNeovimPlugin fetchFromGitHub; }) ++ nixpkgsPlugins ++ [ extra-treesitter-textobjects extra-tsc-compiler ]; 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 ${./theme.lua} '' + lib.optionalString withPlayground '' source ${./playground.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 ''; }