all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: 宋文武 <iyzsong@gmail.com>
Cc: 20255@debbugs.gnu.org
Subject: bug#20255: 'search-paths' should respect both user and system profile.
Date: Mon, 04 May 2015 23:44:19 +0200	[thread overview]
Message-ID: <87lhh43tn0.fsf@gnu.org> (raw)
In-Reply-To: <87d23j1bxk.fsf@gmail.com> ("宋文武"'s message of "Sun, 05 Apr 2015 11:39:03 +0800")

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

宋文武 <iyzsong@gmail.com> skribis:

> Or better to generate a 'profile' script for each manifest, and then
> merged in shell level, so it can work out-of-the-box. How about:
>   - /etc/profile:
>     # configuration for the whole system goes here.
>     # shouldn't refer profile paths.
>     export LANG=en_US.utf8
>     export SSL_CERT_DIR=/etc/ssl/certs
>     export LINUX_MODULE_DIRECTORY=/run/booted-system/kernel/lib/modules
>     [...]
>
>     source /run/current-system/profile/etc/profile
>
>     if [ -f $HOME/.guix-profile/etc/profile ]; then
>       source $HOME/.guix-profile/etc/profile
>     fi
>
>     # honor setuid-programs
>     export PATH=/run/setuid-programs:$PATH
>
>   - /run/current-system/profile/etc/profile:
>     export PATH=/run/current-system/profile/bin:/run/current-system/profile/sbin:$PATH
>     export MANPATH=/run/current-system/profile/share/man:$PATH
>     [...]
>     
>   - ~/.guix-profile/etc/profile:
>     export PATH=~/.guix-profile/bin:~/.guix-profile/sbin:$PATH
>     [...]

There’s a further complication here: ‘profile-derivation’, which builds
the profile, doesn’t know its user-visible name ~/.guix-profile.  It
just knows its store file name.  However, we don’t want etc/profile to
read:

  export PATH=/gnu/store/...-profile/bin:$PATH

because then, the user’s environment variables in a running session
would keep pointing to a given profile generation.

So we have to tell ‘profile-generation’ what the user-visible name of
the profile is going to be.  Attached is a very rough patch to do that.
This is not so nice because all user interfaces will now have to pass
that #:target parameter or etc/profile will be “wrong.”

Another option would be to simply run:

  eval `guix package -p ~/.guix-profile --search-paths`

This has two downsides:

  1. It takes ~200 ms to run on my laptop, which can maybe be
     noticeable; OTOH it’s only for interactive shells, so maybe that’s
     OK.

  2. If there’s a manifest format change and /etc/profile calls a ‘guix’
     command that cannot handle the manifest format (because it’s older
     than the ‘guix’ used to build the profile), then it doesn’t work at
     all (that’s a bit contrived, but not completely impossible.)

Thoughts?

Ludo’.


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

	Modified   guix/profiles.scm
diff --git a/guix/profiles.scm b/guix/profiles.scm
index 8445e00..308dc23 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -582,10 +582,15 @@ MANIFEST.  Single-file bundles are required by programs such as Git and Lynx."
 
 (define* (profile-derivation manifest
                              #:key
+                             target
                              (hooks %default-profile-hooks))
   "Return a derivation that builds a profile (aka. 'user environment') with
 the given MANIFEST.  The profile includes additional derivations returned by
-the monadic procedures listed in HOOKS--such as an Info 'dir' file, etc."
+the monadic procedures listed in HOOKS--such as an Info 'dir' file, etc.
+
+When TARGET is not #f, it must be a string denoting the file name under which
+the profile will be available--e.g., \"/home/rms/.guix-profile\".  This name
+is used in the profile's 'etc/profile' file (read that again.)"
   (mlet %store-monad ((extras (if (null? (manifest-entries manifest))
                                   (return '())
                                   (sequence %store-monad
@@ -598,20 +603,72 @@ the monadic procedures listed in HOOKS--such as an Info 'dir' file, etc."
 
     (define builder
       #~(begin
-          (use-modules (ice-9 pretty-print)
-                       (guix build union))
+          (use-modules (ice-9 match)
+                       (ice-9 regex)
+                       (ice-9 pretty-print)
+                       (guix build union)
+                       (guix build utils)
+                       (guix search-paths))
+
+          (define target
+            '#$target)
+
+          (define search-paths
+            (map sexp->search-path-specification
+                 '#$(map search-path-specification->sexp
+                         (append-map manifest-entry-search-paths
+                                     (manifest-entries manifest)))))
+
+          (define (use-target value separator)
+            (let ((items ((@@ (guix search-paths) string-tokenize*)
+                          value separator)))
+              (string-join (map (lambda (str)
+                                  (string-append target
+                                                 (string-drop str
+                                                              (string-length
+                                                               #$output))))
+                                items)
+                           separator)))
+
+          (define write-environment-variable-definition
+            (match-lambda
+              ((spec . value)
+               (let ((variable (search-path-specification-variable spec))
+                     (sep      (search-path-specification-separator spec)))
+                 (display
+                  (environment-variable-definition variable
+                                                   (if target
+                                                       (use-target value sep)
+                                                       value)
+                                                   #:separator sep
+                                                   #:kind 'prefix))
+                 (newline)))))
 
           (setvbuf (current-output-port) _IOLBF)
           (setvbuf (current-error-port) _IOLBF)
 
+          ;; Make the symlinks.
           (union-build #$output '#$inputs
                        #:log-port (%make-void-port "w"))
+
+          ;; Store meta-data.
           (call-with-output-file (string-append #$output "/manifest")
             (lambda (p)
-              (pretty-print '#$(manifest->gexp manifest) p)))))
+              (pretty-print '#$(manifest->gexp manifest) p)))
+
+          ;; Store a ready-to-use Bash profile.
+          (mkdir-p (string-append #$output "/etc"))
+          (with-output-to-file (string-append #$output "/etc/profile")
+            (lambda ()
+              (let ((variables (evaluate-search-paths search-paths #$output)))
+                (for-each write-environment-variable-definition
+                          variables))))))
 
     (gexp->derivation "profile" builder
-                      #:modules '((guix build union))
+                      #:modules '((guix build union)
+                                  (guix build utils)
+                                  (guix search-paths)
+                                  (guix records))
                       #:local-build? #t)))
 
 (define (profile-regexp profile)
	Modified   guix/scripts/package.scm
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 7f53af7..38ec8ed 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -833,6 +833,7 @@ more information.~%"))
                (let* ((prof-drv (run-with-store (%store)
                                   (profile-derivation
                                    new
+                                   #:target (user-friendly-profile profile)
                                    #:hooks (if bootstrap?
                                                '()
                                                %default-profile-hooks))))


  parent reply	other threads:[~2015-05-04 21:45 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-04 10:29 bug#20255: 'search-paths' should respect both user and system profile 宋文武
2015-04-04 21:04 ` Ludovic Courtès
2015-04-05  3:39   ` 宋文武
2015-04-05 18:15     ` Ludovic Courtès
2015-04-06  4:02       ` 宋文武
2015-04-06  8:24         ` Mark H Weaver
2015-05-02 22:12         ` Ludovic Courtès
2015-11-19 22:32           ` Ludovic Courtès
2015-11-20 22:42             ` Alex Kost
2015-11-21  8:57               ` Ludovic Courtès
2015-11-21 18:41                 ` Alex Kost
2015-11-21 20:10                   ` Ludovic Courtès
2015-11-22  7:52                     ` Alex Kost
2015-11-22 10:52                       ` Ludovic Courtès
2015-11-22 18:44                         ` Alex Kost
2015-11-22 23:04                           ` Ludovic Courtès
2015-11-23 11:55                             ` Alex Kost
2015-11-23 14:31                               ` Ludovic Courtès
2015-11-23 20:07                                 ` Adding operating-system field for a custom /etc/profile Alex Kost
2015-11-24 12:48                                   ` Ludovic Courtès
2015-11-24 19:36                                     ` Alex Kost
2015-11-24 20:30                                       ` Ludovic Courtès
2015-11-30  9:10                                         ` Alex Kost
2015-11-30 13:00                                           ` Ludovic Courtès
2015-11-24 15:22                                   ` 宋文武
2015-11-24 20:03                                     ` Alex Kost
2015-11-27 14:58                                       ` Customizing /etc Ludovic Courtès
2015-11-30  9:11                                         ` Alex Kost
2015-11-27 14:34                                     ` /etc/environment and /etc/profile Ludovic Courtès
2015-11-24 17:22                       ` bug#20255: 'search-paths' should respect both user and system profile Ludovic Courtès
2015-11-30  9:08                         ` Alex Kost
2015-11-30 12:25                           ` Ludovic Courtès
2015-05-04 21:44     ` Ludovic Courtès [this message]
2015-05-05  8:28       ` 宋文武
2015-05-05 12:35         ` Ludovic Courtès
2015-05-06 16:35         ` Ludovic Courtès
2015-11-12 11:13       ` Ludovic Courtès
2020-02-21 15:53 ` bug#20255: (old)bug#20255: 'search-paths' should respect both user and system profiles zimoun
2020-02-21 17:18   ` Alex Kost
2021-06-26  2:37     ` bug#20255: 'search-paths' should respect both user and system profile Maxim Cournoyer
2021-06-26  5:59       ` Leo Prikler
2021-06-28  4:35         ` Maxim Cournoyer
2021-06-28  6:58           ` Leo Prikler
2021-06-27  9:59       ` Alex Kost
2021-06-28  4:48         ` Maxim Cournoyer
2021-06-29 17:29           ` Alex Kost
2020-12-18 20:27   ` bug#20255: «the Oldest» [PATCH] 'search-paths' should respect both user and system profiles zimoun
2023-05-12 12:34     ` bug#20255: 'search-paths' should respect both user and system profile 宋文武 via Bug reports for GNU Guix
2023-05-15 13:53       ` Maxim Cournoyer
2023-05-17 14:12         ` 宋文武
2023-05-15 17:14       ` Josselin Poiret via Bug reports for GNU Guix
2023-05-15 17:46         ` Maxim Cournoyer
2023-05-16  9:37           ` Josselin Poiret via Bug reports for GNU Guix
2023-05-16 11:00             ` 宋文武 via Bug reports for GNU Guix
2023-05-17 14:04 ` bug#20255: [PATCH 1/4] home: shells: Merge search-paths of multiple profiles iyzsong--- via Bug reports for GNU Guix
2023-05-17 14:04   ` bug#20255: [PATCH 2/4] system: default-skeletons: Set up Guix home profile when it exists iyzsong--- via Bug reports for GNU Guix
2023-05-17 14:04   ` bug#20255: [PATCH 3/4] system: Only source system profile's settings in '/etc/profile' iyzsong--- via Bug reports for GNU Guix
2023-05-17 14:04   ` bug#20255: [PATCH 4/4] news: Add entry for '/etc/profile' changes iyzsong--- via Bug reports for GNU Guix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lhh43tn0.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=20255@debbugs.gnu.org \
    --cc=iyzsong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.