[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to lower a record to the build code ?
From: |
edk |
Subject: |
How to lower a record to the build code ? |
Date: |
Wed, 05 May 2021 18:58:17 +0200 |
User-agent: |
mu4e 1.4.15; emacs 27.1 |
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)))))
- How to lower a record to the build code ?,
edk <=