[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#26023: [PATCH] gexp: Expose functions to allow creating derivation b

From: Roel Janssen
Subject: bug#26023: [PATCH] gexp: Expose functions to allow creating derivation builders.
Date: Wed, 08 Mar 2017 15:26:27 +0100
User-agent: mu4e 0.9.18; emacs 25.1.1

Ludovic Courtès writes:

> Hello!
> Roel Janssen <address@hidden> skribis:
>> I would like to add the following two functions to the public interface
>> of the gexp module.
>> This makes writing custom derivation builders easier for external
>> projects.
> Out of curiosity, how do you use them?
> I’m asking because they’re not too bad but not too nice an interface
> either, especially ‘load-path-expression’, and I’d expect the use cases
> to be covered by ‘gexp->script’ & ‘gexp->file’.
> Ludo’.

Here's how I use it:

(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))))
          (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~%"
                        (lambda _ (pretty-print '(ungexp set-load-path)))))
              (format port ";; Actual code from the procedure.~%~a~%"
                        (lambda _ (pretty-print '(ungexp exp)))))
              (format port "EOF~%")
              (format port "~a/bin/guile -c \"$CODE\"~%" (ungexp guile))
              (chmod port #o555)))))))))

If you have a suggestion on how to avoid using them, I'd love to hear it.

Kind regards,
Roel Janssen

reply via email to

[Prev in Thread] Current Thread [Next in Thread]