1
0

neovim.nix 3.2 KB

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