Subject: bug#52727: When logged as user, GUILE_LOAD_COMPILED_PATH points to the system cache instead of the user cache

From: Denis 'GNUtoo' Carikli <[email-masked]>
Date: Wed, 22 Dec 2021 01:16:47 +0100

Hi,

When running guix package -i hello as user (gnutoo) I have:
> [gnutoo@primary_laptop ~]$ guix package -i hello
> Backtrace:
> In ice-9/boot-9.scm:
>    222:29 19 (map1 (((gnu packages gnupg)) ((gnu packages golang)) …))
>    222:29 18 (map1 (((gnu packages golang)) ((gnu packages #)) (#) …))
>    222:29 17 (map1 (((gnu packages graphics)) ((gnu packages gtk)) …))
>    222:29 16 (map1 (((gnu packages gtk)) ((gnu packages guile)) (#)
> …)) 222:29 15 (map1 (((gnu packages guile)) ((gnu packages linux)) #
> …)) 222:29 14 (map1 (((gnu packages linux)) ((gnu packages #)) ((…))
> …)) 222:29 13 (map1 (((gnu packages ncurses)) ((gnu packages nss)) #
> …)) 222:29 12 (map1 (((gnu packages nss)) ((gnu packages perl)) (#)
> …)) 222:29 11 (map1 (((gnu packages perl)) ((gnu packages #)) ((…))
> …)) 222:17 10 (map1 (((gnu packages perl-web)) ((gnu packages #)) #
> …)) 3326:17  9 (resolve-interface (gnu packages perl-web) #:select _
> # …) In ice-9/threads.scm:
>     390:8  8 (_ _)
> In ice-9/boot-9.scm:
>   3252:13  7 (_)
> In ice-9/threads.scm:
>     390:8  6 (_ _)
> In ice-9/boot-9.scm:
>   3536:20  5 (_)
>    2835:4  4 (save-module-excursion #<procedure 87f9108 at
> ice-9/boo…>) 3556:26  3 (_)
> In unknown file:
>            2 (primitive-load-path "gnu/packages/perl-web"
> #<procedur…>) In gnu/packages/perl-web.scm:
>      36:5  1 (_)
> In ice-9/boot-9.scm:
>   1685:16  0 (raise-exception _ #:continuable? _)
> 
> ice-9/boot-9.scm:1685:16: In procedure raise-exception:
> Throw to key `record-abi-mismatch-error' with args `(abi-check "~a:
> record ABI mismatch; recompilation needed" (#<record-type <origin>>)
> ())'.

However that works fine with sudo su:
> [gnutoo@primary_laptop ~]$ sudo su
> [root@primary_laptop gnutoo]# guix package -i hello
> guix package: warning: Consider running 'guix pull' followed by
> 'guix package -u' to get up-to-date packages and security updates.
> 
> The following package will be installed:
>    hello 2.10
> 
> The following derivation will be built:
>    /gnu/store/ck96mk8hphd9k70a06y8ciqy0p3yp4qa-profile.drv
> 
> 0.1 MB will be downloaded
>  hello-2.10  52KiB
>                             444KiB/s 00:00 [##################]
> 100.0% building CA certificate bundle... listing Emacs
> sub-directories... building fonts directory...
> building directory of Info manuals...
> building profile with 1 package...
> hint: Consider setting the necessary environment variables by running:
> 
>      GUIX_PROFILE="/root/.guix-profile"
>      . "$GUIX_PROFILE/etc/profile"
> 
> Alternately, see `guix package --search-paths -p
> "/root/.guix-profile"'.

As I understand from what I was told on #guix, when running sudo su,
guix comes from the system:
> [root@primary_laptop ~]# which guix
> /run/current-system/profile/bin/guix

Whereas when running it from the user, it doesn't:
> [gnutoo@primary_laptop ~]$ which guix
> /home/gnutoo/.config/guix/current/bin/guix

And as user GUILE_LOAD_COMPILED_PATH is somehow exported to system
paths:
> [gnutoo@primary_laptop ~]$ echo $GUILE_LOAD_COMPILED_PATH
> /run/current-system/profile/lib/guile/3.0/site-ccache:/run/current-system/profile/share/guile/site/3.0

So if I instead set it to the right paths it works again:
> [gnutoo@primary_laptop guix]$ export
> GUILE_LOAD_COMPILED_PATH="/home/gnutoo/.config/guix/current/lib/guile/3.0/site-ccache:/home/gnutoo/.config/guix/current/share/guile/site/3.0"
> [gnutoo@primary_laptop guix]$ guix package -i hello
> The following package will be upgraded:
>    hello (dependencies or package changed)
> 
> nothing to be done

'GUILE_LOAD_COMPILED_PATH="" guix package -i hello' also works.

In my case the issue is that having
'/run/current-system/profile/lib/guile/3.0/site-ccache' in
GUILE_LOAD_COMPILED_PATH makes it fail:
> [gnutoo@primary_laptop guix]$ export
> GUILE_LOAD_COMPILED_PATH=/run/current-system/profile/lib/guile/3.0/site-ccache
> [gnutoo@primary_laptop guix]$ guix package -i hello Backtrace:
> In ice-9/boot-9.scm:
>    222:29 19 (map1 (((gnu packages gnupg)) ((gnu packages golang)) …))
[...]

And apparently it fails just because it is in the path:
> [gnutoo@primary_laptop guix]$ export
> GUILE_LOAD_COMPILED_PATH="/home/gnutoo/.config/guix/current/lib/guile/3.0/site-ccache:/home/gnutoo/.config/guix/current/share/guile/site/3.0:/run/current-system/profile/lib/guile/3.0/site-ccache"
> [gnutoo@primary_laptop guix]$ guix package -i hello Backtrace:
> In ice-9/boot-9.scm:
>    222:29 19 (map1 (((gnu packages gnupg)) ((gnu packages golang)) …))
[...]

This behavior probably happens becuase the system guix wasn't updated
with guix system reconfigure for some time, and that the user relies on
the system guile cache.

And as I understand from #guix on liberachat, I'm supposed to be able
to not keep my user profile and my guix system in sync.

Would the solution to that be to correctly export
GUILE_LOAD_COMPILED_PATH in  ~/.guix-profile/etc/profile like it is
done in the patch I attached (with an extra small modification in the
commit message to mention the bug report)?

Other commits fixing bugs in that same profile mentioned bug reports,
so I assume that it's simplier to discuss the bug in a bug report
than directly sending a patch to fix the issue.

Note that I also didn't test the patch yet but I did test that export
command.

Denis.
From 579e613da312f288aa9b9aebd264794bb9586625 Mon Sep 17 00:00:00 2001
From: Denis 'GNUtoo' Carikli <[email-masked]>
Date: Wed, 22 Dec 2021 00:45:28 +0100
Subject: [PATCH] gnu: system: $GUIX_PROFILE/etc/profile: Fix
 GUILE_LOAD_COMPILED_PATH

* gnu/system.scm (operating-system-etc-service)[profile]: export
  GUILE_LOAD_COMPILED_PATH

Signed-off-by: Denis 'GNUtoo' Carikli <[email-masked]>
---
 gnu/system.scm | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gnu/system.scm b/gnu/system.scm
index 088c62ddde..4dbdf1928e 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -987,6 +987,8 @@ (define* (operating-system-etc-service os)
 # Allow GStreamer-based applications to find plugins.
 export GST_PLUGIN_PATH=\"$HOME/.guix-profile/lib/gstreamer-1.0\"
 
+export GUILE_LOAD_COMPILED_PATH=\"$HOME/.config/guix/current/lib/guile/3.0/site-ccache:$HOME/.config/guix/current/share/guile/site/3.0\"
+
 if [ -n \"$BASH_VERSION\" -a -f /etc/bashrc ]
 then
   # Load Bash-specific initialization code.
-- 
2.34.0