Browse Source

nixpkgs/neovim: reorganize configuration

This now puts most of the config into the user lua module rather than
being sourced adhoc
Thomas Dy 3 weeks ago
parent
commit
d4433ff3b2

+ 0 - 0
.config/nixpkgs/neovim/overrides/after/compiler/typescript.lua → .config/nixpkgs/neovim/config/after/compiler/typescript.lua


+ 0 - 0
.config/nixpkgs/neovim/overrides/after/ftplugin/javascript.vim → .config/nixpkgs/neovim/config/after/ftplugin/javascript.vim


+ 0 - 0
.config/nixpkgs/neovim/overrides/after/ftplugin/typescript.vim → .config/nixpkgs/neovim/config/after/ftplugin/typescript.vim


+ 0 - 0
.config/nixpkgs/neovim/overrides/after/ftplugin/typescriptreact.vim → .config/nixpkgs/neovim/config/after/ftplugin/typescriptreact.vim


+ 0 - 0
.config/nixpkgs/neovim/overrides/after/syntax/git.vim → .config/nixpkgs/neovim/config/after/syntax/git.vim


+ 0 - 0
.config/nixpkgs/neovim/autocmd.lua → .config/nixpkgs/neovim/config/lua/user/autocmd.lua


+ 0 - 0
.config/nixpkgs/neovim/commands.lua → .config/nixpkgs/neovim/config/lua/user/commands.lua


+ 7 - 0
.config/nixpkgs/neovim/config/lua/user/init.lua

@@ -0,0 +1,7 @@
+require('user.settings')
+require('user.plugins')
+require('user.mappings')
+require('user.autocmd')
+require('user.lsp')
+require('user.commands')
+require('user.theme')

+ 0 - 0
.config/nixpkgs/neovim/lsp.lua → .config/nixpkgs/neovim/config/lua/user/lsp.lua


+ 3 - 0
.config/nixpkgs/neovim/luadev.lua → .config/nixpkgs/neovim/config/lua/user/luadev.lua

@@ -1,3 +1,6 @@
+vim.cmd.packadd('nvim-luadev')
+
+local opts = { silent = true }
 vim.keymap.set('n', '<Leader>r', '<Plug>(Luadev-Run)', opts)
 vim.keymap.set('v', '<Leader>r', '<Plug>(Luadev-Run)', opts)
 

+ 0 - 0
.config/nixpkgs/neovim/mappings.lua → .config/nixpkgs/neovim/config/lua/user/mappings.lua


+ 0 - 0
.config/nixpkgs/neovim/plugins.lua → .config/nixpkgs/neovim/config/lua/user/plugins.lua


+ 0 - 0
.config/nixpkgs/neovim/settings.lua → .config/nixpkgs/neovim/config/lua/user/settings.lua


+ 0 - 0
.config/nixpkgs/neovim/theme.lua → .config/nixpkgs/neovim/config/lua/user/theme.lua


+ 0 - 1
.config/nixpkgs/neovim/flake.nix

@@ -29,7 +29,6 @@
       in
       {
         packages.neovim = pkgs.callPackage ./neovim.nix {};
-        packages.neovim-with-luadev = pkgs.callPackage ./neovim.nix { withLuadev = true; };
         packages.neovim-minimal = (pkgs.callPackage ./neovim.nix {}).minimal;
         packages.default = self.packages.${system}.neovim;
       }

+ 33 - 35
.config/nixpkgs/neovim/neovim.nix

@@ -13,7 +13,6 @@
 , blink-cmp
 , fetchFromGitHub
 , fetchpatch
-, withLuadev ? false
 }:
 let
   buildNeovimPlugin = attrs: stdenv.mkDerivation ({
@@ -73,24 +72,31 @@ let
     ++ [
       extra-treesitter-textobjects
       blink-cmp
-    ] ++ lib.optionals withLuadev [
-      pinnedPlugins."bfredl/nvim-luadev"
     ];
 
-  generic = { initText ? "", enabledPlugins ? [], passthru ? {} }: stdenv.mkDerivation {
+  optionalPlugins = builtins.filter (p: p.optional) (lib.attrValues pinnedPlugins);
+
+  generic = { minimal ? false , startPlugins ? [] , optPlugins ? [] , 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
+    initLua = ''
+      vim.g.loaded_python3_provider = 0
+      vim.g.loaded_ruby_provider = 0
+      vim.g.loaded_node_provider = 0
+      vim.g.loaded_perl_provider = 0
+
+      vim.o.runtimepath = table.concat({
+        '${placeholder "out"}/lib',
+        vim.env.VIMRUNTIME,
+        '${placeholder "out"}/lib/after',
+      }, ',')
 
-      set runtimepath=${placeholder "out"}/lib,$VIMRUNTIME
-      set packpath=${placeholder "out"}/lib,$VIMRUNTIME
+      vim.o.packpath = table.concat({
+        '${placeholder "out"}/lib',
+        vim.env.VIMRUNTIME,
+      }, ',')
 
-      lua <<EOF
       -- make sure docs in our packpath are marked as help
       vim.filetype.add({
         pattern = {
@@ -98,12 +104,11 @@ let
           ['.*/pack/.*/doc/.*%.txt'] = 'help',
         }
       })
-      EOF
 
-      ${initText}
+      ${if minimal then "" else "require('user')"}
     '';
 
-    passAsFile = [ "initVim" ];
+    passAsFile = [ "initLua" ];
 
     nativeBuildInputs = [ makeWrapper ];
 
@@ -114,15 +119,19 @@ let
       mkdir -p lib/pack/nixpkgs/start
       ${lib.concatMapStringsSep "\n" (p: ''
         ln -s "${p}" "lib/pack/nixpkgs/start/${lib.getName p}"
-      '') enabledPlugins}
+      '') startPlugins}
 
-      # copy in overrides
-      mkdir -p lib/pack/nixpkgs/start
-      cp -r ${./overrides} lib/pack/nixpkgs/start/overrides
+      mkdir -p lib/pack/nixpkgs/opt
+      ${lib.concatMapStringsSep "\n" (p: ''
+        ln -s "${p}" "lib/pack/nixpkgs/opt/${lib.getName p}"
+      '') optPlugins}
+
+      # copy in config
+      cp -r ${./config}/. lib/
 
       # create config file
       mkdir etc
-      cp "$initVimPath" etc/init.vim
+      cp "$initLuaPath" etc/init.lua
 
       # symlink in man pages
       mkdir -p share
@@ -133,7 +142,7 @@ let
       makeWrapper ${neovim-unwrapped}/bin/nvim bin/nvim \
         --prefix PATH : ${lib.makeBinPath extraPath} \
         --add-flags -u \
-        --add-flags $out/etc/init.vim
+        --add-flags $out/etc/init.lua
     '';
 
     inherit passthru;
@@ -145,21 +154,10 @@ let
   };
 in
 generic {
-  initText = ''
-    source ${./settings.lua}
-    source ${./plugins.lua}
-    source ${./mappings.lua}
-    source ${./autocmd.lua}
-    source ${./lsp.lua}
-    source ${./commands.lua}
-    source ${./theme.lua}
-  '' + lib.optionalString withLuadev ''
-    source ${./luadev.lua}
-  '';
-
-  enabledPlugins = plugins;
+  startPlugins = plugins;
+  optPlugins = optionalPlugins;
 
   passthru = {
-    minimal = generic {};
+    minimal = generic { minimal = true; };
   };
 }