unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] profiles: Let canonicalize-profile return an absolute path.
@ 2018-07-03 17:59 Roel Janssen
  2018-07-11 11:06 ` Ludovic Courtès
  0 siblings, 1 reply; 4+ messages in thread
From: Roel Janssen @ 2018-07-03 17:59 UTC (permalink / raw)
  To: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1018 bytes --]

Dear Guix,

I'd like to change the way the symlinks to custom profiles are created.
Here's what currently happens:

$ guixr package -i hello -p guix-profiles/test
$ ls -l guix-profiles
lrwxrwxrwx. 1 user group 25 Jul  3 19:53 test -> guix-profiles/test-1-link
lrwxrwxrwx. 1 user group 51 Jul  3 19:53 test-1-link -> /gnu/store/...6qbaps-profile

Now, that symlink is broken.
Instead, I'd like to have it always use absolute paths:

$ guixr package -i hello -p guix-profiles/test
$ ls -l guix-profiles
lrwxrwxrwx 1 roel users 36  3 jul 19:56 test -> /home/user/guix-profiles/test-1-link
lrwxrwxrwx 1 roel users 51  3 jul 19:56 test-1-link -> /gnu/store/...6qbaps-profile

This symlink isn't broken.

In this patch I implemented this behavior by modifying
canonicalize-profile to return an absolute path when it's not
“~/.guix-profile”.

I hope we can merge this, or a similar solution so that creating
profiles in custom locations is a little more robust.

Kind regards,
Roel Janssen


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-profiles-Let-canonicalize-path-return-an-absolute-pa.patch --]
[-- Type: text/x-patch, Size: 1653 bytes --]

From 95178018beb8c5458c154771ac9d1ff4866cc507 Mon Sep 17 00:00:00 2001
From: Roel Janssen <roel@gnu.org>
Date: Tue, 3 Jul 2018 19:49:04 +0200
Subject: [PATCH] profiles: Let canonicalize-profile return an absolute path.

* guix/profiles.scm (canonicalize-profile): Return an absolute path.
---
 guix/profiles.scm | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/guix/profiles.scm b/guix/profiles.scm
index ebd7da2a2..4a6a0a80e 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -1547,8 +1547,8 @@ because the NUMBER is zero.)"
 
 (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>
+return PROFILE as an absolute path.  The goal is to treat '-p ~/.guix-profile'
+as if '-p' was omitted."                       ; see <http://bugs.gnu.org/17939>
 
   ;; Trim trailing slashes so that the basename comparison below works as
   ;; intended.
@@ -1558,7 +1558,10 @@ return PROFILE unchanged.  The goal is to treat '-p ~/.guix-profile' as if
                        (dirname %user-profile-directory))
              (string=? (basename profile) (basename %user-profile-directory)))
         %current-profile
-        profile)))
+        (string-append
+         (canonicalize-path (dirname profile))
+         file-name-separator-string
+         (basename profile)))))
 
 (define (user-friendly-profile profile)
   "Return either ~/.guix-profile if that's what PROFILE refers to, directly or
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] profiles: Let canonicalize-profile return an absolute path.
  2018-07-03 17:59 [PATCH] profiles: Let canonicalize-profile return an absolute path Roel Janssen
@ 2018-07-11 11:06 ` Ludovic Courtès
  2018-07-12 20:53   ` Roel Janssen
  0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2018-07-11 11:06 UTC (permalink / raw)
  To: Roel Janssen; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1333 bytes --]

Hi Roel,

Roel Janssen <roel@gnu.org> skribis:

> I'd like to change the way the symlinks to custom profiles are created.
> Here's what currently happens:
>
> $ guixr package -i hello -p guix-profiles/test
> $ ls -l guix-profiles
> lrwxrwxrwx. 1 user group 25 Jul  3 19:53 test -> guix-profiles/test-1-link
> lrwxrwxrwx. 1 user group 51 Jul  3 19:53 test-1-link -> /gnu/store/...6qbaps-profile
>
> Now, that symlink is broken.
> Instead, I'd like to have it always use absolute paths:

How about instead making the link to the generation file (“test-1-link”)
always a relative symlink?  Like this:

--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env guix package -p foo/x -i sed

[...]

$ ls -l foo/*
lrwxrwxrwx 1 ludo users  8 Jul 11 13:03 foo/x -> x-1-link
lrwxrwxrwx 1 ludo users 51 Jul 11 13:03 foo/x-1-link -> /gnu/store/qp6dqlbsf0pw9p9fwc3gzdcaxx40rn9v-profile
--8<---------------cut here---------------end--------------->8---

Patch below.

FWIW I prefer avoiding ‘canonicalize-path’ in general because it’s
inefficient and because it can surprise the user: you can end up with a
long file name that you didn’t type in, or you can have ENOENT errors
because ‘canonicalize-path’ requires the given file to exist.

WDYT?

Thanks,
Ludo’.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 1680 bytes --]

diff --git a/guix/profiles.scm b/guix/profiles.scm
index d2a794b18..f34f4fcff 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -1521,7 +1521,7 @@ the generation that was current before switching."
                               (profile profile)
                               (generation number)))))
           (else
-           (switch-symlinks profile generation)
+           (switch-symlinks profile (basename generation))
            current))))
 
 (define (switch-to-previous-generation profile)
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 29829f52c..b38a55d01 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -190,7 +190,7 @@ do not treat collisions in MANIFEST as an error."
              (let* ((entries (manifest-entries manifest))
                     (count   (length entries)))
                (switch-symlinks name prof)
-               (switch-symlinks profile name)
+               (switch-symlinks profile (basename name))
                (unless (string=? profile %current-profile)
                  (register-gc-root store name))
                (format #t (N_ "~a package in profile~%"
diff --git a/tests/guix-package.sh b/tests/guix-package.sh
index 3b3fa35cd..3833b568a 100644
--- a/tests/guix-package.sh
+++ b/tests/guix-package.sh
@@ -215,7 +215,7 @@ do
     guix package --bootstrap --roll-back
     ! test -f "$HOME/.guix-profile/bin"
     ! test -f "$HOME/.guix-profile/lib"
-    test "`readlink "$default_profile"`" = "$default_profile-0-link"
+    test "`readlink "$default_profile"`" = "`basename $default_profile-0-link`"
 done
 
 # Check whether '-p ~/.guix-profile' makes any difference.

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] profiles: Let canonicalize-profile return an absolute path.
  2018-07-11 11:06 ` Ludovic Courtès
