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

From: Liliana Marie Prikler <[email-masked]>
Date: Wed, 22 Jan 2025 19:19:14 +0100

Hi Thiago

Am Montag, dem 20.01.2025 um 19:43 -0300 schrieb Thiago Jung Bauermann:
> 
> 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. 
You quite likely have redundant code in your shell init scripts.  Note
that your Guix profile should already be sourced on Guix System without
adding anything to them.

> 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
> […]

Try replacing nconc with append and see whether it fixes your issue. 
You can reproduce this more easily with

  $ guix shell emacs-pgtk emacs-dash \
         --with-input=emacs-minimal=emacs-pgtk -- \
         sh -c 'source $GUIX_ENVIRONMENT/etc/profile && emacs'

Cheers