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'.
This commit is contained in:
Ludovic Courtès 2014-06-14 22:37:24 +02:00
parent a83c6a6471
commit 56b8210697
4 changed files with 24 additions and 2 deletions

View file

@ -2244,7 +2244,11 @@ For example, @var{expr} may be @code{(@@ (gnu packages guile)
guile-1.8)}, which unambiguously designates this specific variant of guile-1.8)}, which unambiguously designates this specific variant of
version 1.8 of Guile. 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 (@pxref{The Store Monad}). The procedure must return a derivation as a
monadic value, which is then passed through @code{run-with-store}. monadic value, which is then passed through @code{run-with-store}.

View file

@ -24,6 +24,7 @@ (define-module (guix scripts build)
#:use-module (guix packages) #:use-module (guix packages)
#:use-module (guix utils) #:use-module (guix utils)
#:use-module (guix monads) #:use-module (guix monads)
#:use-module (guix gexp)
#:use-module (ice-9 format) #:use-module (ice-9 format)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:use-module (ice-9 vlist) #:use-module (ice-9 vlist)
@ -338,6 +339,11 @@ (define system
`(argument . ,p)) `(argument . ,p))
((? procedure? proc) ((? procedure? proc)
(let ((drv (run-with-store store (proc) #:system system))) (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))))) `(argument . ,drv)))))
(opt opt)) (opt opt))
opts)) opts))

View file

@ -238,6 +238,14 @@ (define (call-with-error-handling thunk)
(leave (_ "~a: ~a~%") proc (leave (_ "~a: ~a~%") proc
(apply format #f format-string format-args)))))) (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) (define (read/eval str)
"Read and evaluate STR, raising an error if something goes wrong." "Read and evaluate STR, raising an error if something goes wrong."
(let ((exp (catch #t (let ((exp (catch #t
@ -248,7 +256,7 @@ (define (read/eval str)
str args))))) str args)))))
(catch #t (catch #t
(lambda () (lambda ()
(eval exp the-root-module)) (eval exp %guix-user-module))
(lambda args (lambda args
(leave (_ "failed to evaluate expression `~a': ~s~%") (leave (_ "failed to evaluate expression `~a': ~s~%")
exp args))))) exp args)))))

View file

@ -80,3 +80,7 @@ guix build -e "(begin
(gexp->derivation \"test\" (gexp->derivation \"test\"
(gexp (mkdir (ungexp output))))))" \ (gexp (mkdir (ungexp output))))))" \
--dry-run --dry-run
# Running a gexp.
guix build -e '#~(mkdir #$output)' -d
guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'