aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-07-04 22:19:23 +0200
committerLudovic Courtès <ludo@gnu.org>2016-07-12 22:47:08 +0200
commitdd8d1a30468dae1412762e54801592f6b475f88e (patch)
treea452600af230d6b387379cf982bc66081c347452
parent43dcce8674d9c7d72db4f3f5aae590cea788d5b4 (diff)
downloadgnu-guix-dd8d1a30468dae1412762e54801592f6b475f88e.tar
gnu-guix-dd8d1a30468dae1412762e54801592f6b475f88e.tar.gz
gexp: Factorize load-path-setting expression.
* guix/gexp.scm (load-path-expression): New procedure. (gexp->script): Use it.
-rw-r--r--guix/gexp.scm26
1 files changed, 14 insertions, 12 deletions
diff --git a/guix/gexp.scm b/guix/gexp.scm
index e9274a05f4..e76a281bba 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -990,6 +990,18 @@ they can refer to each other."
(module-ref (resolve-interface '(gnu packages commencement))
'guile-final))
+(define (load-path-expression modules)
+ "Return as a monadic value a gexp that sets '%load-path' and
+'%load-compiled-path' to point to MODULES, a list of module names."
+ (mlet %store-monad ((modules (imported-modules modules))
+ (compiled (compiled-modules modules)))
+ (return (gexp (eval-when (expand load eval)
+ (set! %load-path
+ (cons (ungexp modules) %load-path))
+ (set! %load-compiled-path
+ (cons (ungexp compiled)
+ %load-compiled-path)))))))
+
(define* (gexp->script name exp
#:key (modules '()) (guile (default-guile)))
"Return an executable script NAME that runs EXP using GUILE with MODULES in
@@ -997,8 +1009,7 @@ its search path."
(define %modules
(append (gexp-modules exp) modules))
- (mlet %store-monad ((modules (imported-modules %modules))
- (compiled (compiled-modules %modules)))
+ (mlet %store-monad ((set-load-path (load-path-expression %modules)))
(gexp->derivation name
(gexp
(call-with-output-file (ungexp output)
@@ -1011,16 +1022,7 @@ its search path."
"#!~a/bin/guile --no-auto-compile~%!#~%"
(ungexp guile))
- ;; Write the 'eval-when' form so that it can be
- ;; compiled.
- (write
- '(eval-when (expand load eval)
- (set! %load-path
- (cons (ungexp modules) %load-path))
- (set! %load-compiled-path
- (cons (ungexp compiled)
- %load-compiled-path)))
- port)
+ (write '(ungexp set-load-path) port)
(write '(ungexp exp) port)
(chmod port #o555)))))))