Odd behavior of tramp sudo when using nix shell

Hello,

I’m hunting one nasty bug which bother me quite a time.

I have simple shell.nix file:

{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
  buildInputs = with pkgs; [
    xorg.xclock
  ];
}

And corresponding .envrc file:

use nix

Problem become, when I try run sudo command with eshell (with envrc installed). In this case it echo some environment variables and exit without other output, example:

eshell> sudo id
SHELL=/gnu/store/49m5357rhckpn7nvvphfv579i3hzpq8w-bash-5.2.37/bin/bash
SANE_CONFIG_DIR=/gnu/store/gs1f6x82wfc170qh191x3xgfbqy74mk9-sane-backends-1.4.0/etc/sane.d
SUDO_GID=998
GTK_IM_MODULE=xim
LSP_USE_PLISTS=true
LINUX_MODULE_DIRECTORY=/run/booted-system/kernel/lib/modules
INSIDE_EMACS=31.0.50,eat,tramp:2.8.2-pre
SUDO_COMMAND=/gnu/store/49m5357rhckpn7nvvphfv579i3hzpq8w-bash-5.2.37/bin/bash -c /bin/sh -i
...
eshell> 

Emacs configuration to reproduce this (using elpaca):

(elpaca-test
  :interactive t
  :keep t
  :init
  (require 'eshell)
  (require 'esh-module)
  (require 'em-tramp)
  (add-to-list 'eshell-modules-list 'eshell-tramp)
  (elpaca envrc
    (envrc-global-mode +1))
  (add-hook 'elpaca-after-init-hook
            (lambda ()
              (let ((default-directory "~/bin/"))
                (eshell)
                (insert "sudo id")
                (eshell-send-input)))))))

I tested on Guix, Nix machine, with envrc or direnv Emacs package even with doas instead of sudo result is always the same.

Have anyone a clue what could cause this behavior? Or at least confirm it on own machine?

I quickly checked on my guix system and in the context of a folder with use guix in the .envrc it works as expected. I thought to try it out as there is a close family resemblance between nix and guix and might provide a data point.

Thanks for reply. I finally made a minimal example which can be reported to Emacs bug tracker:

(let ((default-directory "/tmp")
      (bad (concat "BAD_VARIABLE=" (make-string 2024 ?x))))
  (require 'eshell)
  (require 'esh-module)
  (require 'em-tramp)
  (add-to-list 'eshell-modules-list 'eshell-tramp)
  (eshell)
  (setq-local process-environment (cl-list* bad bad bad bad process-environment)) ;; should be enough
  (insert "sudo id")
  (eshell-send-input))

It seems environment hit some kind of limit. Guix shell’s are not affected since they export only needed environment variables (thanks to –-search-paths flag)