unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Josselin Poiret <dev@jpoiret.xyz>
To: Maxime Devos <maximedevos@telenet.be>,
	Brian Cully <bjc@spork.org>,
	guix-devel@gnu.org
Subject: Re: Viewing derivation output in the store
Date: Thu, 21 Apr 2022 09:44:05 +0200	[thread overview]
Message-ID: <87v8v2g9tm.fsf@jpoiret.xyz> (raw)
In-Reply-To: <40e59c1a7b3cd1bb4333b912739688a5146336cb.camel@telenet.be>

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
  #~(begin
      (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
build-derivations)).

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.

Best,
-- 
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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

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

  git send-email \
    --in-reply-to=87v8v2g9tm.fsf@jpoiret.xyz \
    --to=dev@jpoiret.xyz \
    --cc=bjc@spork.org \
    --cc=guix-devel@gnu.org \
    --cc=maximedevos@telenet.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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

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