1
0

neovim.nix 3.4 KB

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