gexp: Factorize load-path-setting expression.

* guix/gexp.scm (load-path-expression): New procedure.
(gexp->script): Use it.
This commit is contained in:
Ludovic Courtès 2016-07-04 22:19:23 +02:00
parent 43dcce8674
commit dd8d1a3046
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 14 additions and 12 deletions

View File

@ -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)))))))