neovim.nix 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. { lib
  2. , stdenv
  3. , runCommand
  4. , writeShellScriptBin
  5. , writeTextFile
  6. , neovim-unwrapped
  7. , makeWrapper
  8. , tree-sitter
  9. , fd
  10. , ripgrep
  11. , html-tidy
  12. , node-lsp
  13. , fetchFromGitHub
  14. , fetchpatch
  15. , withPlayground ? false
  16. , withLuadev ? false
  17. }:
  18. let
  19. buildNeovimPlugin = attrs: stdenv.mkDerivation ({
  20. forceShare= [ "man" "info" ];
  21. installPhase = ''
  22. cp -r . $out
  23. if [ -d "$out/doc" ]; then
  24. ${neovim-unwrapped}/bin/nvim -N -u NONE -i NONE -n -E -s -V1 -c "helptags $out/doc" +quit!
  25. fi
  26. '';
  27. } // attrs);
  28. extra-treesitter-textobjects = writeTextFile {
  29. name = "extra-treesitter-textobjects";
  30. destination = "/queries/ecma/textobjects.scm";
  31. text = ''
  32. ;; extends
  33. ; consider array elements as @parameter text objects too
  34. (array
  35. "," @_start .
  36. (_) @parameter.inner
  37. (#make-range! "parameter.outer" @_start @parameter.inner))
  38. (array
  39. . (_) @parameter.inner
  40. . ","? @_end
  41. (#make-range! "parameter.outer" @parameter.inner @_end))
  42. '';
  43. };
  44. tsc = writeShellScriptBin "tsc" ''
  45. if [ -x "./node_modules/.bin/tsc" ]; then
  46. exec ./node_modules/.bin/tsc "$@"
  47. else
  48. exec ${node-lsp}/lib/node_modules/.bin/tsc "$@"
  49. fi
  50. '';
  51. extraPath = [
  52. fd
  53. ripgrep
  54. html-tidy
  55. node-lsp
  56. tsc
  57. ];
  58. pinnedPlugins = import ./plugins {
  59. inherit buildNeovimPlugin fetchFromGitHub fetchpatch;
  60. };
  61. treesitterPlugins = import ./treesitter {
  62. inherit lib runCommand fetchFromGitHub tree-sitter;
  63. };
  64. plugins = (builtins.filter (p: !p.optional) (lib.attrValues pinnedPlugins))
  65. ++ (lib.attrValues treesitterPlugins)
  66. ++ [
  67. extra-treesitter-textobjects
  68. ] ++ lib.optionals withPlayground [
  69. pinnedPlugins."nvim-treesitter/playground"
  70. ] ++ lib.optionals withLuadev [
  71. pinnedPlugins."bfredl/nvim-luadev"
  72. ];
  73. generic = { initText ? "", enabledPlugins ? [], passthru ? {} }: stdenv.mkDerivation {
  74. pname = "nvim";
  75. version = neovim-unwrapped.version;
  76. initVim = ''
  77. let g:loaded_python3_provider = 0
  78. let g:loaded_ruby_provider = 0
  79. let g:loaded_node_provider = 0
  80. let g:loaded_perl_provider = 0
  81. set runtimepath^=${placeholder "out"}/lib
  82. set packpath^=${placeholder "out"}/lib
  83. ${initText}
  84. '';
  85. passAsFile = [ "initVim" ];
  86. nativeBuildInputs = [ makeWrapper ];
  87. unpackPhase = ":";
  88. buildPhase = ''
  89. # build pack / runtime dir
  90. mkdir -p lib/pack/nixpkgs/start
  91. ${lib.concatMapStringsSep "\n" (p: ''
  92. ln -s "${p}" "lib/pack/nixpkgs/start/${lib.getName p}"
  93. '') enabledPlugins}
  94. # create config file
  95. mkdir etc
  96. cp "$initVimPath" etc/init.vim
  97. # symlink in man pages
  98. mkdir -p share
  99. ln -s ${neovim-unwrapped}/share/man share/man
  100. # make bin
  101. mkdir bin
  102. makeWrapper ${neovim-unwrapped}/bin/nvim bin/nvim \
  103. --prefix PATH : ${lib.makeBinPath extraPath} \
  104. --add-flags -u \
  105. --add-flags $out/etc/init.vim
  106. '';
  107. inherit passthru;
  108. installPhase = ''
  109. mkdir $out
  110. cp -r * $out
  111. '';
  112. };
  113. in
  114. generic {
  115. initText = ''
  116. source ${./settings.lua}
  117. source ${./plugins.lua}
  118. source ${./mappings.lua}
  119. source ${./autocmd.lua}
  120. source ${./lsp.lua}
  121. source ${./make.lua}
  122. source ${./theme.lua}
  123. '' + lib.optionalString withPlayground ''
  124. source ${./playground.lua}
  125. '' + lib.optionalString withLuadev ''
  126. source ${./luadev.lua}
  127. '';
  128. enabledPlugins = plugins;
  129. passthru = {
  130. minimal = generic {};
  131. };
  132. }