* Exposing set-load-path and load-path-expression from Gexp.
@ 2017-03-02 13:31 Roel Janssen
0 siblings, 0 replies; only message in thread
From: Roel Janssen @ 2017-03-02 13:31 UTC (permalink / raw)
To: guix-devel
Dear Guix,
To write a derivation builder that can turn a G-expression into a
derivation, it would be handy to expose two functions that are currently
not in the interface of (guix gexp).
Here's an example:
(define* (process->bash-engine-derivation proc #:key (guile (default-guile)))
"Return an executable script that runs the PROCEDURE described in PROC, with
PROCEDURE's imported modules in its search path."
(let ((name (process-full-name proc))
(exp (process-procedure proc))
(out (process-output-path proc)))
(let ((out-str (if out (format #f "(setenv \"out\" ~s)" out) "")))
(mlet %store-monad ((set-load-path
(load-path-expression (gexp-modules exp))))
(gexp->derivation
name
(gexp
(call-with-output-file (ungexp output)
(lambda (port)
(use-modules (ice-9 pretty-print))
(format port "#!~a/bin/bash~%" (ungexp bash))
;; Now that we've written all of the shell code,
;; We can start writing the Scheme code.
;; We rely on Bash for this to work.
(format port "read -d '' CODE <<EOF~%")
;; The destination can be outside of the store.
;; TODO: We have to mount this location when building inside
;; a container.
(format port "~a" (ungexp out-str))
(format port
"~%;; Code to create a proper Guile environment.~%~a~%"
(with-output-to-string
(lambda _ (pretty-print '(ungexp set-load-path)))))
(format port ";; Actual code from the procedure.~%~a~%"
(with-output-to-string
(lambda _ (pretty-print '(ungexp exp)))))
(format port "EOF~%")
(format port "~a/bin/guile -c \"$CODE\"~%" (ungexp guile))
(chmod port #o555)))))))))
Without having set-load-path and load-path-expression, I think it would
be hard (and quite possibly an exact duplicate of the code inside (guix
gexp)) to set up a proper environment for the Guile code to run.
I would like to request exposing these two functions to the public
interface of (guix gexp).
WDYT?
Kind regards,
Roel Janssen
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-03-02 13:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-02 13:31 Exposing set-load-path and load-path-expression from Gexp Roel Janssen
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).