(use-modules (ice-9 match)
             (guix store)
             (guix monads)
             (guix derivations)
             (guix gexp))

(define script
  (program-file "my-hello.scm" #~(display "hello there!")))

;; This is a store computation that lowers the script to a derivation
;; and then builds the derivation.  The computation, when executed in
;; the store monad, returns the file name of the built thing.
(define (build-it thing)
  (mlet* %store-monad
      ((drv (lower-object thing))
       (built (built-derivations (list drv))))
    ;; Return file name of the first output.
    (match (derivation-outputs drv)
      (((_ . output) . rest)
       (return (derivation-output-path output))))))

(with-store store  ; "store" below is a store connection
  (run-with-store store (build-it script)))

Generated by Ricardo Wurmus using scpaste at Wed Feb 3 14:34:35 2021. CET. (original)