unofficial mirror of 
 help / color / mirror / code / Atom feed
From: Josselin Poiret <>
To: Maxime Devos <>,
	Brian Cully <>,
Subject: Re: Viewing derivation output in the store
Date: Thu, 21 Apr 2022 09:44:05 +0200	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

Hello everyone,

Just for completeness' sake, here's my take on it from yesterday while
we were talking about it with Brian:

--8<---------------cut here---------------start------------->8---
(define-module (test)
  #:use-module (guix gexp)
  #:use-module (guix monads)
  #:use-module (guix derivations)
  #:use-module (guix store))

(define test-gexp
      (copy-file #$(plain-file "helloes.txt" "contents") #$output)
      (format #t "Helloes~%")))

(with-store store
  (run-with-store store
    (mlet* %store-monad
        ((drv (gexp->derivation "myderivation" test-gexp))
         (output -> (derivation->output-path drv)))
      (mbegin %store-monad
        (built-derivations (list drv))
        (return (format #t "~a~%" output))))))
--8<---------------cut here---------------end--------------->8---

I tried to use the most monadic approach here to demonstrate its
usefulness, however, it seems to me that derivation->output-path is not
documented, along with built-derivations (which is just (store-lift

Lesson learned: don't shadow gexp (hence `test-gexp`)!

As an aside: is there anything preventing us from having do notation à
la Haskell?  This could help bridge mlet and mbegin with >>=, which in
its current form is impractical.  Here's what it could look like:

--8<---------------cut here---------------start------------->8---
(mdo %store-monad
  (drv <- (gexp-derivation "myderivation" test-gexp))
  (output <- (return (derivation->output-path drv)))
  (built-derivations (list drv))
  (return (format #t "~a~%" output)))
--8<---------------cut here---------------end--------------->8---

We could even have some more sugar for (x <- (return y)), Haskell has
`let x = y`, but we could instead have something like `(x := y)`?

If it's okay I could whip up a quick implementation for it, shouldn't be
too hard.

Josselin Poiret

  reply	other threads:[~2022-04-21  8:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-20 15:40 Viewing derivation output in the store Brian Cully
2022-04-20 19:42 ` Maxime Devos
2022-04-21  7:44   ` Josselin Poiret [this message]
2022-04-21 11:50     ` Brian Cully
2022-04-28  7:30     ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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).