neovim.nix 3.4 KB

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