@ 2018-07-12 20:53   ` Roel Janssen
  2018-07-13 15:33     ` Ludovic Courtès
  0 siblings, 1 reply; 4+ messages in thread
From: Roel Janssen @ 2018-07-12 20:53 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel


Ludovic Courtès <ludo@gnu.org> writes:

> Hi Roel,
>
> Roel Janssen <roel@gnu.org> skribis:
>
>> I'd like to change the way the symlinks to custom profiles are created.
>> Here's what currently happens:
>>
>> $ guixr package -i hello -p guix-profiles/test
>> $ ls -l guix-profiles
>> lrwxrwxrwx. 1 user group 25 Jul  3 19:53 test -> guix-profiles/test-1-link
>> lrwxrwxrwx. 1 user group 51 Jul  3 19:53 test-1-link -> /gnu/store/...6qbaps-profile
>>
>> Now, that symlink is broken.
>> Instead, I'd like to have it always use absolute paths:
>
> How about instead making the link to the generation file (“test-1-link”)
> always a relative symlink?  Like this:
>
> --8<---------------cut here---------------start------------->8---
> $ ./pre-inst-env guix package -p foo/x -i sed
>
> [...]
>
> $ ls -l foo/*
> lrwxrwxrwx 1 ludo users  8 Jul 11 13:03 foo/x -> x-1-link
> lrwxrwxrwx 1 ludo users 51 Jul 11 13:03 foo/x-1-link -> /gnu/store/qp6dqlbsf0pw9p9fwc3gzdcaxx40rn9v-profile
> --8<---------------cut here---------------end--------------->8---
>
> Patch below.
>
> FWIW I prefer avoiding ‘canonicalize-path’ in general because it’s
> inefficient and because it can surprise the user: you can end up with a
> long file name that you didn’t type in, or you can have ENOENT errors
> because ‘canonicalize-path’ requires the given file to exist.
>
> WDYT?
>
> Thanks,
> Ludo’.

I like your patch a lot better than mine!  It fixes the issue I run
into, so it'd be great to apply your patch soon.

There's one other thing I also run into that is somewhat related to
this:
On a multi-user system, where ‘root’ cannot see what's in a user's
directory, it's impossible to keep track of custom profiles.  However,
the default user profiles are fine, because they are actually stored in
the local state dir, and symlinked outside.  Could we do the same with
custom profiles?  The functionality stays the same, it might even be
cleaner in the user's directory because it only needs a single symlink
to the latest generation of a profile, and we might be able to do
garbage collection again on our cluster!

I'd image something like this:

--8<---------------cut here---------------start------------->8---
$ echo $HOME
/home/roel
$ guix package -i hello teeworlds -p ~/my/custom/profile
--> /var/guix/profiles/per-user/roel/home/roel/my/custom/profile -> ...
--> /var/guix/profiles/per-user/roel/home/roel/my/custom/profile-1-link
$ ls -l ~/my/custom
drwxrwxrwx ... profile -> /var/guix/profiles/per-user/roel/home/roel/my/custom/profile
--8<---------------cut here---------------end--------------->8---

That way, if root cannot look into ‘/home/roel’, it can still keep
track of the profile because it can look into ‘/var/guix’.

Kind regards,
Roel Janssen

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] profiles: Let canonicalize-profile return an absolute path.
  2018-07-12 20:53   ` Roel Janssen
@ 2018-07-13 15:33     ` Ludovic Courtès
  0 siblings, 0 replies; 4+ messages in thread
From: Ludovic Courtès @ 2018-07-13 15:33 UTC (permalink / raw)
  To: Roel Janssen; +Cc: guix-devel

Roel Janssen <roel@gnu.org> skribis:

> I like your patch a lot better than mine!  It fixes the issue I run
> into, so it'd be great to apply your patch soon.

Applied as bc6e291ef0b3c71c07e50d88d7764e5dd334e8b1.

> There's one other thing I also run into that is somewhat related to
> this:
> On a multi-user system, where ‘root’ cannot see what's in a user's
> directory, it's impossible to keep track of custom profiles.  However,
> the default user profiles are fine, because they are actually stored in
> the local state dir, and symlinked outside.  Could we do the same with
> custom profiles?  The functionality stays the same, it might even be
> cleaner in the user's directory because it only needs a single symlink
> to the latest generation of a profile, and we might be able to do
> garbage collection again on our cluster!
>
> I'd image something like this:
>
> $ echo $HOME
> /home/roel
> $ guix package -i hello teeworlds -p ~/my/custom/profile
> --> /var/guix/profiles/per-user/roel/home/roel/my/custom/profile -> ...
> --> /var/guix/profiles/per-user/roel/home/roel/my/custom/profile-1-link
> $ ls -l ~/my/custom
> drwxrwxrwx ... profile -> /var/guix/profiles/per-user/roel/home/roel/my/custom/profile
>
> That way, if root cannot look into ‘/home/roel’, it can still keep
> track of the profile because it can look into ‘/var/guix’.

Indeed, that could be a solution on setups such as clusters.

I think you can email it to bug-guix@gnu.org with priority “wishlist.”
:-)

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-07-13 15:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-03 17:59 [PATCH] profiles: Let canonicalize-profile return an absolute path Roel Janssen
2018-07-11 11:06 ` Ludovic Courtès
2018-07-12 20:53   ` Roel Janssen
2018-07-13 15:33     ` Ludovic Courtès

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).