From 3fd19f5f59c28689e55b3a7dede942014f9b7fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=96=87=E6=AD=A6?= Date: Fri, 15 Dec 2017 22:20:38 +0800 Subject: [PATCH 1/2] gexp: Add 'eval-gexp'. * guix/gexp.scm (eval-gexp): New procedure. --- guix/gexp.scm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/guix/gexp.scm b/guix/gexp.scm index 1929947d9..678e0c1e6 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -76,6 +76,7 @@ gexp->derivation gexp->file gexp->script + eval-gexp text-file* mixed-text-file file-union @@ -1161,6 +1162,21 @@ and '%load-compiled-path' to honor EXP's imported modules." #:local-build? #t #:substitutable? #f))))) +(define* (eval-gexp exp #:optional (name "value")) + "Return as a monadic value the EXP (a gexp) evaluate to. This is +implemented by building a store file NAME that contains the textual +representation of EXP's value, and then @code{read} from it." + (mlet* %store-monad + ((drv (gexp->derivation + name + (gexp (with-output-to-file (ungexp output) + (lambda () + (write (eval (quote (ungexp exp)) (current-module)))))) + #:local-build? #t + #:substitutable? #t)) + (_ (built-derivations (list drv)))) + (return (call-with-input-file (derivation->output-path drv) read)))) + (define* (text-file* name #:rest text) "Return as a monadic value a derivation that builds a text file containing all of TEXT. TEXT may list, in addition to strings, objects of any type that -- 2.13.3