浏览代码

nixpkgs/neovim: use our own wrapper

This avoids a lot of cruft that the default wrapper injects.
Thomas Dy 2 年之前
父节点
当前提交
9274c7d96f
共有 1 个文件被更改,包括 88 次插入41 次删除
  1. 88 41
      .config/nixpkgs/neovim/neovim.nix

+ 88 - 41
.config/nixpkgs/neovim/neovim.nix

@@ -1,13 +1,12 @@
 { lib
 , stdenv
 , writeTextFile
-, neovim
 , neovim-unwrapped
+, makeWrapper
 , fd
 , ripgrep
 , node-lsp
 , vimPlugins
-, vimUtils
 , fetchFromGitHub
 , withPlayground ? false
 }:
@@ -23,7 +22,6 @@ let
       fi
     '';
   } // attrs);
-  plugins = import ./plugins.nix { inherit buildNeovimPlugin fetchFromGitHub; };
   extra-treesitter-textobjects = writeTextFile {
     name = "extra-treesitter-textobjects";
     destination = "/after/queries/javascript/textobjects.scm";
@@ -46,43 +44,92 @@ let
     ripgrep
     node-lsp
   ];
-in
-neovim.override {
-  extraMakeWrapperArgs = "--prefix PATH : ${lib.makeBinPath extraPath}";
-  withRuby = false;
-  configure = {
-    customRC = ''
-      source ${./settings.lua}
-      source ${./plugins.lua}
-      source ${./mappings.lua}
-      source ${./autocmd.lua}
-      source ${./lsp.lua}
-      source ${./theme.lua}
-    '' + lib.optionalString withPlayground ''
-      source ${./playground.lua}
-    '';
-    packages.myVimPackage = with vimPlugins; {
-      start = plugins ++ [
-        (nvim-treesitter.withPlugins (p: with p; [
-          tree-sitter-bash
-          tree-sitter-css
-          tree-sitter-elvish
-          tree-sitter-go
-          tree-sitter-javascript
-          tree-sitter-json
-          tree-sitter-lua
-          tree-sitter-nix
-          tree-sitter-ruby
-          tree-sitter-tsx
-          tree-sitter-typescript
-        ] ++ lib.optionals withPlayground [
-          tree-sitter-query
-        ]))
-        extra-treesitter-textobjects
-        extra-tsc-compiler
+
+  nixpkgsPlugins =
+    let
+      # we take nvim-treesitter from nixpkgs as the plugin and grammar versions
+      # must match exactly
+      nvim-treesitter = (vimPlugins.nvim-treesitter.withPlugins (p: with p; [
+        tree-sitter-bash
+        tree-sitter-css
+        tree-sitter-elvish
+        tree-sitter-go
+        tree-sitter-javascript
+        tree-sitter-json
+        tree-sitter-lua
+        tree-sitter-nix
+        tree-sitter-ruby
+        tree-sitter-tsx
+        tree-sitter-typescript
       ] ++ lib.optionals withPlayground [
-        playground
-      ];
-    };
-  };
+        tree-sitter-query
+      ]));
+    in
+    [ nvim-treesitter ] ++ nvim-treesitter.dependencies ++ lib.optionals withPlayground [
+      vimPlugins.playground
+    ];
+
+  plugins = (import ./plugins.nix { inherit buildNeovimPlugin fetchFromGitHub; })
+    ++ nixpkgsPlugins
+    ++ [
+      extra-treesitter-textobjects
+      extra-tsc-compiler
+    ];
+in
+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
+
+    source ${./settings.lua}
+    source ${./plugins.lua}
+    source ${./mappings.lua}
+    source ${./autocmd.lua}
+    source ${./lsp.lua}
+    source ${./theme.lua}
+  '' + lib.optionalString withPlayground ''
+    source ${./playground.lua}
+  '';
+
+  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}"
+    '') plugins}
+
+    # 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
+  '';
+
+  installPhase = ''
+    mkdir $out
+    cp -r * $out
+  '';
 }