aboutsummaryrefslogtreecommitdiff
path: root/guix/build/profiles.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2015-05-06 17:08:00 +0200
committerLudovic Courtès <ludo@gnu.org>2015-05-06 18:26:54 +0200
commitd664f1b431d2a64ff58ddc4ccce40e187947b960 (patch)
tree81dbd7402d8dae149a4899b2734837cfee2eefd3 /guix/build/profiles.scm
parent611adb1ee5814907694abc9afa1bad984f0cbea0 (diff)
downloadgnu-guix-d664f1b431d2a64ff58ddc4ccce40e187947b960.tar
gnu-guix-d664f1b431d2a64ff58ddc4ccce40e187947b960.tar.gz
profiles: Generate an 'etc/profile' file.
Suggested by 宋文武 <iyzsong@gmail.com> in <http://bugs.gnu.org/20255>. * guix/build/profiles.scm (abstract-profile, write-environment-variable-definition): New procedures. (build-profile): Add #:search-paths parameter. Create OUTPUT/etc/profile. * guix/profiles.scm (profile-derivation)[builder]: Add 'search-paths' variable and pass it to 'build-profile'. Adjust #:modules argument. * tests/profiles.scm ("etc/profile"): New test. * doc/guix.texi (Invoking guix package): Mention etc/profile.
Diffstat (limited to 'guix/build/profiles.scm')
-rw-r--r--guix/build/profiles.scm67
1 files changed, 64 insertions, 3 deletions
diff --git a/guix/build/profiles.scm b/guix/build/profiles.scm
index 1c5b54e40b..eda54cb37a 100644
--- a/guix/build/profiles.scm
+++ b/guix/build/profiles.scm
@@ -18,6 +18,10 @@
(define-module (guix build profiles)
#:use-module (guix build union)
+ #:use-module (guix build utils)
+ #:use-module (guix search-paths)
+ #:use-module (srfi srfi-26)
+ #:use-module (ice-9 match)
#:use-module (ice-9 pretty-print)
#:export (build-profile))
@@ -28,14 +32,71 @@
;;;
;;; Code:
+(define (abstract-profile profile)
+ "Return a procedure that replaces PROFILE in VALUE with a reference to the
+'GUIX_PROFILE' environment variable. This allows users to specify what the
+user-friendly name of the profile is, for instance ~/.guix-profile rather than
+/gnu/store/...-profile."
+ (let ((replacement (string-append "${GUIX_PROFILE:-" profile "}")))
+ (match-lambda
+ ((search-path . value)
+ (let* ((separator (search-path-specification-separator search-path))
+ (items (string-tokenize* value separator))
+ (crop (cute string-drop <> (string-length profile))))
+ (cons search-path
+ (string-join (map (lambda (str)
+ (string-append replacement (crop str)))
+ items)
+ separator)))))))
+
+(define (write-environment-variable-definition port)
+ "Write the given environment variable definition to PORT."
+ (match-lambda
+ ((search-path . value)
+ (display (search-path-definition search-path value #:kind 'prefix)
+ port)
+ (newline port))))
+
(define* (build-profile output inputs
- #:key manifest)
+ #:key manifest search-paths)
"Build a user profile from INPUTS in directory OUTPUT. Write MANIFEST, an
-sexp, to OUTPUT/manifest."
+sexp, to OUTPUT/manifest. Create OUTPUT/etc/profile with Bash definitions for
+all the variables listed in SEARCH-PATHS."
+ ;; 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 p))))
+ (pretty-print manifest p)))
+
+ ;; Add a ready-to-use Bash profile.
+ (mkdir-p (string-append output "/etc"))
+ (call-with-output-file (string-append output "/etc/profile")
+ (lambda (port)
+ ;; The use of $GUIX_PROFILE described below is not great. Another
+ ;; option would have been to use "$1" and have users run:
+ ;;
+ ;; source ~/.guix-profile/etc/profile ~/.guix-profile
+ ;;
+ ;; However, when 'source' is used with no arguments, $1 refers to the
+ ;; first positional parameter of the calling scripts, so we can rely on
+ ;; it.
+ (display "\
+# Source this file to define all the relevant environment variables in Bash
+# for this profile. You may want to define the 'GUIX_PROFILE' environment
+# variable to point to the \"visible\" name of the profile, like this:
+#
+# GUIX_PROFILE=/path/to/profile
+# source /path/to/profile/etc/profile
+#
+# When GUIX_PROFILE is undefined, the various environment variables refer
+# to this specific profile generation.
+\n" port)
+ (let ((variables (evaluate-search-paths (cons $PATH search-paths)
+ (list output))))
+ (for-each (write-environment-variable-definition port)
+ (map (abstract-profile output) variables))))))
;;; profile.scm ends here