summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2014-06-14 22:37:24 +0200
committerLudovic Courtès <ludo@gnu.org>2014-06-14 22:55:59 +0200
commit56b821069722c6341e9079299d90ae1cdfe9a916 (patch)
tree31207af9b6ec534010dd03b89f661b93eb936b3a
parenta83c6a6471b0f1950ab5c53acb278e1b88d51c11 (diff)
downloadpatches-56b821069722c6341e9079299d90ae1cdfe9a916.tar
patches-56b821069722c6341e9079299d90ae1cdfe9a916.tar.gz
guix build: Allow gexps to be passed to '-e'.
* guix/ui.scm (%guix-user-module): New variable. (read/eval): Pass it as the second argument to 'eval'. * guix/scripts/build.scm (options/resolve-packages): Add case for 'gexp?'. * tests/guix-build.sh: Add tests. * doc/guix.texi (Invoking guix build): Document '-e gexp'. guxi build: Allow gexps to be passed to '-e'. * guix/ui.scm (%guix-user-module): New variable. (read/eval): Pass it as the second argument to 'eval'. * guix/scripts/build.scm (options/resolve-packages): Add case for 'gexp?'. * tests/guix-build.sh: Add tests. * doc/guix.texi (Invoking guix build): Document '-e gexp'.
-rw-r--r--doc/guix.texi6
-rw-r--r--guix/scripts/build.scm6
-rw-r--r--guix/ui.scm10
-rw-r--r--tests/guix-build.sh4
4 files changed, 24 insertions, 2 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index c1e51eac94..c14272ed9a 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -2244,7 +2244,11 @@ For example, @var{expr} may be @code{(@@ (gnu packages guile)
guile-1.8)}, which unambiguously designates this specific variant of
version 1.8 of Guile.
-Alternately, @var{expr} may refer to a zero-argument monadic procedure
+Alternately, @var{expr} may be a G-expression, in which case it is used
+as a build program passed to @code{gexp->derivation}
+(@pxref{G-Expressions}).
+
+Lastly, @var{expr} may refer to a zero-argument monadic procedure
(@pxref{The Store Monad}). The procedure must return a derivation as a
monadic value, which is then passed through @code{run-with-store}.
diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
index 6d864bfe3b..5e4647de79 100644
--- a/guix/scripts/build.scm
+++ b/guix/scripts/build.scm
@@ -24,6 +24,7 @@
#:use-module (guix packages)
#:use-module (guix utils)
#:use-module (guix monads)
+ #:use-module (guix gexp)
#:use-module (ice-9 format)
#:use-module (ice-9 match)
#:use-module (ice-9 vlist)
@@ -338,6 +339,11 @@ packages."
`(argument . ,p))
((? procedure? proc)
(let ((drv (run-with-store store (proc) #:system system)))
+ `(argument . ,drv)))
+ ((? gexp? gexp)
+ (let ((drv (run-with-store store
+ (gexp->derivation "gexp" gexp
+ #:system system))))
`(argument . ,drv)))))
(opt opt))
opts))
diff --git a/guix/ui.scm b/guix/ui.scm
index 6fef9b36e4..beb41e925a 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -238,6 +238,14 @@ interpreted."
(leave (_ "~a: ~a~%") proc
(apply format #f format-string format-args))))))
+(define %guix-user-module
+ ;; Module in which user expressions are evaluated.
+ (let ((module (make-module)))
+ (beautify-user-module! module)
+ ;; Use (guix gexp) so that one can use #~ & co.
+ (module-use! module (resolve-interface '(guix gexp)))
+ module))
+
(define (read/eval str)
"Read and evaluate STR, raising an error if something goes wrong."
(let ((exp (catch #t
@@ -248,7 +256,7 @@ interpreted."
str args)))))
(catch #t
(lambda ()
- (eval exp the-root-module))
+ (eval exp %guix-user-module))
(lambda args
(leave (_ "failed to evaluate expression `~a': ~s~%")
exp args)))))
diff --git a/tests/guix-build.sh b/tests/guix-build.sh
index e0c774d055..7c6594775a 100644
--- a/tests/guix-build.sh
+++ b/tests/guix-build.sh
@@ -80,3 +80,7 @@ guix build -e "(begin
(gexp->derivation \"test\"
(gexp (mkdir (ungexp output))))))" \
--dry-run
+
+# Running a gexp.
+guix build -e '#~(mkdir #$output)' -d
+guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'