1
0

neovim.nix 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. , withLuadev ? false
  16. }:
  17. let
  18. buildNeovimPlugin = attrs: stdenv.mkDerivation ({
  19. forceShare= [ "man" "info" ];
  20. installPhase = ''
  21. cp -r . $out
  22. if [ -d "$out/doc" ]; then
  23. ${neovim-unwrapped}/bin/nvim -N -u NONE -i NONE -n -E -s -V1 -c "helptags $out/doc" +quit!
  24. fi
  25. '';
  26. } // attrs);
  27. extra-treesitter-textobjects = writeTextFile {
  28. name = "extra-treesitter-textobjects";
  29. destination = "/queries/ecma/textobjects.scm";
  30. text = ''
  31. ;; extends
  32. ; consider array elements as @parameter text objects too
  33. (array
  34. "," @_start .
  35. (_) @parameter.inner
  36. (#make-range! "parameter.outer" @_start @parameter.inner))
  37. (array
  38. . (_) @parameter.inner
  39. . ","? @_end
  40. (#make-range! "parameter.outer" @parameter.inner @_end))
  41. '';
  42. };
  43. tsc = writeShellScriptBin "tsc" ''
  44. if [ -x "./node_modules/.bin/tsc" ]; then
  45. exec ./node_modules/.bin/tsc "$@"
  46. else
  47. exec ${node-lsp}/lib/node_modules/.bin/tsc "$@"
  48. fi
  49. '';
  50. extraPath = [
  51. fd
  52. ripgrep
  53. html-tidy
  54. node-lsp
  55. tsc
  56. ];
  57. pinnedPlugins = import ./plugins {
  58. inherit buildNeovimPlugin fetchFromGitHub fetchpatch;
  59. };
  60. treesitterPlugins = import ./treesitter {
  61. inherit lib runCommand fetchFromGitHub tree-sitter;
  62. };
  63. plugins = (builtins.filter (p: !p.optional) (lib.attrValues pinnedPlugins))
  64. ++ (lib.attrValues treesitterPlugins)
  65. ++ [
  66. extra-treesitter-textobjects
  67. ] ++ lib.optionals withLuadev [
  68. pinnedPlugins."bfredl/nvim-luadev"
  69. ];
  70. generic = { initText ? "", enabledPlugins ? [], passthru ? {} }: stdenv.mkDerivation {
  71. pname = "nvim";
  72. version = neovim-unwrapped.version;
  73. initVim = ''
  74. let g:loaded_python3_provider = 0
  75. let g:loaded_ruby_provider = 0
  76. let g:loaded_node_provider = 0
  77. let g:loaded_perl_provider = 0
  78. set runtimepath=${placeholder "out"}/lib,$VIMRUNTIME
  79. set packpath=${placeholder "out"}/lib
  80. ${initText}
  81. '';
  82. passAsFile = [ "initVim" ];
  83. nativeBuildInputs = [ makeWrapper ];
  84. unpackPhase = ":";
  85. buildPhase = ''
  86. # build pack / runtime dir
  87. mkdir -p lib/pack/nixpkgs/start
  88. ${lib.concatMapStringsSep "\n" (p: ''
  89. ln -s "${p}" "lib/pack/nixpkgs/start/${lib.getName p}"
  90. '') enabledPlugins}
  91. # copy in overrides
  92. mkdir -p lib/pack/nixpkgs/start
  93. cp -r ${./overrides} lib/pack/nixpkgs/start/overrides
  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 withLuadev ''
  124. source ${./luadev.lua}
  125. '';
  126. enabledPlugins = plugins;
  127. passthru = {
  128. minimal = generic {};
  129. };
  130. }