From: edk@beaver-labs.com
To: help-guix@gnu.org
Subject: How to lower a record to the build code ?
Date: Wed, 05 May 2021 18:58:17 +0200 [thread overview]
Message-ID: <87eeelglsm.fsf@rdklein.fr> (raw)
Hi,
I've been stuck for a few days on the following:
Let's say I have a record type:
(define-record-type* <my-record> my-record make-my-record
my-record?
this-record
(first-field my-record-first-field)
(second-field my-record-second-field))
And a function that uses such a record, but needs to run on the build
side, because it also needs the store path of a package (I can't edit
this function):
(define (function-of-a-record-and-a-build-time-path rec path)
"Concatenate the path, first, and second field"
(string-append path " " (my-record-first-field rec) " " (car
(my-record-second-field rec)) " " (cdr (my-record-second-field rec))))
How can I use this record in the build side. For example, I'm unable to
build the following G-exp:
(define a-record (my-record
(first-field "first")
(second-field '("second" . "third"))))
#~(with-output-to-file (string-append #$output "/file.txt")
(lambda _
(display (function-of-a-record-and-a-build-time-path #$a-record
#$bash)))))
I expect the gexp to compile to a file in the store whose contents are
/gnu/store/....bash/ first second third
The error is 1. &gexp-input-error: #<<my-record> first-field: "first"
second-field: ("second" . "third")>
I tried to define a gexp-compiler, but I have clearly no idea of what
I'm doing and I could sometimes make it work if I convert the record
into a list, but not if there is a list within that list.
I've read the relevant sections of the manual, and the code, and
basically all instances of a call to define-gexp-compiler in the source
code, but nothing comes close to what I need.
I really could use some help,
Thank you very much,
Edouard.
P.S. here is a minimal not-working example that you can copy paste in
guix repl in order to reproduce my problem:
(use-modules
(guix gexp)
(guix store)
(guix derivations)
(guix records)
(guix monads)
(gnu packages bash))
(define (build-gexp gexp)
"Build GEXP using the local daemon."
(let ((derivation
(run-with-store (open-connection)
(gexp->derivation
"noname"
gexp))))
(build-derivations
(open-connection)
(list derivation))
(derivation-output-path (assoc-ref (derivation-outputs derivation) "out"))))
;; There is a record type that I need on the build side
(define-record-type* <my-record> my-record make-my-record
my-record?
this-record
(first-field my-record-first-field)
(second-field my-record-second-field))
(define a-record (my-record
(first-field "first")
(second-field '("second" . "third"))))
(define (function-of-a-record-and-a-build-time-path rec path)
"Concatenate the path, first, and second field"
(string-append path " " (my-record-first-field rec) " " (car (my-record-second-field rec)) " " (cdr (my-record-second-field rec))))
;; 1. &gexp-input-error: #<<my-record> first-field: "first" second-field: ("second" . "third")>
(build-gexp
#~(with-output-to-file (string-append #$output "/file.txt")
(lambda _
(display (function-of-a-record-and-a-build-time-path #$a-record #$bash)))))
next reply other threads:[~2021-05-05 17:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-05 16:58 edk [this message]
2021-05-05 18:18 ` How to lower a record to the build code ? Christopher Baines
2021-05-07 16:21 ` Edouard Klein
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=87eeelglsm.fsf@rdklein.fr \
--to=edk@beaver-labs.com \
--cc=help-guix@gnu.org \
/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.
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).