1
0

neovim.nix 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. { lib
  2. , stdenv
  3. , runCommand
  4. , writeShellScriptBin
  5. , neovim-unwrapped
  6. , makeWrapper
  7. , tree-sitter
  8. , fd
  9. , ripgrep
  10. , html-tidy
  11. , typescript
  12. , bash-language-server
  13. , typescript-language-server
  14. , svelte-language-server
  15. , vscode-langservers-extracted
  16. , pyright
  17. , blink-cmp
  18. , fetchFromGitHub
  19. , fetchpatch
  20. }:
  21. let
  22. buildNeovimPlugin = attrs: stdenv.mkDerivation ({
  23. forceShare= [ "man" "info" ];
  24. installPhase = ''
  25. runHook preInstall
  26. cp -r . $out
  27. if [ -d "$out/doc" ]; then
  28. ${neovim-unwrapped}/bin/nvim -N -u NONE -i NONE -n -E -s -V1 -c "helptags $out/doc" +quit!
  29. fi
  30. runHook postInstall
  31. '';
  32. } // attrs);
  33. tsc = writeShellScriptBin "tsc" ''
  34. if [ -x "./node_modules/.bin/tsc" ]; then
  35. exec ./node_modules/.bin/tsc "$@"
  36. else
  37. exec ${typescript}/bin/tsc "$@"
  38. fi
  39. '';
  40. extraPath = [
  41. fd
  42. ripgrep
  43. html-tidy
  44. bash-language-server
  45. typescript-language-server
  46. svelte-language-server
  47. vscode-langservers-extracted
  48. pyright
  49. tsc
  50. ];
  51. pinnedPlugins = import ./plugins {
  52. inherit buildNeovimPlugin fetchFromGitHub fetchpatch;
  53. };
  54. treesitterPlugins = import ./treesitter {
  55. inherit lib runCommand fetchFromGitHub tree-sitter;
  56. };
  57. plugins = (builtins.filter (p: !p.optional) (lib.attrValues pinnedPlugins))
  58. ++ (lib.attrValues treesitterPlugins)
  59. ++ [ blink-cmp ];
  60. optionalPlugins = builtins.filter (p: p.optional) (lib.attrValues pinnedPlugins);
  61. generic = { minimal ? false , startPlugins ? [] , optPlugins ? [] , passthru ? {} }: stdenv.mkDerivation {
  62. pname = "nvim";
  63. version = neovim-unwrapped.version;
  64. initLua = ''
  65. vim.g.loaded_python3_provider = 0
  66. vim.g.loaded_ruby_provider = 0
  67. vim.g.loaded_node_provider = 0
  68. vim.g.loaded_perl_provider = 0
  69. vim.o.runtimepath = table.concat({
  70. '${placeholder "out"}/lib',
  71. vim.env.VIMRUNTIME,
  72. '${placeholder "out"}/lib/after',
  73. }, ',')
  74. vim.o.packpath = table.concat({
  75. '${placeholder "out"}/lib',
  76. vim.env.VIMRUNTIME,
  77. }, ',')
  78. -- make sure docs in our packpath are marked as help
  79. vim.filetype.add({
  80. pattern = {
  81. [os.getenv("VIMRUNTIME"):gsub('[%.%-]', '%%%0') .. '/doc/.*%.txt'] = 'help',
  82. ['.*/pack/.*/doc/.*%.txt'] = 'help',
  83. }
  84. })
  85. ${if minimal then "" else "require('user')"}
  86. '';
  87. passAsFile = [ "initLua" ];
  88. nativeBuildInputs = [ makeWrapper ];
  89. unpackPhase = ":";
  90. buildPhase = ''
  91. # build pack / runtime dir
  92. mkdir -p lib/pack/nixpkgs/start
  93. ${lib.concatMapStringsSep "\n" (p: ''
  94. ln -s "${p}" "lib/pack/nixpkgs/start/${lib.getName p}"
  95. '') startPlugins}
  96. mkdir -p lib/pack/nixpkgs/opt
  97. ${lib.concatMapStringsSep "\n" (p: ''
  98. ln -s "${p}" "lib/pack/nixpkgs/opt/${lib.getName p}"
  99. '') optPlugins}
  100. # copy in config
  101. cp -r ${./config}/. lib/
  102. # create config file
  103. mkdir etc
  104. cp "$initLuaPath" etc/init.lua
  105. # symlink in man pages
  106. mkdir -p share
  107. ln -s ${neovim-unwrapped}/share/man share/man
  108. # make bin
  109. mkdir bin
  110. makeWrapper ${neovim-unwrapped}/bin/nvim bin/nvim \
  111. --prefix PATH : ${lib.makeBinPath extraPath} \
  112. --add-flags -u \
  113. --add-flags $out/etc/init.lua
  114. '';
  115. inherit passthru;
  116. installPhase = ''
  117. mkdir $out
  118. cp -r * $out
  119. '';
  120. };
  121. in
  122. generic {
  123. startPlugins = plugins;
  124. optPlugins = optionalPlugins;
  125. passthru = {
  126. minimal = generic { minimal = true; };
  127. };
  128. }