neovim.nix 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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,$VIMRUNTIME
  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. # copy in overrides
  95. mkdir -p lib/pack/nixpkgs/start
  96. cp -r ${./overrides} lib/pack/nixpkgs/start/overrides
  97. # create config file
  98. mkdir etc
  99. cp "$initVimPath" etc/init.vim
  100. # symlink in man pages
  101. mkdir -p share
  102. ln -s ${neovim-unwrapped}/share/man share/man
  103. # make bin
  104. mkdir bin
  105. makeWrapper ${neovim-unwrapped}/bin/nvim bin/nvim \
  106. --prefix PATH : ${lib.makeBinPath extraPath} \
  107. --add-flags -u \
  108. --add-flags $out/etc/init.vim
  109. '';
  110. inherit passthru;
  111. installPhase = ''
  112. mkdir $out
  113. cp -r * $out
  114. '';
  115. };
  116. in
  117. generic {
  118. initText = ''
  119. source ${./settings.lua}
  120. source ${./plugins.lua}
  121. source ${./mappings.lua}
  122. source ${./autocmd.lua}
  123. source ${./lsp.lua}
  124. source ${./make.lua}
  125. source ${./theme.lua}
  126. '' + lib.optionalString withPlayground ''
  127. source ${./playground.lua}
  128. '' + lib.optionalString withLuadev ''
  129. source ${./luadev.lua}
  130. '';
  131. enabledPlugins = plugins;
  132. passthru = {
  133. minimal = generic {};
  134. };
  135. }