Neovim cannot find plugins (packages) with sudoedit

I remember I start experiencing this issue around NixOS 24.04 was rolling out. Neovim works fine, but when invoked with sudoedit, it won’t be able to find plugins under Nix store:

Error detected while processing /home/hftsai/.dotfiles/xdg_config/nvim/init.lua:                                                                             
E5113: Error while calling lua chunk: vim/_editor.lua:0: /home/hftsai/.dotfiles/xdg_config/nvim/init.lua..nvim_exec2() called at /home/hftsai/.dotfiles/xdg_c
onfig/nvim/init.lua:0: Vim(colorscheme):E185: Cannot find color scheme 'hybrid'

This is the full configuration tree, but I think the relative part of the module (neovim/default.nix) is:

{ config, pkgs, ... }:
let
  inherit (config.lib.file) mkOutOfStoreSymlink;
  inherit (config.home) homeDirectory;

in
{
  xdg.configFile."nvim".source = mkOutOfStoreSymlink "${homeDirectory}/.dotfiles/xdg_config/nvim";

  programs.neovim = {
    enable = true;
    defaultEditor = true;
    plugins = [
      pkgs.vimPlugins.vim-hybrid
    ];
  };
}

Is it because I’m introducing the config LUAs by mkOutOfStoreSymlink, so that some magics are missing when run from sudoedit?

I think this is related to sudoedit which IIRC unsets some variables or prevents loading some config parts we probably rely on.

I recently figured sudoedit is picking up the wrong executable installed with the native OS package manager (/usr/bin/nvim) from $EDITOR=nvim. To do this properly I would have to override this variable from my zsh config:

programs.zsh.initExtra = ''EDITOR=$(which nvim)''

It kinda works but is not very elegant IMO. Apparently sudoedit does not respect PATH set by the user.