1
0

neovim.nix 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. , blink-cmp
  14. , fetchFromGitHub
  15. , fetchpatch
  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. blink-cmp
  68. ];
  69. optionalPlugins = builtins.filter (p: p.optional) (lib.attrValues pinnedPlugins);
  70. generic = { minimal ? false , startPlugins ? [] , optPlugins ? [] , passthru ? {} }: stdenv.mkDerivation {
  71. pname = "nvim";
  72. version = neovim-unwrapped.version;
  73. initLua = ''
  74. vim.g.loaded_python3_provider = 0
  75. vim.g.loaded_ruby_provider = 0
  76. vim.g.loaded_node_provider = 0
  77. vim.g.loaded_perl_provider = 0
  78. vim.o.runtimepath = table.concat({
  79. '${placeholder "out"}/lib',
  80. vim.env.VIMRUNTIME,
  81. '${placeholder "out"}/lib/after',
  82. }, ',')
  83. vim.o.packpath = table.concat({
  84. '${placeholder "out"}/lib',
  85. vim.env.VIMRUNTIME,
  86. }, ',')
  87. -- make sure docs in our packpath are marked as help
  88. vim.filetype.add({
  89. pattern = {
  90. [os.getenv("VIMRUNTIME"):gsub('[%.%-]', '%%%0') .. '/doc/.*%.txt'] = 'help',
  91. ['.*/pack/.*/doc/.*%.txt'] = 'help',
  92. }
  93. })
  94. ${if minimal then "" else "require('user')"}
  95. '';
  96. passAsFile = [ "initLua" ];
  97. nativeBuildInputs = [ makeWrapper ];
  98. unpackPhase = ":";
  99. buildPhase = ''
  100. # build pack / runtime dir
  101. mkdir -p lib/pack/nixpkgs/start
  102. ${lib.concatMapStringsSep "\n" (p: ''
  103. ln -s "${p}" "lib/pack/nixpkgs/start/${lib.getName p}"
  104. '') startPlugins}
  105. mkdir -p lib/pack/nixpkgs/opt
  106. ${lib.concatMapStringsSep "\n" (p: ''
  107. ln -s "${p}" "lib/pack/nixpkgs/opt/${lib.getName p}"
  108. '') optPlugins}
  109. # copy in config
  110. cp -r ${./config}/. lib/
  111. # create config file
  112. mkdir etc
  113. cp "$initLuaPath" etc/init.lua
  114. # symlink in man pages
  115. mkdir -p share
  116. ln -s ${neovim-unwrapped}/share/man share/man
  117. # make bin
  118. mkdir bin
  119. makeWrapper ${neovim-unwrapped}/bin/nvim bin/nvim \
  120. --prefix PATH : ${lib.makeBinPath extraPath} \
  121. --add-flags -u \
  122. --add-flags $out/etc/init.lua
  123. '';
  124. inherit passthru;
  125. installPhase = ''
  126. mkdir $out
  127. cp -r * $out
  128. '';
  129. };
  130. in
  131. generic {
  132. startPlugins = plugins;
  133. optPlugins = optionalPlugins;
  134. passthru = {
  135. minimal = generic { minimal = true; };
  136. };
  137. }