How to lower a record to the build code ?

2021-05-05 Thread edk
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 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: #< 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 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: #< 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)



Re: How to lower a record to the build code ?

2021-05-05 Thread Christopher Baines

e...@beaver-labs.com writes:

> I've been stuck for a few days on the following:
> Let's say I have a record type:
>
> (define-record-type*  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)

Could you ungexp the record access bits? So something like:

  (string-append #$path " " #$(my-record-first-field rec) " " #$(car
(my-record-second-field rec)) " " #$(cdr (my-record-second-field
rec)))

Obviously, then the handling of rec would just be on the build side.

I'm not quite sure quite what your code looks like, in the example you
give, you've got a number of problems.

Ignoring the #$a-record, you'll need to (mkdir #$output) before trying
to write to a file within that directory.

Secondly, function-of-a-record-and-a-build-time-path isn't defined on
the build side.

If you want to define function-of-a-record-and-a-build-time-path on the
host side, then you could have it return a gexp, something like:

  (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

  (build-gexp
   #~(begin
   (mkdir #$output)
   (with-output-to-file (string-append #$output "/file.txt")
 (lambda _
   (display #$(function-of-a-record-and-a-build-time-path  a-record 
bash))

With these changes, the example you give works for me.


signature.asc
Description: PGP signature


Re: Anyone running Guix on the pinephone?

2021-05-05 Thread raingloom
On Sun, 02 May 2021 12:36:37 -0400
Joshua Branson  wrote:

> Christopher Lemmer Webber  writes:
> 
> > I see the cookbook now mentions the possibility of running Guix on a
> > pinephone... is anyone actually doing it?  Mind posting your
> > experiences and setup?
> >
> > (Doesn't have to be as a phone necessarily... I'm more interested in
> > using it as a lightweight portable computer.  But a phone would be
> > nice too.)  
> 
> Is a pine phone good enough for a portable and personal computer?
> Doesn't it only have 2GB?  I was starting to run into RAM issues with
> 4GB when I was using Gnome.  Now I have 8GB and I am running sway.  No
> RAM issues anymore.
> 
> Just out of curiosity, how would you deal with RAM issues/slow CPU
> issues on a pinephone?  Using a lightweight window manager and only
> run Emacs?  :)
> 
> --
> Joshua Branson (joshuaBPMan in #guix)
> Sent from Emacs and Gnus
>   https://gnucode.me
>   https://video.hardlimit.com/accounts/joshua_branson/video-channels
>   https://propernaming.org
>   "You can have whatever you want, as long as you help
> enough other people get what they want." - Zig Ziglar
> 

Firefox works fine on it, can even compile some software on the device.
The trick is indeed to not run too much RAM eating crap at the same
time, browsers included. I wish Netsurf was more touch friendly and
less buggy.

Also there is a model with more RAM.

What's actually missing is better input. GTK's touch input is still
very far from Android's. Also a lot of apps need to be made more touch
friendly and responsive.

The big issues with Guix would be:
* too much wasted storage space compared to postmarketOS
* much slower guix pull
* no GUI frontend
* lots of missing packages