guix-devel
[Top][All Lists]
Advanced

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

Re: Viewing derivation output in the store


From: Josselin Poiret
Subject: Re: Viewing derivation output in the store
Date: Thu, 21 Apr 2022 09:44:05 +0200

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 via email to

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