diff --git a/nvim/bytecompile.nix b/nvim/bytecompile.nix index fff0a33..dd44153 100644 --- a/nvim/bytecompile.nix +++ b/nvim/bytecompile.nix @@ -58,13 +58,12 @@ } ); - byteCompile = plugins: let - byteCompile = p: - (byteCompileLuaDrv p).overrideAttrs ( - prev: lib.optionalAttrs (prev ? dependencies) {dependencies = map byteCompile prev.dependencies;} - ); + byteCompile = p: let + drv = (byteCompileLuaDrv p.plugin).overrideAttrs ( + prev: lib.optionalAttrs (prev ? dependencies) {dependencies = map byteCompile prev.dependencies;} + ); in - map (p: p // {plugin = byteCompile p.plugin;}) plugins; + p // {plugin = drv;}; byteCompileVim = package: pkgs.symlinkJoin { diff --git a/nvim/default.nix b/nvim/default.nix index 684b864..f11d7fc 100644 --- a/nvim/default.nix +++ b/nvim/default.nix @@ -14,16 +14,15 @@ in config = ./.; - plugins = with pkgs.vimPlugins; [ - { - plugin = lz-n; - optional = false; - } - - # TODO: make grammars optional - # nvim-treesitter.withAllGrammars - catppuccin-nvim - ]; + plugins = with pkgs.vimPlugins; { + start = [ + lz-n + catppuccin-nvim + nvim-treesitter.withAllGrammars + ]; + opts = [ + ]; + }; extraPackages = with pkgs; [ # lsp diff --git a/nvim/lua/plugins/colors.lua b/nvim/lua/plugins/colors.lua index 92be842..b22e322 100644 --- a/nvim/lua/plugins/colors.lua +++ b/nvim/lua/plugins/colors.lua @@ -2,6 +2,7 @@ return { { "catppuccin-nvim", -- colorscheme = "catppuccin", + load = function()end, priority = 1000, opt = { integrations = { diff --git a/nvim/mknvim.nix b/nvim/mknvim.nix index f3b916c..8d2482c 100644 --- a/nvim/mknvim.nix +++ b/nvim/mknvim.nix @@ -5,7 +5,10 @@ }: { package ? pkgs.neovim, config, - plugins ? [], + plugins ? { + start = []; + opts = []; + }, extraPackages ? [], extraLuaPackages ? p: [], extraPython3Packages ? p: [], @@ -15,22 +18,19 @@ withNodeJs ? false, withSqlite ? false, }: let - # Stolen from pkgs.neovimUtils.normalizePlugins but this changes defaultPlugin.optional to true. - normalizePlugins = plugins: let + normalize = optional: p: let defaultPlugin = { plugin = null; config = null; - optional = true; + inherit optional; }; in - map (x: - defaultPlugin - // ( - if (x ? plugin) - then x - else {plugin = x;} - )) - plugins; + defaultPlugin + // ( + if (p ? plugin) + then p + else {plugin = p;} + ); initLua = # lua @@ -38,17 +38,22 @@ vim.opt.rtp:remove(vim.fn.stdpath('config')) -- ~/.config/nvim vim.opt.rtp:remove(vim.fn.stdpath('config') .. "/after") -- ~/.config/nvim/after vim.opt.rtp:prepend('${config}') - vim.opt.rtp:prepend('${config}/after') + vim.opt.rtp:append('${config}/after') ${builtins.readFile (config + "/init.lua")} ''; builder = (import ./bytecompile.nix) {inherit pkgs lib;}; + pack = (import ./pack.nix) {inherit pkgs lib;}; nvim = builder.byteCompileVim package; + + start = map (p: lib.pipe p [(normalize false) builder.byteCompile]) plugins.start; + opts = map (p: lib.pipe p [(normalize true) builder.byteCompile]) plugins.opts; + startPacked = pack.packPlugins start; in pkgs.wrapNeovimUnstable nvim { - plugins = builder.byteCompile (normalizePlugins plugins); + plugins = [startPacked] ++ opts; wrapRc = false; wrapperArgs = builtins.concatStringsSep " " [ diff --git a/nvim/pack.nix b/nvim/pack.nix new file mode 100644 index 0000000..17ac479 --- /dev/null +++ b/nvim/pack.nix @@ -0,0 +1,80 @@ +{ + pkgs, + lib, + ... +}: { + packPlugins = plugins: let + # Set option value with default priority so that values are appended by default + pathsToLink = [ + # :h rtp + "/autoload" + "/colors" + "/compiler" + "/doc" + "/ftplugin" + "/indent" + "/keymap" + "/lang" + "/lua" + "/pack" + "/parser" + "/plugin" + "/queries" + "/rplugin" + "/spell" + "/syntax" + "/tutor" + "/after" + "/ftdetect" + # plenary.nvim + "/data/plenary/filetypes" + ]; + + # Every plugin has its own generated help tags (doc/tags) + # Remove them to avoid collisions, new help tags + # will be generate for the entire pack later on + overriddenPlugins = + map ( + plugin: + plugin.plugin.overrideAttrs (prev: { + nativeBuildInputs = lib.remove pkgs.vimUtils.vimGenDocHook prev.nativeBuildInputs or []; + configurePhase = '' + ${prev.configurePhase or ""} + rm -vf doc/tags''; + }) + ) + plugins; + + # Python3 dependencies + python3Dependencies = let + deps = map (p: p.plugin.python3Dependencies or (_: [])) plugins; + in + ps: builtins.concatMap (f: f ps) deps; + + # Combined plugin + combinedPlugin = pkgs.vimUtils.toVimPlugin ( + pkgs.buildEnv { + name = "plugin-pack"; + paths = overriddenPlugins; + inherit pathsToLink; + # Remove empty directories and activate vimGenDocHook + postBuild = '' + find $out -type d -empty -delete + runHook preFixup + ''; + passthru = { + inherit python3Dependencies; + }; + } + ); + + # Combined plugin configs + combinedConfig = builtins.concatStringsSep "\n" ( + builtins.concatMap (x: lib.optional (x.config != null && x.config != "") x.config) plugins + ); + in { + plugin = combinedPlugin; + config = combinedConfig; + optional = false; + }; +}