{ lib , stdenv , runCommand , writeShellScriptBin , writeTextFile , neovim-unwrapped , makeWrapper , tree-sitter , fd , ripgrep , html-tidy , node-lsp , fetchFromGitHub , fetchpatch , 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/.bin/tsc "$@" fi ''; extraPath = [ fd ripgrep html-tidy node-lsp tsc ]; pinnedPlugins = import ./plugins { inherit buildNeovimPlugin fetchFromGitHub fetchpatch; }; treesitterPlugins = import ./treesitter { inherit lib runCommand fetchFromGitHub tree-sitter; }; plugins = (builtins.filter (p: !p.optional) (lib.attrValues pinnedPlugins)) ++ (lib.attrValues treesitterPlugins) ++ [ extra-treesitter-textobjects ] ++ lib.optionals withPlayground [ pinnedPlugins."nvim-treesitter/playground" ] ++ lib.optionals withLuadev [ pinnedPlugins."bfredl/nvim-luadev" ]; generic = { initText ? "", enabledPlugins ? [], passthru ? {} }: 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 ${initText} ''; 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}" '') enabledPlugins} # 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 ''; inherit passthru; installPhase = '' mkdir $out cp -r * $out ''; }; in generic { initText = '' 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} ''; enabledPlugins = plugins; passthru = { minimal = generic {}; }; }