1
0

neovim.nix 3.5 KB

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