aboutsummaryrefslogtreecommitdiff
path: root/guix/gexp.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix/gexp.scm')
-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)))))))