1
0

neovim.nix 3.4 KB

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