all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Seeking help with g-expressions maze
@ 2024-06-10  4:35 Abbé
  2024-06-10  7:50 ` Christopher Baines
  0 siblings, 1 reply; 3+ messages in thread
From: Abbé @ 2024-06-10  4:35 UTC (permalink / raw)
  To: help-guix


[-- Attachment #1.1: Type: text/plain, Size: 4162 bytes --]

Hi,

I'm trying to implement a guix home service module for rbw, and ended up with following:

----------------8<----------------------8<-----------------------
(define-module (abbe services rbw)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix gexp)
  #:use-module (guix records)
  #:use-module (gnu home services)
  #:use-module (gnu home services xdg)
  #:use-module (gnu services)
  #:use-module (gnu services configuration)
  #:use-module (gnu packages gnupg)
  #:use-module (json)
  #:use-module (ice-9 match)
  #:export  (home-rbw-configuration
             home-rbw-configuration?
             home-rbw-configuration-pinentry-program
             home-rbw-configuration-email
             home-rbw-configuration-base-url
             home-rbw-configuration-identity-url
             home-rbw-configuration-notifications-url
             home-rbw-configuration-client-cert-path
             home-rbw-configuration-sync-interval
             home-rbw-configuration-lock-timeout

             home-rbw-config-files

             home-rbw-service-type))

(define-maybe string)

(define-configuration/no-serialization home-rbw-configuration
  (pinentry-program
   (file-like (file-append pinentry "/bin/pinentry-curses"))
   "Pinentry program to use.")
  (email
   (string "")
   "Email address of the user")
  (base-url
   maybe-string
   "Base URL")
  (identity-url
   maybe-string
   "Identity URL")
  (notifications-url
   maybe-string
   "Notifications URL")
  (client-cert-path
   maybe-string
   "Client certificate path")
  (sync-interval
   (integer 3600)
   "Synchronization interval")
  (lock-timeout
   (integer 3600)
   "Lock timeout"))

(define (home-rbw-config-files config)
  (define (rbw-config config)
    (match-record config <home-rbw-configuration>
                  (pinentry-program email base-url identity-url notifications-url
                                    client-cert-path sync-interval lock-timeout)
                  `((pinentry-program . ,pinentry-program)
                    (email . ,email)
                    (base_url . ,base-url)
                    (identity_url . ,identity-url)
                    (notifications_url . ,notifications-url)
                    (client_cert_path . ,client-cert-path)
                    (sync_interval . ,sync-interval)
                    (lock_timeout . ,lock-timeout))))
  (define (home-rbw-configuration-file config)
    (let ((xformed-config (rbw-config config)))
      (computed-file "rbw-config.json" 

                     #~(call-with-output-file #$output
                         (lambda (port)
                           (display #$(scm->json-string xformed-config) port))))))
  `(("rbw/config.json" ,(home-rbw-configuration-file config))))

(define home-rbw-service-type
  (service-type
   (name 'home-rbw)
   (extensions
    (list (service-extension home-xdg-configuration-files-service-type
                             home-rbw-config-files)))
   (default-value (home-rbw-configuration))
   (description
    "Configure rbw")))
----------------8<----------------------8<-----------------------

While applying this module, I end up with following obvious error, but I'm not quite sure how to go about resolving this:

----------------8<----------------------8<-----------------------
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Throw to key `json-invalid' with args `(#<file-append #<package pinentry@1.2.1 gnu/packages/gnupg.scm:1016 7df6139219a0> "/bin/pinentry-curses">)'.
----------------8<----------------------8<-----------------------

Following is the service definition I'm using in my home configuration:

----------------8<----------------------8<-----------------------
     (service home-rbw-service-type
              (home-rbw-configuration))
----------------8<----------------------8<-----------------------

I'm coming from nix background, documentation on G Expressions documentation seem a bit overwhelming, akin to Haskell for a C programmer.

Any help will be appreciated.

Thanks!
--
Abbe

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 249 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Seeking help with g-expressions maze
  2024-06-10  4:35 Seeking help with g-expressions maze Abbé
@ 2024-06-10  7:50 ` Christopher Baines
  2024-06-10 23:23   ` Abbé
  0 siblings, 1 reply; 3+ messages in thread
From: Christopher Baines @ 2024-06-10  7:50 UTC (permalink / raw)
  To: Abbé; +Cc: help-guix

[-- Attachment #1: Type: text/plain, Size: 2461 bytes --]

Abbé <gnu.bonfire@p.atriar.ch> writes:

> (define-configuration/no-serialization home-rbw-configuration
>   (pinentry-program
>    (file-like (file-append pinentry "/bin/pinentry-curses"))
>    "Pinentry program to use.")
>   (email
>    (string "")
>    "Email address of the user")

...

>   (define (rbw-config config)
>     (match-record config <home-rbw-configuration>
>                   (pinentry-program email base-url identity-url notifications-url
>                                     client-cert-path sync-interval lock-timeout)
>                   `((pinentry-program . ,pinentry-program)
>                     (email . ,email)
>                     (base_url . ,base-url)
>                     (identity_url . ,identity-url)
>                     (notifications_url . ,notifications-url)
>                     (client_cert_path . ,client-cert-path)
>                     (sync_interval . ,sync-interval)
>                     (lock_timeout . ,lock-timeout))))
>   (define (home-rbw-configuration-file config)
>     (let ((xformed-config (rbw-config config)))
>       (computed-file "rbw-config.json" 
>
>                      #~(call-with-output-file #$output
>                          (lambda (port)
>                            (display #$(scm->json-string xformed-config) port))))))

Here you're calling scm->json-string on an alist containing the
file-append record for pinentry-program. scm->json-string doesn't know
how to handle that, it's invalid. Hence the exception you're getting.

>   `(("rbw/config.json" ,(home-rbw-configuration-file config))))

...

> While applying this module, I end up with following obvious error, but
> I'm not quite sure how to go about resolving this:
>
> ----------------8<----------------------8<-----------------------
> ice-9/boot-9.scm:1685:16: In procedure raise-exception:
> Throw to key `json-invalid' with args `(#<file-append #<package pinentry@1.2.1 gnu/packages/gnupg.scm:1016 7df6139219a0> "/bin/pinentry-curses">)'.
> ----------------8<----------------------8<-----------------------

If you want to use scm->json-string, you need to be working with a data
structure it can understand, and it can't understand gexp's. That
suggests you should run it on the build side, once the file-append
record has been transformed in to a string.

I think this would be similar to how the transmission service in Guix
builds it's settings.json file.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 987 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Seeking help with g-expressions maze
  2024-06-10  7:50 ` Christopher Baines
@ 2024-06-10 23:23   ` Abbé
  0 siblings, 0 replies; 3+ messages in thread
From: Abbé @ 2024-06-10 23:23 UTC (permalink / raw)
  To: Christopher Baines; +Cc: help-guix@gnu.org


[-- Attachment #1.1: Type: text/plain, Size: 2430 bytes --]

On Monday, June 10th, 2024 at 9:50 AM, Christopher Baines <mail@cbaines.net> wrote:

> Abbé gnu.bonfire@p.atriar.ch writes:
> 

> > (define-configuration/no-serialization home-rbw-configuration
> > (pinentry-program
> > (file-like (file-append pinentry "/bin/pinentry-curses"))
> > "Pinentry program to use.")
> > (email
> > (string "")
> > "Email address of the user")
> 

> 

> ...
> 

> > (define (rbw-config config)
> > (match-record config <home-rbw-configuration>
> > (pinentry-program email base-url identity-url notifications-url
> > client-cert-path sync-interval lock-timeout)
> > `((pinentry-program . ,pinentry-program)
> > (email . ,email)
> > (base_url . ,base-url)
> > (identity_url . ,identity-url)
> > (notifications_url . ,notifications-url)
> > (client_cert_path . ,client-cert-path)
> > (sync_interval . ,sync-interval)
> > (lock_timeout . ,lock-timeout))))
> > (define (home-rbw-configuration-file config)
> > (let ((xformed-config (rbw-config config)))
> > (computed-file "rbw-config.json"
> > 

> > #~(call-with-output-file #$output
> > (lambda (port)
> > (display #$(scm->json-string xformed-config) port))))))
> 

> 

> Here you're calling scm->json-string on an alist containing the
> 

> file-append record for pinentry-program. scm->json-string doesn't know
> 

> how to handle that, it's invalid. Hence the exception you're getting.
> 

> > `(("rbw/config.json" ,(home-rbw-configuration-file config))))
> 

> 

> ...
> 

> > While applying this module, I end up with following obvious error, but
> > I'm not quite sure how to go about resolving this:
> > 

> > ----------------8<----------------------8<-----------------------
> > ice-9/boot-9.scm:1685:16: In procedure raise-exception:
> > Throw to key `json-invalid' with args` (#<file-append #<package pinentry@1.2.1 gnu/packages/gnupg.scm:1016 7df6139219a0> "/bin/pinentry-curses">)'.
> > ----------------8<----------------------8<-----------------------
> 

> 

> If you want to use scm->json-string, you need to be working with a data
> 

> structure it can understand, and it can't understand gexp's. That
> suggests you should run it on the build side, once the file-append
> record has been transformed in to a string.
> 

> I think this would be similar to how the transmission service in Guix
> builds it's settings.json file.

Thanks for the hint.

Abbe

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 249 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-10 23:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-10  4:35 Seeking help with g-expressions maze Abbé
2024-06-10  7:50 ` Christopher Baines
2024-06-10 23:23   ` Abbé

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.