aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/guix.texi6
-rw-r--r--gnu/system.scm3
-rw-r--r--guix/gexp.scm32
3 files changed, 30 insertions, 11 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index a0014e7112..abd294e886 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -3943,8 +3943,12 @@ script, and @var{modules} is the list of modules visible to that script.
This is the declarative counterpart of @code{gexp->script}.
@end deffn
-@deffn {Monadic Procedure} gexp->file @var{name} @var{exp}
+@deffn {Monadic Procedure} gexp->file @var{name} @var{exp} @
+ [#:set-load-path? #t]
Return a derivation that builds a file @var{name} containing @var{exp}.
+When @var{set-load-path?} is true, emit code in the resulting file to
+set @code{%load-path} and @code{%load-compiled-path} to honor
+@var{exp}'s imported modules.
The resulting file holds references to all the dependencies of @var{exp}
or a subset thereof.
diff --git a/gnu/system.scm b/gnu/system.scm
index 96ea153cd0..a49b3f29b3 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -731,7 +731,8 @@ this file is the reconstruction of GRUB menu entries for old configurations."
(kernel #$(operating-system-kernel os))
(kernel-arguments
#$(operating-system-kernel-arguments os))
- (initrd #$initrd)))))
+ (initrd #$initrd))
+ #:set-load-path? #f)))
;;;
diff --git a/guix/gexp.scm b/guix/gexp.scm
index e76a281bba..60f8905ea4 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -1026,15 +1026,29 @@ its search path."
(write '(ungexp exp) port)
(chmod port #o555)))))))
-(define (gexp->file name exp)
- "Return a derivation that builds a file NAME containing EXP."
- (gexp->derivation name
- (gexp
- (call-with-output-file (ungexp output)
- (lambda (port)
- (write '(ungexp exp) port))))
- #:local-build? #t
- #:substitutable? #f))
+(define* (gexp->file name exp #:key (set-load-path? #t))
+ "Return a derivation that builds a file NAME containing EXP. When
+SET-LOAD-PATH? is true, emit code in the resulting file to set '%load-path'
+and '%load-compiled-path' to honor EXP's imported modules."
+ (match (if set-load-path? (gexp-modules exp) '())
+ (() ;zero modules
+ (gexp->derivation name
+ (gexp
+ (call-with-output-file (ungexp output)
+ (lambda (port)
+ (write '(ungexp exp) port))))
+ #:local-build? #t
+ #:substitutable? #f))
+ ((modules ...)
+ (mlet %store-monad ((set-load-path (load-path-expression modules)))
+ (gexp->derivation name
+ (gexp
+ (call-with-output-file (ungexp output)
+ (lambda (port)
+ (write '(ungexp set-load-path) port)
+ (write '(ungexp exp) port))))
+ #:local-build? #t
+ #:substitutable? #f)))))
(define* (text-file* name #:rest text)
"Return as a monadic value a derivation that builds a text file containing