Subject: [TRAMP] Tramp/Emacs does not pick up PATH from login shell via Distrobox method
From: Alexis Purslane <[email-masked]>
To: [email-masked]
Date: Thu, 30 May 2024 00:16:26 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

1. Start emacs -Q.
2. Evaluate the forms
    (require 'tramp)
    (load "path/to/tramp-2.7.1/tramp-container.el")
    (tramp-enable-distrobox-method)
3. `cd' to an `/distrobox:' location via eshell, or use find-file to
    open a file through a distrobox so that your default-directory is in
    it.
4. Observe the PATH according to Emacs
5. Then run sh -l in that distrobox (either by doing distrobox enter on
    an external shell, or via eshell). Obeserve the PATH according to
    distrobox.
6. Check the /etc/profile* files inside the distrobox to see which is
    correct.

Example, from inside emacs -Q:

    ~ $ cd /distrobox:rust-latest:.
    /distrobox:rust-latest:~ $ echo $PATH
    /bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
    /distrobox:rust-latest:~ $ sh -l
    $ echo $PATH
    /usr/local/cargo/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
    $ exit
    /distrobox:rust-latest:~ $ cat /distrobox:rust-latest:/etc/profile.d/00-restore-env.sh 
    export PATH=/usr/local/cargo/bin:/usr/local/cargo/bin:$PATH
    /distrobox:rust-latest:~ $ 

This is especially odd, since, looking at the code, I'm seeing that the
distrobox method /should/ be calling sh with -l too, and thus getting
the profile settings. So I'm suspecting something inside emacs is
overriding that.

In GNU Emacs 29.3 (build 1, x86_64-redhat-linux-gnu, GTK+ Version
 3.24.41, cairo version 1.18.0) of 2024-04-25 built on
 cabaf4098b994f6da8ef60f3f6652faa
System Description: Fedora Linux 40.20240529.0 (Silverblue)

Configured using:
 'configure --build=x86_64-redhat-linux-gnu
 --host=x86_64-redhat-linux-gnu --program-prefix=
 --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr
 --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc
 --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64
 --libexecdir=/usr/libexec --localstatedir=/var --runstatedir=/run
 --sharedstatedir=/var/lib --mandir=/usr/share/man
 --infodir=/usr/share/info --with-cairo --with-dbus --with-gif
 --with-gpm=no --with-harfbuzz --with-jpeg --with-json --with-modules
 --with-native-compilation=aot --with-pgtk --with-png --with-rsvg
 --with-sqlite3 --with-tiff --with-tree-sitter --with-webp --with-xpm
 --with-xwidgets build_alias=x86_64-redhat-linux-gnu
 host_alias=x86_64-redhat-linux-gnu CC=gcc 'CFLAGS=-DMAIL_USE_LOCKF -O2
 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches
 -pipe -Wall -Werror=format-security
 -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS
 -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong
 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64
 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection
 -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer '
 LDFLAGS=-Wl,-z,relro
 PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig CXX=g++
 'CXXFLAGS=-O2 -flto=auto -ffat-lto-objects -fexceptions -g
 -grecord-gcc-switches -pipe -Wall -Werror=format-security
 -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS
 -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong
 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64
 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection
 -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer ''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY
PDUMPER PGTK PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XIM XWIDGETS GTK3 ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: ELisp/d

Minor modes in effect:
  eshell-syntax-highlighting-global-mode: t
  global-fish-completion-mode: t
  fish-completion-mode: t
  eat-eshell-mode: t
  gnus-desktop-notify-mode: t
  server-mode: t
  elisp-def-mode: t
  highlight-defined-mode: t
  electric-pair-mode: t
  hl-line-mode: t
  display-line-numbers-mode: t
  outline-minor-mode: t
  diff-hl-mode: t
  corfu-popupinfo-mode: t
  corfu-mode: t
  editorconfig-mode: t
  eldoc-box-hover-at-point-mode: t
  yas-minor-mode: t
  hl-todo-mode: t
  ligature-mode: t
  shell-dirtrack-mode: t
  nerd-icons-completion-mode: t
  mood-line-mode: t
  spacious-padding-mode: t
  global-treesit-auto-mode: t
  global-evil-collection-unimpaired-mode: t
  evil-collection-unimpaired-mode: t
  which-key-mode: t
  marginalia-mode: t
  evil-mode: t
  evil-local-mode: t
  general-override-mode: t
  recentf-mode: t
  icomplete-vertical-mode: t
  icomplete-mode: t
  override-global-mode: t
  savehist-mode: t
  winner-mode: t
  delete-selection-mode: t
  pixel-scroll-precision-mode: t
  cua-mode: t
  apheleia-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  prettify-symbols-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  column-number-mode: t
  line-number-mode: t
  global-visual-line-mode: t
  visual-line-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/var/home/alexispurslane/.emacs.d/elpa/transient-20240525.1118/transient hides /usr/share/emacs/29.3/lisp/transient
/var/home/alexispurslane/.emacs.d/elpa/jsonrpc-1.0.25/jsonrpc hides /usr/share/emacs/29.3/lisp/jsonrpc
~/.quake.d/load/tramp-container hides /usr/share/emacs/29.3/lisp/net/tramp-container

Features:
(shadow sort mail-extr emacsbug evil-collection-vc-git vc-git
mood-line-segment-vc face-remap mule-util pcmpl-unix company-oddmuse
company-keywords company-etags etags fileloop company-gtags
company-dabbrev-code company-dabbrev company-files company-clang
company-capf company-cmake company-semantic company-template
company-bbdb esh-autosuggest evil-collection-company company em-term
em-script em-hist em-pred em-glob em-extpipe em-basic em-banner
eshell-syntax-highlighting em-alias esh-help evil-collection-man man
em-unix fish-completion em-cmpl eshell-prompt-extras em-dirs em-ls
evil-collection-eshell em-prompt eshell esh-var esh-mode
evil-collection-eat eat evil-collection-term term ehelp color esh-cmd
generator esh-ext esh-opt esh-proc esh-io esh-arg esh-module esh-groups
esh-util mood-line-segment-modal gnus-demon nntp gnus-desktop-notify
notifications evil-collection-gnus smtpmail-async async smtpmail
gnus-registry registry eieio-base gnus-art mm-uu mml2015 mm-view
mml-smime smime gnutls dig gnus-sum shr pixel-fill kinsoku url-file svg
dom gnus-group gnus-undo gnus-start gnus-dbus dbus xml gnus-cloud nnimap
nnmail mail-source nnoo gnus-spec gnus-win gnus-int gnus-range message
sendmail yank-media puny evil-collection-dired dired dired-loaddefs
rfc822 mml mml-sec evil-collection-epa epa derived epg rfc6068
epg-config mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047
rfc2045 ietf-drums mailabbrev gmm-utils mailheader imap rfc2104 utf7
gnus nnheader gnus-util text-property-search mail-utils range mm-util
mail-prsvr server elisp-def evil-collection-ert ert
evil-collection-debug debug backtrace evil-collection-xref xref
find-func f s dash highlight-defined elec-pair hl-line
display-line-numbers evil-collection-outline noutline outline
evil-collection-diff-hl diff-hl evil-collection-log-view log-view
pcvs-util evil-collection-vc-dir vc-dir ewoc vc vc-dispatcher
evil-collection-diff-mode diff-mode corfu-popupinfo yasnippet-capf
nerd-icons-corfu evil-collection-corfu corfu editorconfig
editorconfig-core editorconfig-core-handle editorconfig-fnmatch
yasnippet eldoc-box hl-todo ligature project tramp-sh tramp-container
tramp-cache time-stamp tramp tramp-loaddefs trampver tramp-integration
files-x tramp-compat shell pcomplete evil-collection-comint comint
ansi-osc parse-time iso8601 format-spec ansi-color time
nerd-icons-completion evil-collection-dashboard dashboard
dashboard-widgets nerd-icons nerd-icons-faces nerd-icons-data
nerd-icons-data-mdicon nerd-icons-data-flicon nerd-icons-data-codicon
nerd-icons-data-devicon nerd-icons-data-sucicon nerd-icons-data-wicon
nerd-icons-data-faicon nerd-icons-data-powerline nerd-icons-data-octicon
nerd-icons-data-pomicon nerd-icons-data-ipsicon ffap mood-line
spacious-padding doom-gruvbox-theme doom-themes doom-themes-base
treesit-auto evil-textobj-tree-sitter
evil-textobj-tree-sitter-thing-at-point evil-collection-unimpaired
evil-collection-which-key evil-collection-tabulated-list
evil-collection-tab-bar evil-collection-simple evil-collection-replace
evil-collection-process-menu evil-collection-package-menu
evil-collection-info evil-collection-indent evil-collection-help
evil-collection-elisp-mode evil-collection-eldoc evil-collection-custom
evil-collection-buff-menu evil-collection annalist which-key orderless
marginalia compat evil-textobj-tree-sitter-core evil evil-keybindings
evil-integration evil-maps evil-commands reveal evil-jumps
evil-command-window evil-types evil-search evil-ex evil-macros
evil-repeat evil-states evil-core comp comp-cstr warnings advice
evil-common thingatpt rect evil-vars treesit general
use-package-diminish recentf tree-widget icomplete edmacro kmacro
finder-inf use-package-bind-key bind-key disp-table savehist winner
delsel pixel-scroll cua-base ring cus-edit pp cus-load icons wid-edit
cl-extra help-mode time-date use-package-ensure use-package-core rx
apheleia-autoloads easy-mmode async-autoloads breadcrumb-autoloads
consult-notes-autoloads consult-autoloads corfu-autoloads dape-autoloads
darkroom-autoloads dashboard-autoloads denote-autoloads
diff-hl-autoloads doom-themes-autoloads eat-autoloads
editorconfig-autoloads eldoc-box-autoloads elisp-def-autoloads
elisp-demos-autoloads embark-autoloads esh-autosuggest-autoloads
company-autoloads esh-help-autoloads eshell-prompt-extras-autoloads
eshell-syntax-highlighting-autoloads evil-collection-autoloads
annalist-autoloads evil-org-autoloads evil-textobj-tree-sitter-autoloads
fish-completion-autoloads flymake-proselint-autoloads general-autoloads
gnus-desktop-notify-autoloads helpful-autoloads elisp-refs-autoloads
f-autoloads highlight-defined-autoloads hl-todo-autoloads
jsonrpc-autoloads latex-preview-pane-autoloads ligature-autoloads
magit-autoloads pcase git-commit-autoloads magit-section-autoloads
marginalia-autoloads markdown-mode-autoloads mood-line-autoloads
nerd-icons-completion-autoloads nerd-icons-corfu-autoloads
nerd-icons-autoloads orderless-autoloads org-mime-autoloads
org-static-blog-autoloads pandoc-mode-autoloads
spacious-padding-autoloads transient-autoloads treemacs-evil-autoloads
treemacs-autoloads cfrs-autoloads posframe-autoloads ht-autoloads
hydra-autoloads lv-autoloads pfuture-autoloads ace-window-autoloads
avy-autoloads s-autoloads dash-autoloads evil-autoloads
goto-chg-autoloads treesit-auto-autoloads which-key-autoloads
with-editor-autoloads info compat-autoloads yasnippet-capf-autoloads
yasnippet-autoloads package browse-url url url-proxy url-privacy
url-expand url-methods url-history url-cookie generate-lisp-file
url-domsuf url-util mailcap url-handlers url-parse auth-source cl-seq
eieio eieio-core cl-macs password-cache json subr-x map byte-opt gv
bytecomp byte-compile url-vars cl-loaddefs cl-lib rmc iso-transl tooltip
cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/pgtk-win pgtk-win term/common-win pgtk-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq
simple cl-generic indonesian philippine cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite emoji-zwj charscript charprop case-table
epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button
loaddefs theme-loaddefs faces cus-face macroexp files window
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget keymap hashtable-print-readable backquote threads
xwidget-internal dbusbind inotify dynamic-setting system-font-setting
font-render-setting cairo gtk pgtk multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 555112 158275)
 (symbols 48 34237 8)
 (strings 32 135897 9989)
 (string-bytes 1 4706230)
 (vectors 16 68681)
 (vector-slots 8 1363880 92855)
 (floats 8 893 282)
 (intervals 56 2083 512)
 (buffers 984 25))