123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- { lib
- , stdenv
- , runCommand
- , writeShellScriptBin
- , writeTextFile
- , neovim-unwrapped
- , makeWrapper
- , tree-sitter
- , fd
- , ripgrep
- , html-tidy
- , node-lsp
- , fetchFromGitHub
- , fetchpatch
- , withPlayground ? false
- , withLuadev ? false
- }:
- let
- buildNeovimPlugin = attrs: stdenv.mkDerivation ({
- forceShare= [ "man" "info" ];
- installPhase = ''
- cp -r . $out
- if [ -d "$out/doc" ]; then
- ${neovim-unwrapped}/bin/nvim -N -u NONE -i NONE -n -E -s -V1 -c "helptags $out/doc" +quit!
- fi
- '';
- } // attrs);
- extra-treesitter-textobjects = writeTextFile {
- name = "extra-treesitter-textobjects";
- destination = "/queries/ecma/textobjects.scm";
- text = ''
- ;; extends
- ; consider array elements as @parameter text objects too
- (array
- "," @_start .
- (_) @parameter.inner
- (#make-range! "parameter.outer" @_start @parameter.inner))
- (array
- . (_) @parameter.inner
- . ","? @_end
- (#make-range! "parameter.outer" @parameter.inner @_end))
- '';
- };
- tsc = writeShellScriptBin "tsc" ''
- if [ -x "./node_modules/.bin/tsc" ]; then
- exec ./node_modules/.bin/tsc "$@"
- else
- exec ${node-lsp}/lib/node_modules/.bin/tsc "$@"
- fi
- '';
- extraPath = [
- fd
- ripgrep
- html-tidy
- node-lsp
- tsc
- ];
- pinnedPlugins = import ./plugins {
- inherit buildNeovimPlugin fetchFromGitHub fetchpatch;
- };
- treesitterPlugins = import ./treesitter {
- inherit lib runCommand fetchFromGitHub tree-sitter;
- };
- plugins = (builtins.filter (p: !p.optional) (lib.attrValues pinnedPlugins))
- ++ (lib.attrValues treesitterPlugins)
- ++ [
- extra-treesitter-textobjects
- ] ++ lib.optionals withPlayground [
- pinnedPlugins."nvim-treesitter/playground"
- ] ++ lib.optionals withLuadev [
- pinnedPlugins."bfredl/nvim-luadev"
- ];
- generic = { initText ? "", enabledPlugins ? [], passthru ? {} }: stdenv.mkDerivation {
- pname = "nvim";
- version = neovim-unwrapped.version;
- initVim = ''
- let g:loaded_python3_provider = 0
- let g:loaded_ruby_provider = 0
- let g:loaded_node_provider = 0
- let g:loaded_perl_provider = 0
- set runtimepath^=${placeholder "out"}/lib
- set packpath^=${placeholder "out"}/lib
- ${initText}
- '';
- passAsFile = [ "initVim" ];
- nativeBuildInputs = [ makeWrapper ];
- unpackPhase = ":";
- buildPhase = ''
- # build pack / runtime dir
- mkdir -p lib/pack/nixpkgs/start
- ${lib.concatMapStringsSep "\n" (p: ''
- ln -s "${p}" "lib/pack/nixpkgs/start/${lib.getName p}"
- '') enabledPlugins}
- # create config file
- mkdir etc
- cp "$initVimPath" etc/init.vim
- # symlink in man pages
- mkdir -p share
- ln -s ${neovim-unwrapped}/share/man share/man
- # make bin
- mkdir bin
- makeWrapper ${neovim-unwrapped}/bin/nvim bin/nvim \
- --prefix PATH : ${lib.makeBinPath extraPath} \
- --add-flags -u \
- --add-flags $out/etc/init.vim
- '';
- inherit passthru;
- installPhase = ''
- mkdir $out
- cp -r * $out
- '';
- };
- in
- generic {
- initText = ''
- source ${./settings.lua}
- source ${./plugins.lua}
- source ${./mappings.lua}
- source ${./autocmd.lua}
- source ${./lsp.lua}
- source ${./make.lua}
- source ${./theme.lua}
- '' + lib.optionalString withPlayground ''
- source ${./playground.lua}
- '' + lib.optionalString withLuadev ''
- source ${./luadev.lua}
- '';
- enabledPlugins = plugins;
- passthru = {
- minimal = generic {};
- };
- }
|