~ruther/guix-local

88371f0d7dcdbb1bd304073257e5214409e89c2f — Ludovic Courtès 11 years ago e84d8b3
guix package: Do the right thing for '-p ~/.guix-profile'.

Fixes <http://bugs.gnu.org/17939>.
Reported by Taylan Ulrich Bayirli/Kammer <taylanbayirli@gmail.com>.

* guix/scripts/package.scm (canonicalize-profile): New procedure.
  (%options): Use it for --profile.
* tests/guix-package.sh: Add test.
2 files changed, 22 insertions(+), 2 deletions(-)

M guix/scripts/package.scm
M tests/guix-package.sh
M guix/scripts/package.scm => guix/scripts/package.scm +12 -1
@@ 68,6 68,17 @@
  ;; coexist with Nix profiles.
  (string-append %profile-directory "/guix-profile"))

(define (canonicalize-profile profile)
  "If PROFILE is %USER-PROFILE-DIRECTORY, return %CURRENT-PROFILE.  Otherwise
return PROFILE unchanged.  The goal is to treat '-p ~/.guix-profile' as if
'-p' was omitted."                           ; see <http://bugs.gnu.org/17939>
  (if (and %user-profile-directory
           (string=? (canonicalize-path (dirname profile))
                     (dirname %user-profile-directory))
           (string=? (basename profile) (basename %user-profile-directory)))
      %current-profile
      profile))

(define (link-to-empty-profile generation)
  "Link GENERATION, a string, to the empty profile."
  (let* ((drv  (profile-derivation (%store) (manifest '())))


@@ 573,7 584,7 @@ Install, remove, or upgrade PACKAGES in a single transaction.\n"))
                           #f)))
         (option '(#\p "profile") #t #f
                 (lambda (opt name arg result arg-handler)
                   (values (alist-cons 'profile arg
                   (values (alist-cons 'profile (canonicalize-profile arg)
                                       (alist-delete 'profile result))
                           #f)))
         (option '(#\n "dry-run") #f #f

M tests/guix-package.sh => tests/guix-package.sh +10 -1
@@ 189,7 189,7 @@ test "`readlink_base "$profile"`" = "$generation"

XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
export XDG_CACHE_HOME
HOME="t-home-$$"
HOME="$PWD/t-home-$$"
export HOME

mkdir -p "$HOME"


@@ 224,6 224,15 @@ do
    test "`readlink "$default_profile"`" = "$default_profile-0-link"
done

# Check whether '-p ~/.guix-profile' makes any difference.
# See <http://bugs.gnu.org/17939>.
if test -e "$HOME/.guix-profile-0-link"; then false; fi
if test -e "$HOME/.guix-profile-1-link"; then false; fi
guix package --bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap
if test -e "$HOME/.guix-profile-1-link"; then false; fi
guix package --bootstrap --roll-back -p "$HOME/.guix-profile"
if test -e "$HOME/.guix-profile-0-link"; then false; fi

# Extraneous argument.
if guix package install foo-bar;
then false; else true; fi