From 4b868d0de680b378b3f5e24515ceec8b314d0990 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 23 Apr 2024 21:10:39 +0300 Subject: [PATCH 1/3] wrapper/rc: loop over removed runtime paths Would be neat to expose removed paths as a list in the future --- modules/wrapper/rc/options.nix | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/modules/wrapper/rc/options.nix b/modules/wrapper/rc/options.nix index 44199ec..21da8b2 100644 --- a/modules/wrapper/rc/options.nix +++ b/modules/wrapper/rc/options.nix @@ -49,8 +49,17 @@ in { default = []; example = literalExpression '' [ - "$HOME/.config/nvim-extra" # absolute path, as a string - impure - ./nvim # relative path, as a path - pure + # absolute path, as a string - impure + "$HOME/.config/nvim-extra" + + # relative path, as a path - pure + ./nvim + + # source type path - pure and reproducible + (builtins.source { + path = ./runtime; + name = "nvim-runtime"; + }) ] ''; @@ -124,9 +133,15 @@ in { -- Remove default user runtime paths from the -- `runtimepath` option to avoid leaking user configuration -- into the final neovim wrapper - vim.opt.runtimepath:remove(vim.fn.stdpath('config')) -- $HOME/.config/nvim - vim.opt.runtimepath:remove(vim.fn.stdpath('config') .. "/after") -- $HOME/.config/nvim/after - vim.opt.runtimepath:remove(vim.fn.stdpath('data') .. "/site") -- $HOME/.local/share/nvim/site + local defaultRuntimePaths = { + vim.fn.stdpath('config'), -- $HOME/.config/nvim + vim.fn.stdpath('config') .. "/after", -- $HOME/.config/nvim/after + vim.fn.stdpath('data') .. "/site", -- $HOME/.local/share/nvim/site + } + + for _, path in ipairs(defaultRuntimePaths) do + vim.opt.runtimepath:remove(path) + end ''} ${optionalString cfg.enableLuaLoader "vim.loader.enable()"} @@ -134,9 +149,9 @@ in { defaultText = literalMD '' By default, this option will **append** paths in - [vim.additionalRuntimePaths](#opt-vim.additionalRuntimePaths) + [](#opt-vim.additionalRuntimePaths) to the `runtimepath` and enable the experimental Lua module loader - if [vim.enableLuaLoader](#opt-vim.enableLuaLoader) is set to true. + if [](#opt-vim.enableLuaLoader) is set to true. ''; example = literalExpression ''"$${builtins.readFile ./my-lua-config-pre.lua}"''; From 94003faec623b626b1f0e5a712fa6a4907e1ebde Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 26 Apr 2024 12:55:04 +0300 Subject: [PATCH 2/3] init --- modules/default.nix | 12 ++++++++---- modules/wrapper/rc/options.nix | 32 ++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/modules/default.nix b/modules/default.nix index fa72b9b..737fe5c 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -92,8 +92,10 @@ inputs: { extraLuaPackages = ps: map (x: ps.${x}) vimOptions.luaPackages; extraPython3Packages = ps: map (x: ps.${x}) vimOptions.python3Packages; - extraWrapperArgs = - concatStringsSep " " (optional (vimOptions.extraPackages != []) ''--prefix PATH : "${makeBinPath vimOptions.extraPackages}"''); + extraWrapperArgs = concatStringsSep " " (optional (vimOptions.extraPackages != []) '' + --unset XDG_DATA_DIRS \ + --prefix PATH : "${makeBinPath vimOptions.extraPackages}" + ''); # wrap user's desired neovim package with the desired neovim configuration # using wrapNeovimUnstable and makeNeovimConfig from nixpkgs. @@ -119,6 +121,8 @@ in { inherit (module) options config; inherit (module._module.args) pkgs; - # expose wrapped neovim-package - neovim = neovim-wrapped; + # expose wrapped neovim package + neovim = neovim-wrapped.overrideAttrs (old: { + generatedWrapperArgs = (old.generatedWrapperArgs or []) ++ ["--set" "NVIM_APPNAME" "nvf"]; + }); } diff --git a/modules/wrapper/rc/options.nix b/modules/wrapper/rc/options.nix index 21da8b2..ccbadcb 100644 --- a/modules/wrapper/rc/options.nix +++ b/modules/wrapper/rc/options.nix @@ -60,6 +60,13 @@ in { path = ./runtime; name = "nvim-runtime"; }) + + # as a Neovim plugin - pure, reproducible and follows Neovim practices + (pkgs.vimUtils.buildVimPlugin { + pname = "nvim-runtime"; + src = ./nvim-runtime; # needs a plugin/init.lua, can refer to modules in a root level lua/ dir + version = "#"; + }) ] ''; @@ -133,14 +140,27 @@ in { -- Remove default user runtime paths from the -- `runtimepath` option to avoid leaking user configuration -- into the final neovim wrapper - local defaultRuntimePaths = { - vim.fn.stdpath('config'), -- $HOME/.config/nvim - vim.fn.stdpath('config') .. "/after", -- $HOME/.config/nvim/after - vim.fn.stdpath('data') .. "/site", -- $HOME/.local/share/nvim/site - } + local defaultRuntimePaths = {} + local function addPath(path) + table.insert(defaultRuntimePaths, path) + table.insert(defaultRuntimePaths, path .. "/site") + end + + -- Add standard paths to the table + addPath(vim.fn.stdpath('config')) -- $HOME/.config/nvim + addPath(vim.fn.stdpath('data')) -- $HOME/.local/share + addPath(vim.fn.stdpath('state')) -- $HOME/.local/state + addPath(vim.fn.stdpath('cache')) -- $HOME/.cache/nvim + addPath(vim.fn.stdpath('config_dirs')) + addPath(vim.fn.stdpath('data_dirs')) for _, path in ipairs(defaultRuntimePaths) do - vim.opt.runtimepath:remove(path) + -- Check if the path exists in runtimepath before removing it + if vim.fn.index(vim.opt.runtimepath, path) >= 0 then + vim.opt.runtimepath:remove(path) + else + print("Path does not exist in runtimepath:", path) + end end ''} From 32d17bcc158291eaeca6f33c9af1fda545760f19 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 30 Apr 2024 08:03:13 +0300 Subject: [PATCH 3/3] reduce table size --- modules/wrapper/rc/options.nix | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/modules/wrapper/rc/options.nix b/modules/wrapper/rc/options.nix index ccbadcb..51e6281 100644 --- a/modules/wrapper/rc/options.nix +++ b/modules/wrapper/rc/options.nix @@ -147,20 +147,14 @@ in { end -- Add standard paths to the table - addPath(vim.fn.stdpath('config')) -- $HOME/.config/nvim - addPath(vim.fn.stdpath('data')) -- $HOME/.local/share - addPath(vim.fn.stdpath('state')) -- $HOME/.local/state - addPath(vim.fn.stdpath('cache')) -- $HOME/.cache/nvim - addPath(vim.fn.stdpath('config_dirs')) - addPath(vim.fn.stdpath('data_dirs')) + addPath(vim.fn.stdpath('config')) -- $XDG_CONFIG_HOME + addPath(vim.fn.stdpath('data')) -- $XDG_DATA_HOME + addPath(vim.fn.stdpath('state')) -- $XDG_STATE_HOME + addPath(vim.fn.stdpath('cache')) -- $XDG_CACHE_HOME + -- Remove paths that are already in runtimepath for _, path in ipairs(defaultRuntimePaths) do - -- Check if the path exists in runtimepath before removing it - if vim.fn.index(vim.opt.runtimepath, path) >= 0 then - vim.opt.runtimepath:remove(path) - else - print("Path does not exist in runtimepath:", path) - end + vim.opt.runtimepath:remove(path) end ''}