Subject: bug#75709: Emacs fails to start with "List contains a loop" error

From: James Smith <[email-masked]>
Date: Mon, 20 Jan 2025 18:37:30 -0700

Hi,

Thiago Jung Bauermann via Bug reports for GNU Guix <[email-masked]> writes:

> Since a recent "guix pull", Emacs (I tested with the emacs-pgtk package)
> can't start up anymore:
>
> $ emacs
> List contains a loop: ("/home/user/.guix-profile/lib/emacs/native-site-lisp" "/gnu/store/k62mmzkbmivw2r3wwlpcxs3lp9vwjyac-emacs-lsp-mode-9.0.0/lib/emacs/native-site-lisp" "/home/user/.guix-profile/lib/emacs/native-site-lisp" "/home/user/.guix-profile/lib/emacs/native-site-lisp" "/gnu/store/k62mmzkbmivw2r3wwlpcxs3lp9vwjyac-emacs-lsp-mode-9.0.0/lib/emacs/native-site-lisp" . #2)
> $ echo $?
> 255
>
> The root cause of the problem is that I have duplicate path entries in
> these environment variables:
>
> $ env | grep EMACS
> EMACSNATIVELOADPATH=/home/sademeo/.guix-profile/lib/emacs/native-site-lisp:/home/sademeo/.guix-profile/lib/emacs/native-site-lisp
> EMACSLOADPATH=/home/sademeo/.guix-profile/share/emacs/site-lisp:/home/sademeo/.guix-profile/share/emacs/site-lisp
>
> If I remove the duplicate entries, Emacs starts correctly again.
>
> I suppose this is a common problem (it's surprisingly hard to ensure a
> given shell initialization snippet will run only once), and also it's
> hardly a fatal or unrecoverable error. IMHO it should warrant at most a
> warning message (if that), not a complete abort of the program.
>
> With that in mind, I bisected Guix and arrived at this commit:
>
> e9b13294700de7082ee23aa6e1c17b4a8c8828ec is the first bad commit
> commit e9b13294700de7082ee23aa6e1c17b4a8c8828ec
>
>     profiles: emacs-subdirs: Also expand native-comp-eln-load-path.
>
> To reproduce the problem, it's enough to install emacs-pgtk and
> emacs-ccls in your profile. It might be necessary to remove them and
> then install them again, not sure why.
>
> Guix version:
>
> $ guix describe
> Generation 17   jan 20 2025 18:48:17    (current)
>   guix e9b1329
>     repository URL: https://git.savannah.gnu.org/git/guix.git
>     commit: e9b13294700de7082ee23aa6e1c17b4a8c8828ec
>
> It's probably irrelevant, but just for completeness: Guix is installed
> on top of Ubuntu 24.10.

I've encountered the same issue on Guix System, and found that only
duplicate paths in $EMACSNATIVELOADPATH causes this ($EMACSLOADPATH
doesn't seem to be causing any issues).

Here's the relevant variables on my system:
#+begin_src bash
EMACSNATIVELOADPATH=/home/ubuntuxp/.guix-profile/lib/emacs/native-site-lisp:/home/ubuntuxp/.guix-profile/lib/emacs/native-site-lisp:/home/ubuntuxp/.guix-profile/lib/emacs/native-site-lisp
EMACSLOADPATH=/home/ubuntuxp/.guix-profile/share/emacs/site-lisp:/home/ubuntuxp/.guix-profile/share/emacs/site-lisp:/home/ubuntuxp/.guix-profile/share/emacs/site-lisp
#+end_src

James Smith