Subject: bug#42983: "sudo -E guix pull" breaks ~/.config/guix/current for regular user

From: Ludovic Courtès <[email-masked]>
Date: Fri, 28 Aug 2020 15:41:05 +0200

Hi Danny,

Danny Milosavljevic <[email-masked]> skribis:

> The culprit, I think, is this:
>
> (define (ensure-default-profile)
>   (ensure-profile-directory)
>
>   ;; In 0.15.0+ we'd create ~/.config/guix/current-[0-9]*-link symlinks.  Move
>   ;; them to %PROFILE-DIRECTORY.
>   ;;
>   ;; XXX: Ubuntu's 'sudo' preserves $HOME by default, and thus the second
>   ;; condition below is always false when one runs "sudo guix pull".  As a
>   ;; workaround, skip this code when $SUDO_USER is set.  See
>   ;; <https://bugs.gnu.org/36785>.
>   (unless (or (getenv "SUDO_USER")
>               (string=? %profile-directory
>                         (dirname
>                          (canonicalize-profile %user-profile-directory))))
>     (migrate-generations %user-profile-directory %profile-directory))
>
> where
>
>   %profile-directory = "/var/guix/profiles/per-user/dannym"
>   %user-profile-directory = "/home/dannym/.config/guix/current" (which is a
> symlink to /var/guix/profiles/per-user/root/current-guix)

We could detect such inconsistencies and emit a warning/hint.  I’m
unsure just how far we need to go in trying to prevent users from
shooting themselves in the foot, though.  Thoughts?

> Ohh, yeah, sudo without "-E" works fine (sudo guix pull, too).

Yes.

Ludo’.