~abcdw/rde-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
17 3

Udiskie home service and YAML serializer

Details
Message ID
<cover.1678531169.git.contact@conses.eu>
DKIM signature
missing
Download raw message
Hi,

This adds a basic udiskie <https://github.com/coldfix/udiskie> home
service along with some changes to YAML serialization.  I reworked it to
follow the style of the JSON serializer and added some extra bits.

conses (3):
  home: udiskie: Add service.
  gnu: Remove yaml-specific utils.
  serializers: Add yaml.

 src/gnu/home-services-utils.scm   |  53 ----------
 src/rde/home/services/desktop.scm |  83 ++++++++++++++++
 src/rde/serializers/yaml.scm      | 157 ++++++++++++++++++++++++++++++
 3 files changed, 240 insertions(+), 53 deletions(-)
 create mode 100644 src/rde/home/services/desktop.scm
 create mode 100644 src/rde/serializers/yaml.scm

-- 
2.39.1



-- 
Best regards,
conses

[PATCH 1/3] home: udiskie: Add service.

Details
Message ID
<1177296327e55007c87913db3ec9191847a9cb1f.1678531169.git.contact@conses.eu>
In-Reply-To
<cover.1678531169.git.contact@conses.eu> (view parent)
DKIM signature
missing
Download raw message
Patch: +83 -0
---
 src/rde/home/services/desktop.scm | 83 +++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100644 src/rde/home/services/desktop.scm

diff --git a/src/rde/home/services/desktop.scm b/src/rde/home/services/desktop.scm
new file mode 100644
index 00000000..60de6cef
--- /dev/null
+++ b/src/rde/home/services/desktop.scm
@@ -0,0 +1,83 @@
;;; rde --- Reproducible development environment.
;;;
;;; Copyright © 2023 conses <contact@conses.eu>
;;;
;;; This file is part of rde.
;;;
;;; rde is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; rde is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.

(define-module (rde home services desktop)
  #:use-module (gnu services)
  #:use-module (gnu services shepherd)
  #:use-module (gnu services configuration)
  #:use-module (gnu home services)
  #:use-module (gnu home services shepherd)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages freedesktop)
  #:use-module (guix packages)
  #:use-module (guix gexp)
  #:use-module (rde serializers yaml)
  #:export (home-udiskie-configuration
            home-udiskie-service-type))

(define-configuration/no-serialization home-udiskie-configuration
  (udiskie
   (package udiskie)
   "The udiskie package to use.")
  (config
   (yaml-config '())
   "Udiskie configuration."))

(define (home-udiskie-profile-service config)
  (list (home-udiskie-configuration-udiskie config)))

(define (home-udiskie-shepherd-service config)
  (list
   (shepherd-service
    (provision '(udiskie))
    (stop #~(make-kill-destructor))
    (start #~(make-forkexec-constructor
              (list
               #$(file-append
                  (home-udiskie-configuration-udiskie config)
                  "/bin/udiskie")))))))

(define (add-udiskie-configuration config)
  `(("udiskie/config.yml"
     ,(apply mixed-text-file "config.yml"
             (serialize-yaml-config
              (home-udiskie-configuration-config config))))))

(define home-udiskie-service-type
  (service-type
   (name 'udiskie)
   (extensions
    (list
     (service-extension
      home-profile-service-type
      home-udiskie-profile-service)
     (service-extension
      home-shepherd-service-type
      home-udiskie-shepherd-service)
     (service-extension
      home-xdg-configuration-files-service-type
      add-udiskie-configuration)))
   (description "Set up a udiskie daemon to automount removable media.")
   (default-value (home-udiskie-configuration))))

(define (generate-home-udiskie-documentation)
  (generate-documentation
   `((home-udiskie-configuration
      ,home-udiskie-configuration-fields))
   'home-udiskie-configuration))
-- 
2.39.1



-- 
Best regards,
conses

[PATCH 2/3] gnu: Remove yaml-specific utils.

Details
Message ID
<afb23f4cfe6d4f92cc8a5be9658c95c68a844f99.1678531169.git.contact@conses.eu>
In-Reply-To
<cover.1678531169.git.contact@conses.eu> (view parent)
DKIM signature
missing
Download raw message
Patch: +0 -53
---
 src/gnu/home-services-utils.scm | 53 ---------------------------------
 1 file changed, 53 deletions(-)

diff --git a/src/gnu/home-services-utils.scm b/src/gnu/home-services-utils.scm
index eb385691..29aef521 100644
--- a/src/gnu/home-services-utils.scm
+++ b/src/gnu/home-services-utils.scm
@@ -65,9 +65,6 @@
            generic-serialize-ini-config
            generic-serialize-git-ini-config

            yaml-config?
            serialize-yaml-config

            string-or-gexp?
            serialize-string-or-gexp

@@ -300,56 +297,6 @@ elements: the section and the subsection."
        fields)
   "\n"))

(define yaml-config? list?)
(define (make-yaml-indent depth)
  (make-string (* 2 depth) #\space))

(define ((serialize-yaml-value depth) value)
  (let* ((tab (make-yaml-indent depth)))
    (cond
     ((string? value)
      (list (format #f "'~a'" value)))
     ((boolean? value)
      (list (format #f "~a" (if value "true" "false"))))
     ((file-like? value)
      (list value))
     ((alist? value)
      (serialize-yaml-alist value #:depth (1+ depth)))
     ((vector? value)
      (serialize-yaml-vector value #:depth depth))
     (else (list (format #f "~a" value))))))

(define ((serialize-yaml-key depth) key)
  (when (vector? key)
    (raise (formatted-message
            (G_ "Vector as key value are not supported by serializer, \
try to avoid them. ~a") key)))
  ((serialize-yaml-value depth) key))

(define ((serialize-yaml-key-value depth) key value)
  (let ((tab (make-yaml-indent depth)))
    `("\n"
      ,tab
      ,@((serialize-yaml-key depth) key) ": "
      ,@((serialize-yaml-value depth) value))))

(define ((serialize-yaml-vector-elem depth) elem)
  (let ((tab (make-yaml-indent (1+ depth))))
    (cons*
     "\n" tab "- "
     ((serialize-yaml-value (1+ depth)) elem))))

(define* (serialize-yaml-vector vec #:key (depth 0))
  (append-map (serialize-yaml-vector-elem depth) (vector->list vec)))

(define* (serialize-yaml-alist lst #:key (depth 0))
  (generic-serialize-alist append (serialize-yaml-key-value depth) lst))

(define (serialize-yaml-config config)
  "Simplified yaml serializer, which supports only a subset of yaml, use
it with caution."
  (serialize-yaml-alist config))

(define (string-or-gexp? sg) (or (string? sg) (gexp? sg)))
(define (serialize-string-or-gexp field-name val) "")

-- 
2.39.1



-- 
Best regards,
conses

[PATCH 3/3] serializers: Add yaml.

Details
Message ID
<c5c5618dae10768930f4a539a9ae1de894fc7fee.1678531169.git.contact@conses.eu>
In-Reply-To
<cover.1678531169.git.contact@conses.eu> (view parent)
DKIM signature
missing
Download raw message
Patch: +157 -0
---
 src/rde/serializers/yaml.scm | 157 +++++++++++++++++++++++++++++++++++
 1 file changed, 157 insertions(+)
 create mode 100644 src/rde/serializers/yaml.scm

diff --git a/src/rde/serializers/yaml.scm b/src/rde/serializers/yaml.scm
new file mode 100644
index 00000000..8f31c1f6
--- /dev/null
+++ b/src/rde/serializers/yaml.scm
@@ -0,0 +1,157 @@
;;; rde --- Reproducible development environment.
;;;
;;; Copyright © 2023 conses <contact@conses.eu>
;;;
;;; This file is part of rde.
;;;
;;; rde is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; rde is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.

(define-module (rde serializers yaml)
  #:use-module (gnu home services utils)
  #:use-module (gnu services configuration)
  #:use-module (guix gexp)
  #:use-module (ice-9 match)
  #:use-module (ice-9 format)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-43)
  #:export (yaml-print
            yaml-config?
            serialize-yaml-config))

(define yaml-config? list?)

(define (pairs? lst)
  (and (list? lst) (every pair? lst)))

(define (make-yaml-indent depth)
  (make-string (* 2 depth) #\space))

(define (yaml-s-boolean v)
  (list (if v "true" "false")))

(define (yaml-s-number v)
  (list (number->string v)))

(define (yaml-s-string v)
  (list (format #f "~s" v)))

(define (yaml-s-symbol v)
  (list (object->snake-case-string
         (string->symbol
          (format #f "~a" v)))))

(define (yaml-s-key k)
  (cond
    ((symbol? k) (yaml-s-symbol k))
    ((string? k) (yaml-s-string k))
    (else (throw 'yaml-invalid-key k))))

(define (yaml-s-identity v)
  (list v))

(define (yaml-s-newline pretty?)
  (if pretty? (list "\n") '()))

(define (yaml-s-space pretty?)
  (if pretty? (list " ") '()))

(define (yaml-s-indentation level pretty?)
  (if pretty?
      (list (format #f "~v_" (- (* 2 level) 2)))
      '()))

(define (yaml-s-vector v level pretty?)
  (append
   (yaml-s-newline pretty?)
   (vector-fold
    (lambda (i acc e)
      (append acc
              (if (> i 0)
                  (yaml-s-newline pretty?)
                  '())
              (yaml-s-indentation (1+ level) pretty?)
              (list "- ")
              (match e
                ((? pairs? e) (yaml-s-vector-alist e (+ 1 level) pretty?))
                (_ (yaml-s-yaml e (1+ level) pretty?)))))
    '() v)))

(define (yaml-s-list v pretty?)
  (append
   (list "[")
   (interpose
    (append-map
     (lambda (x)
       (yaml-s-yaml x 0 pretty?))
     v)
    ", ")
   (list "]")))

(define (yaml-s-pair v level pretty?)
  (append
   (yaml-s-indentation level pretty?)
   (yaml-s-key (car v))
   (list ":")
   (yaml-s-space pretty?)
   (if (pairs? (cdr v))
       (yaml-s-newline pretty?)
       (list ""))
   (yaml-s-yaml (cdr v) level pretty?)))

(define (yaml-s-alist v level pretty?)
  (append
   (yaml-s-pair (car v) (1+ level) pretty?)
   (append-map
    (lambda (x)
      (append
       (yaml-s-newline pretty?)
       (yaml-s-pair x (1+ level) pretty?)))
    (cdr v))))

(define (yaml-s-vector-alist v level pretty?)
  (append
   (yaml-s-pair (car v) (- level (- level 1)) pretty?)
   (append-map
    (lambda (x)
      (append
       (yaml-s-newline pretty?)
       (yaml-s-pair x (1+ level) pretty?)))
    (cdr v))))

(define (yaml-s-yaml yaml level pretty?)
  (append
   (match yaml
     (() (list ""))
     ((? boolean? v) (yaml-s-boolean v))
     ((? number? v) (yaml-s-number v))
     ((? string? v) (yaml-s-key v))
     ((? symbol? v) (yaml-s-key v))
     ((? gexp? v) (yaml-s-identity v))
     ((? file-like? v) (yaml-s-identity v))
     ((? vector? v) (yaml-s-vector v level pretty?))
     ((? pairs? v) (yaml-s-alist v level pretty?))
     ((? list? v) (yaml-s-list v pretty?))
     (e (throw 'yaml-invalid yaml)))))

(define* (yaml-serialize yaml #:key (pretty? #t))
  "Returns a list of YAML strings which have to be concatenated.  It supports gexps,
file-likes, vectors -> arrays, alists -> dictionaries, etc."
  `(,@(yaml-s-yaml yaml 0 pretty?) "\n"))

(define serialize-yaml-config yaml-serialize)

(define* (yaml-print yaml #:key (pretty? #t))
  "Prints the generated YAML, useful for debugging purposes."
  (display (apply string-append
                  (yaml-s-yaml yaml 0 pretty?))))
-- 
2.39.1



-- 
Best regards,
conses

Re: [PATCH 2/3] gnu: Remove yaml-specific utils.

Details
Message ID
<87sfdn7evz.fsf@trop.in>
In-Reply-To
<afb23f4cfe6d4f92cc8a5be9658c95c68a844f99.1678531169.git.contact@conses.eu> (view parent)
DKIM signature
missing
Download raw message
On 2023-03-11 11:42, conses wrote:

> ---
>  src/gnu/home-services-utils.scm | 53 ---------------------------------
>  1 file changed, 53 deletions(-)
>
> diff --git a/src/gnu/home-services-utils.scm b/src/gnu/home-services-utils.scm
> index eb385691..29aef521 100644
> --- a/src/gnu/home-services-utils.scm
> +++ b/src/gnu/home-services-utils.scm
> @@ -65,9 +65,6 @@
>              generic-serialize-ini-config
>              generic-serialize-git-ini-config
>  
> -            yaml-config?
> -            serialize-yaml-config
> -
>              string-or-gexp?
>              serialize-string-or-gexp
>  
> @@ -300,56 +297,6 @@ elements: the section and the subsection."
>          fields)
>     "\n"))
>  
> -(define yaml-config? list?)
> -(define (make-yaml-indent depth)
> -  (make-string (* 2 depth) #\space))
> -
> -(define ((serialize-yaml-value depth) value)
> -  (let* ((tab (make-yaml-indent depth)))
> -    (cond
> -     ((string? value)
> -      (list (format #f "'~a'" value)))
> -     ((boolean? value)
> -      (list (format #f "~a" (if value "true" "false"))))
> -     ((file-like? value)
> -      (list value))
> -     ((alist? value)
> -      (serialize-yaml-alist value #:depth (1+ depth)))
> -     ((vector? value)
> -      (serialize-yaml-vector value #:depth depth))
> -     (else (list (format #f "~a" value))))))
> -
> -(define ((serialize-yaml-key depth) key)
> -  (when (vector? key)
> -    (raise (formatted-message
> -            (G_ "Vector as key value are not supported by serializer, \
> -try to avoid them. ~a") key)))
> -  ((serialize-yaml-value depth) key))
> -
> -(define ((serialize-yaml-key-value depth) key value)
> -  (let ((tab (make-yaml-indent depth)))
> -    `("\n"
> -      ,tab
> -      ,@((serialize-yaml-key depth) key) ": "
> -      ,@((serialize-yaml-value depth) value))))
> -
> -(define ((serialize-yaml-vector-elem depth) elem)
> -  (let ((tab (make-yaml-indent (1+ depth))))
> -    (cons*
> -     "\n" tab "- "
> -     ((serialize-yaml-value (1+ depth)) elem))))
> -
> -(define* (serialize-yaml-vector vec #:key (depth 0))
> -  (append-map (serialize-yaml-vector-elem depth) (vector->list vec)))
> -
> -(define* (serialize-yaml-alist lst #:key (depth 0))
> -  (generic-serialize-alist append (serialize-yaml-key-value depth) lst))
> -
> -(define (serialize-yaml-config config)
> -  "Simplified yaml serializer, which supports only a subset of yaml, use
> -it with caution."
> -  (serialize-yaml-alist config))
> -
>  (define (string-or-gexp? sg) (or (string? sg) (gexp? sg)))
>  (define (serialize-string-or-gexp field-name val) "")
>  
> -- 
> 2.39.1

No need to remove it right now, just let's keep it, other people can
depend on it, we can add a deprecation note as it's done in guix, after
some time (probably on the next release) we will remove it.

-- 
Best regards,
Andrew Tropin

Re: [PATCH 3/3] serializers: Add yaml.

Details
Message ID
<87pm8r7ely.fsf@trop.in>
In-Reply-To
<c5c5618dae10768930f4a539a9ae1de894fc7fee.1678531169.git.contact@conses.eu> (view parent)
DKIM signature
missing
Download raw message
On 2023-03-11 11:42, conses wrote:

> ---
>  src/rde/serializers/yaml.scm | 157 +++++++++++++++++++++++++++++++++++
>  1 file changed, 157 insertions(+)
>  create mode 100644 src/rde/serializers/yaml.scm
>
> diff --git a/src/rde/serializers/yaml.scm b/src/rde/serializers/yaml.scm
> new file mode 100644
> index 00000000..8f31c1f6
> --- /dev/null
> +++ b/src/rde/serializers/yaml.scm
> @@ -0,0 +1,157 @@
> +;;; rde --- Reproducible development environment.
> +;;;
> +;;; Copyright © 2023 conses <contact@conses.eu>
> +;;;
> +;;; This file is part of rde.
> +;;;
> +;;; rde is free software; you can redistribute it and/or modify it
> +;;; under the terms of the GNU General Public License as published by
> +;;; the Free Software Foundation; either version 3 of the License, or (at
> +;;; your option) any later version.
> +;;;
> +;;; rde is distributed in the hope that it will be useful, but
> +;;; WITHOUT ANY WARRANTY; without even the implied warranty of
> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +;;; GNU General Public License for more details.
> +;;;
> +;;; You should have received a copy of the GNU General Public License
> +;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.
> +
> +(define-module (rde serializers yaml)
> +  #:use-module (gnu home services utils)
> +  #:use-module (gnu services configuration)
> +  #:use-module (guix gexp)
> +  #:use-module (ice-9 match)
> +  #:use-module (ice-9 format)
> +  #:use-module (srfi srfi-1)
> +  #:use-module (srfi srfi-43)
> +  #:export (yaml-print
> +            yaml-config?
> +            serialize-yaml-config))
> +
> +(define yaml-config? list?)
> +
> +(define (pairs? lst)
> +  (and (list? lst) (every pair? lst)))
> +
> +(define (make-yaml-indent depth)
> +  (make-string (* 2 depth) #\space))
> +
> +(define (yaml-s-boolean v)
> +  (list (if v "true" "false")))
> +
> +(define (yaml-s-number v)
> +  (list (number->string v)))
> +
> +(define (yaml-s-string v)
> +  (list (format #f "~s" v)))
> +
> +(define (yaml-s-symbol v)
> +  (list (object->snake-case-string
> +         (string->symbol
> +          (format #f "~a" v)))))
> +
> +(define (yaml-s-key k)
> +  (cond
> +    ((symbol? k) (yaml-s-symbol k))
> +    ((string? k) (yaml-s-string k))
> +    (else (throw 'yaml-invalid-key k))))
> +
> +(define (yaml-s-identity v)
> +  (list v))
> +
> +(define (yaml-s-newline pretty?)
> +  (if pretty? (list "\n") '()))
> +
> +(define (yaml-s-space pretty?)
> +  (if pretty? (list " ") '()))
> +
> +(define (yaml-s-indentation level pretty?)
> +  (if pretty?
> +      (list (format #f "~v_" (- (* 2 level) 2)))
> +      '()))
> +
> +(define (yaml-s-vector v level pretty?)
> +  (append
> +   (yaml-s-newline pretty?)
> +   (vector-fold
> +    (lambda (i acc e)
> +      (append acc
> +              (if (> i 0)
> +                  (yaml-s-newline pretty?)
> +                  '())
> +              (yaml-s-indentation (1+ level) pretty?)
> +              (list "- ")
> +              (match e
> +                ((? pairs? e) (yaml-s-vector-alist e (+ 1 level) pretty?))
> +                (_ (yaml-s-yaml e (1+ level) pretty?)))))
> +    '() v)))
> +
> +(define (yaml-s-list v pretty?)
> +  (append
> +   (list "[")
> +   (interpose
> +    (append-map
> +     (lambda (x)
> +       (yaml-s-yaml x 0 pretty?))
> +     v)
> +    ", ")
> +   (list "]")))
> +
> +(define (yaml-s-pair v level pretty?)
> +  (append
> +   (yaml-s-indentation level pretty?)
> +   (yaml-s-key (car v))
> +   (list ":")
> +   (yaml-s-space pretty?)
> +   (if (pairs? (cdr v))
> +       (yaml-s-newline pretty?)
> +       (list ""))
> +   (yaml-s-yaml (cdr v) level pretty?)))
> +
> +(define (yaml-s-alist v level pretty?)
> +  (append
> +   (yaml-s-pair (car v) (1+ level) pretty?)
> +   (append-map
> +    (lambda (x)
> +      (append
> +       (yaml-s-newline pretty?)
> +       (yaml-s-pair x (1+ level) pretty?)))
> +    (cdr v))))
> +
> +(define (yaml-s-vector-alist v level pretty?)
> +  (append
> +   (yaml-s-pair (car v) (- level (- level 1)) pretty?)
> +   (append-map
> +    (lambda (x)
> +      (append
> +       (yaml-s-newline pretty?)
> +       (yaml-s-pair x (1+ level) pretty?)))
> +    (cdr v))))
> +
> +(define (yaml-s-yaml yaml level pretty?)
> +  (append
> +   (match yaml
> +     (() (list ""))
> +     ((? boolean? v) (yaml-s-boolean v))
> +     ((? number? v) (yaml-s-number v))
> +     ((? string? v) (yaml-s-key v))
> +     ((? symbol? v) (yaml-s-key v))
> +     ((? gexp? v) (yaml-s-identity v))
> +     ((? file-like? v) (yaml-s-identity v))
> +     ((? vector? v) (yaml-s-vector v level pretty?))
> +     ((? pairs? v) (yaml-s-alist v level pretty?))
> +     ((? list? v) (yaml-s-list v pretty?))
> +     (e (throw 'yaml-invalid yaml)))))
> +
> +(define* (yaml-serialize yaml #:key (pretty? #t))
> +  "Returns a list of YAML strings which have to be concatenated.  It supports gexps,
> +file-likes, vectors -> arrays, alists -> dictionaries, etc."
> +  `(,@(yaml-s-yaml yaml 0 pretty?) "\n"))
> +
> +(define serialize-yaml-config yaml-serialize)
> +
> +(define* (yaml-print yaml #:key (pretty? #t))
> +  "Prints the generated YAML, useful for debugging purposes."
> +  (display (apply string-append
> +                  (yaml-s-yaml yaml 0 pretty?))))
> -- 
> 2.39.1

Please cover this module with tests and adjust public API according to
https://git.sr.ht/~abcdw/rde/tree/718c215fdf08859106da0d3c64b08377323497b9/doc/decision-log/0002-serialization-api.org#L1

Also, take a look at nginx and nginx-test modules.  They are not perfect
and maybe have some questionable decisions, but they are good enough to
demonstarte how serializer and tests for it can look like.

-- 
Best regards,
Andrew Tropin

Re: [PATCH 3/3] serializers: Add yaml.

Details
Message ID
<87y1kn1ys3.fsf@trop.in>
In-Reply-To
<c5c5618dae10768930f4a539a9ae1de894fc7fee.1678531169.git.contact@conses.eu> (view parent)
DKIM signature
missing
Download raw message
On 2023-03-11 11:42, conses wrote:

> ---
>  src/rde/serializers/yaml.scm | 157 +++++++++++++++++++++++++++++++++++
>  1 file changed, 157 insertions(+)
>  create mode 100644 src/rde/serializers/yaml.scm
>
> diff --git a/src/rde/serializers/yaml.scm b/src/rde/serializers/yaml.scm
> new file mode 100644
> index 00000000..8f31c1f6
> --- /dev/null
> +++ b/src/rde/serializers/yaml.scm
> @@ -0,0 +1,157 @@
> +;;; rde --- Reproducible development environment.
> +;;;
> +;;; Copyright © 2023 conses <contact@conses.eu>
> +;;;
> +;;; This file is part of rde.
> +;;;
> +;;; rde is free software; you can redistribute it and/or modify it
> +;;; under the terms of the GNU General Public License as published by
> +;;; the Free Software Foundation; either version 3 of the License, or (at
> +;;; your option) any later version.
> +;;;
> +;;; rde is distributed in the hope that it will be useful, but
> +;;; WITHOUT ANY WARRANTY; without even the implied warranty of
> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +;;; GNU General Public License for more details.
> +;;;
> +;;; You should have received a copy of the GNU General Public License
> +;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.
> +
> +(define-module (rde serializers yaml)
> +  #:use-module (gnu home services utils)
> +  #:use-module (gnu services configuration)
> +  #:use-module (guix gexp)
> +  #:use-module (ice-9 match)
> +  #:use-module (ice-9 format)
> +  #:use-module (srfi srfi-1)
> +  #:use-module (srfi srfi-43)
> +  #:export (yaml-print
> +            yaml-config?
> +            serialize-yaml-config))
> +
> +(define yaml-config? list?)
> +
> +(define (pairs? lst)
> +  (and (list? lst) (every pair? lst)))
> +
> +(define (make-yaml-indent depth)
> +  (make-string (* 2 depth) #\space))
> +
> +(define (yaml-s-boolean v)
> +  (list (if v "true" "false")))
> +
> +(define (yaml-s-number v)
> +  (list (number->string v)))
> +
> +(define (yaml-s-string v)
> +  (list (format #f "~s" v)))
> +
> +(define (yaml-s-symbol v)
> +  (list (object->snake-case-string
> +         (string->symbol
> +          (format #f "~a" v)))))
> +
> +(define (yaml-s-key k)
> +  (cond
> +    ((symbol? k) (yaml-s-symbol k))
> +    ((string? k) (yaml-s-string k))
> +    (else (throw 'yaml-invalid-key k))))
> +
> +(define (yaml-s-identity v)
> +  (list v))
> +
> +(define (yaml-s-newline pretty?)
> +  (if pretty? (list "\n") '()))
> +
> +(define (yaml-s-space pretty?)
> +  (if pretty? (list " ") '()))
> +
> +(define (yaml-s-indentation level pretty?)
> +  (if pretty?
> +      (list (format #f "~v_" (- (* 2 level) 2)))
> +      '()))
> +
> +(define (yaml-s-vector v level pretty?)
> +  (append
> +   (yaml-s-newline pretty?)
> +   (vector-fold
> +    (lambda (i acc e)
> +      (append acc
> +              (if (> i 0)
> +                  (yaml-s-newline pretty?)
> +                  '())
> +              (yaml-s-indentation (1+ level) pretty?)
> +              (list "- ")
> +              (match e
> +                ((? pairs? e) (yaml-s-vector-alist e (+ 1 level) pretty?))
> +                (_ (yaml-s-yaml e (1+ level) pretty?)))))
> +    '() v)))
> +
> +(define (yaml-s-list v pretty?)
> +  (append
> +   (list "[")
> +   (interpose
> +    (append-map
> +     (lambda (x)
> +       (yaml-s-yaml x 0 pretty?))
> +     v)
> +    ", ")
> +   (list "]")))
> +
> +(define (yaml-s-pair v level pretty?)
> +  (append
> +   (yaml-s-indentation level pretty?)
> +   (yaml-s-key (car v))
> +   (list ":")
> +   (yaml-s-space pretty?)
> +   (if (pairs? (cdr v))
> +       (yaml-s-newline pretty?)
> +       (list ""))
> +   (yaml-s-yaml (cdr v) level pretty?)))
> +
> +(define (yaml-s-alist v level pretty?)
> +  (append
> +   (yaml-s-pair (car v) (1+ level) pretty?)
> +   (append-map
> +    (lambda (x)
> +      (append
> +       (yaml-s-newline pretty?)
> +       (yaml-s-pair x (1+ level) pretty?)))
> +    (cdr v))))
> +
> +(define (yaml-s-vector-alist v level pretty?)
> +  (append
> +   (yaml-s-pair (car v) (- level (- level 1)) pretty?)
> +   (append-map
> +    (lambda (x)
> +      (append
> +       (yaml-s-newline pretty?)
> +       (yaml-s-pair x (1+ level) pretty?)))
> +    (cdr v))))
> +
> +(define (yaml-s-yaml yaml level pretty?)
> +  (append
> +   (match yaml
> +     (() (list ""))
> +     ((? boolean? v) (yaml-s-boolean v))
> +     ((? number? v) (yaml-s-number v))
> +     ((? string? v) (yaml-s-key v))
> +     ((? symbol? v) (yaml-s-key v))
> +     ((? gexp? v) (yaml-s-identity v))
> +     ((? file-like? v) (yaml-s-identity v))
> +     ((? vector? v) (yaml-s-vector v level pretty?))
> +     ((? pairs? v) (yaml-s-alist v level pretty?))
> +     ((? list? v) (yaml-s-list v pretty?))
> +     (e (throw 'yaml-invalid yaml)))))
> +
> +(define* (yaml-serialize yaml #:key (pretty? #t))
> +  "Returns a list of YAML strings which have to be concatenated.  It supports gexps,
> +file-likes, vectors -> arrays, alists -> dictionaries, etc."
> +  `(,@(yaml-s-yaml yaml 0 pretty?) "\n"))
> +
> +(define serialize-yaml-config yaml-serialize)
> +
> +(define* (yaml-print yaml #:key (pretty? #t))
> +  "Prints the generated YAML, useful for debugging purposes."
> +  (display (apply string-append
> +                  (yaml-s-yaml yaml 0 pretty?))))
> -- 
> 2.39.1

Hi Miguel!

Add tests for the yaml serializer, please.  I'll take a closer look at
the implementation after it.

-- 
Best regards,
Andrew Tropin

[PATCH v2 1/3] serializers: Add yaml.

Details
Message ID
<3ef2c5ba11c46d329051bc7a62d611fa497b2151.1688063617.git.mail@migalmoreno.com>
In-Reply-To
<cover.1678531169.git.contact@conses.eu> (view parent)
DKIM signature
missing
Download raw message
Patch: +170 -0
---
 src/rde/serializers/yaml.scm | 170 +++++++++++++++++++++++++++++++++++
 1 file changed, 170 insertions(+)
 create mode 100644 src/rde/serializers/yaml.scm

diff --git a/src/rde/serializers/yaml.scm b/src/rde/serializers/yaml.scm
new file mode 100644
index 00000000..5f507a39
--- /dev/null
+++ b/src/rde/serializers/yaml.scm
@@ -0,0 +1,170 @@
;;; rde --- Reproducible development environment.
;;;
;;; Copyright © 2023 Miguel Ángel Moreno <mail@migalmoreno.com>
;;;
;;; This file is part of rde.
;;;
;;; rde is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; rde is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.

(define-module (rde serializers yaml)
  #:use-module (rde serializers utils)
  #:use-module (gnu home services utils)
  #:use-module (gnu services configuration)
  #:use-module (guix diagnostics)
  #:use-module (guix gexp)
  #:use-module (guix ui)
  #:use-module (ice-9 match)
  #:use-module (ice-9 format)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-43)
  #:export (yaml-print
            yaml-config?
            yaml-serialize

            serialize-yaml-term
            serialize-yaml-element
            serialize-yaml-config))

(define yaml-config? list?)

(define (yaml-term? t)
  (fold (lambda (x acc) (or acc (x t)))
        #f
        (list boolean? symbol? number? string? file-like? gexp?)))

(define (serialize-yaml-string v)
  (format #f "~s" v))

(define (serialize-yaml-symbol v)
  (object->snake-case-string
   (string->symbol
    (format #f "~a" v))))

(define (serialize-yaml-term term)
  (match term
    ((? boolean? v) (if v "true" "false"))
    ((? number? v) (number->string v))
    ((? string? v) (serialize-yaml-string v))
    ((? symbol? v) (serialize-yaml-symbol v))
    ((or (? gexp? v)
         (? file-like? v))
     v)
    (v (raise (formatted-message
               (G_ "\
YAML term should be boolean, number, string, symbol, or gexp. Provided term
is:\n ~a") v)))))

(define (serialize-yaml-key k)
  (list
   (cond
    ((symbol? k) (serialize-yaml-symbol k))
    ((string? k) (serialize-yaml-string k))
    (else (raise (formatted-message
                  (G_ "\
YAML key should be symbol or string. Provided key is:\n ~a")
                  k))))))

(define (serialize-yaml-newline pretty?)
  (if pretty? (list "\n") '()))

(define (serialize-yaml-space pretty?)
  (if pretty? (list " ") '()))

(define (serialize-yaml-indentation level pretty?)
  (if pretty?
      (list (format #f "~v_" (- (* 2 level) 2)))
      '()))

(define (serialize-yaml-vector v level pretty?)
  (append
   (serialize-yaml-newline pretty?)
   (vector-fold
    (lambda (i acc e)
      (append acc
              (if (> i 0)
                  (serialize-yaml-newline pretty?)
                  '())
              (serialize-yaml-indentation (1+ level) pretty?)
              (list "- ")
              (match e
                ((? alist? e)
                 (serialize-yaml-vector-alist e (+ 1 level) pretty?))
                (_ (serialize-yaml-element e (1+ level) pretty?)))))
    '() v)))

(define (serialize-yaml-list v pretty?)
  (append
   (list "[")
   (interpose
    (append-map
     (lambda (x)
       (serialize-yaml-element x 0 pretty?))
     v)
    ", ")
   (list "]")))

(define (serialize-yaml-pair v level pretty?)
  (append
   (serialize-yaml-indentation level pretty?)
   (serialize-yaml-key (car v))
   (list ":")
   (serialize-yaml-space pretty?)
   (if (alist? (cdr v))
       (serialize-yaml-newline pretty?)
       (list ""))
   (serialize-yaml-element (cdr v) level pretty?)))

(define (serialize-yaml-alist v level pretty?)
  (append
   (serialize-yaml-pair (car v) (1+ level) pretty?)
   (append-map
    (lambda (x)
      (append
       (serialize-yaml-newline pretty?)
       (serialize-yaml-pair x (1+ level) pretty?)))
    (cdr v))))

(define (serialize-yaml-vector-alist v level pretty?)
  (append
   (serialize-yaml-pair (car v) (- level (- level 1)) pretty?)
   (append-map
    (lambda (x)
      (append
       (serialize-yaml-newline pretty?)
       (serialize-yaml-pair x (1+ level) pretty?)))
    (cdr v))))

(define (serialize-yaml-element yaml level pretty?)
  (append
   (match yaml
     (() (list ""))
     ((? yaml-term? v) (list (serialize-yaml-term v)))
     ((? alist? v) (serialize-yaml-alist v level pretty?))
     ((? list? v) (serialize-yaml-list v pretty?))
     ((? vector? v) (serialize-yaml-vector v level pretty?))
     (e (throw 'yaml-invalid yaml)))))

(define (serialize-yaml-config f c)
  #~(apply string-append
           (list #$@(serialize-yaml-element c 0 #t))))

(define* (yaml-serialize config)
  "Returns a list of YAML strings which have to be concatenated.  It supports
 gexps, file-likes, vectors -> arrays, alists -> dictionaries, etc."
  (serialize-yaml-config #f config))

(define* (yaml-print yaml #:key (pretty? #t))
  "Prints the generated YAML, useful for debugging purposes."
  (display (apply string-append
                  (serialize-yaml-element yaml 0 pretty?))))
-- 
2.40.1


-- 
Best regards,
Miguel Ángel Moreno

[PATCH v2 2/3] tests: serializers: Add yaml-test.

Details
Message ID
<4bb44d60caf5436991cbdc2fe733be559ab7fee9.1688063617.git.mail@migalmoreno.com>
In-Reply-To
<cover.1678531169.git.contact@conses.eu> (view parent)
DKIM signature
missing
Download raw message
Patch: +79 -0
---
 tests/rde/serializers/yaml-test.scm | 79 +++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100644 tests/rde/serializers/yaml-test.scm

diff --git a/tests/rde/serializers/yaml-test.scm b/tests/rde/serializers/yaml-test.scm
new file mode 100644
index 00000000..a0c0b39e
--- /dev/null
+++ b/tests/rde/serializers/yaml-test.scm
@@ -0,0 +1,79 @@
;;; rde --- Reproducible development environment.
;;;
;;; Copyright © 2023 Miguel Ángel Moreno <mail@migalmoreno.com>
;;;
;;; This file is part of rde.
;;;
;;; rde is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; rde is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.

(define-module (rde serializers yaml-test)
  #:use-module (guix gexp)
  #:use-module (rde serializers yaml)
  #:use-module (rde tests)
  #:use-module (rde tests store)
  #:use-module (ice-9 match))

(define (serialize-yaml config)
  (eval-with-store (yaml-serialize config)))

(define-test yaml-terms
  (test-group "YAML basic values"
    (test-equal "number"
      "123"
      (serialize-yaml-term 123))
    (test-equal "string"
      "\"string here\""
      (serialize-yaml-term "string here"))
    (test-equal "symbol"
      "symbol_here"
      (serialize-yaml-term 'symbol-here))
    (test-assert "gexp"
      (gexp?
       (serialize-yaml-term #~"gexp")))
    (test-equal "true" "true" (serialize-yaml-term #t))
    (test-equal "false" "false" (serialize-yaml-term #f))
    (test-error "list" #t (serialize-yaml-term '(a b c)))
    (test-error "vector" #t (serialize-yaml-term #(a b c)))))

(define-test yaml-lists
  (test-group "YAML lists"
    (test-equal "basic list"
      "[a, b, c]"
      (serialize-yaml '(a b c))))
  (test-group "YAML alists"
    (test-equal "basic alist"
      "a: b"
      (serialize-yaml '((a . b))))
    (test-equal "nested alist"
      "logging: \

  print_level: debug"
      (serialize-yaml '((logging . ((print-level . debug))))))
    (test-error "invalid key" #t (serialize-yaml-config '((1 . test))))))

(define-test yaml-vectors
  (test-group "YAML vectors"
    (test-equal "basic vector"
      "
- a
- b
- c"
      (serialize-yaml #(a b c)))
    (test-equal "nested alist"
      "
- names: [client, federation]
  compress: false"
      (serialize-yaml #(((names . (client federation))
                         (compress . #f)))))
    (test-error "nested list" #t (serialize-yaml #(())))))
-- 
2.40.1

-- 
Best regards,
Miguel Ángel Moreno

[PATCH v2 3/3] home: Add udiskie-service-type.

Details
Message ID
<8a37ad3f5dfc5d85db9da4577cfda6902ce5c34c.1688063617.git.mail@migalmoreno.com>
In-Reply-To
<cover.1678531169.git.contact@conses.eu> (view parent)
DKIM signature
missing
Download raw message
Patch: +83 -0
---
 src/rde/home/services/desktop.scm | 83 +++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100644 src/rde/home/services/desktop.scm

diff --git a/src/rde/home/services/desktop.scm b/src/rde/home/services/desktop.scm
new file mode 100644
index 00000000..5b64f0f5
--- /dev/null
+++ b/src/rde/home/services/desktop.scm
@@ -0,0 +1,83 @@
;;; rde --- Reproducible development environment.
;;;
;;; Copyright © 2023 Miguel Ángel Moreno <mail@migalmoreno.com>
;;;
;;; This file is part of rde.
;;;
;;; rde is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; rde is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.

(define-module (rde home services desktop)
  #:use-module (gnu services)
  #:use-module (gnu services shepherd)
  #:use-module (gnu services configuration)
  #:use-module (gnu home services)
  #:use-module (gnu home services shepherd)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages freedesktop)
  #:use-module (guix packages)
  #:use-module (guix gexp)
  #:use-module (rde serializers yaml)
  #:export (home-udiskie-configuration
            home-udiskie-service-type))

(define-configuration/no-serialization home-udiskie-configuration
  (udiskie
   (package udiskie)
   "The udiskie package to use.")
  (config
   (yaml-config '())
   "Udiskie configuration."))

(define (home-udiskie-profile-service config)
  (list (home-udiskie-configuration-udiskie config)))

(define (home-udiskie-shepherd-service config)
  (list
   (shepherd-service
    (provision '(udiskie))
    (stop #~(make-kill-destructor))
    (start #~(make-forkexec-constructor
              (list
               #$(file-append
                  (home-udiskie-configuration-udiskie config)
                  "/bin/udiskie")))))))

(define (add-udiskie-configuration config)
  `(("udiskie/config.yml"
     ,(mixed-text-file "config.yml"
                       (yaml-serialize
                        (home-udiskie-configuration-config config))))))

(define home-udiskie-service-type
  (service-type
   (name 'udiskie)
   (extensions
    (list
     (service-extension
      home-profile-service-type
      home-udiskie-profile-service)
     (service-extension
      home-shepherd-service-type
      home-udiskie-shepherd-service)
     (service-extension
      home-xdg-configuration-files-service-type
      add-udiskie-configuration)))
   (description "Set up a udiskie daemon to automount removable media.")
   (default-value (home-udiskie-configuration))))

(define (generate-home-udiskie-documentation)
  (generate-documentation
   `((home-udiskie-configuration
      ,home-udiskie-configuration-fields))
   'home-udiskie-configuration))
-- 
2.40.1

-- 
Best regards,
Miguel Ángel Moreno

Re: [PATCH v2 1/3] serializers: Add yaml.

Details
Message ID
<87ttul2vs4.fsf@trop.in>
In-Reply-To
<3ef2c5ba11c46d329051bc7a62d611fa497b2151.1688063617.git.mail@migalmoreno.com> (view parent)
DKIM signature
missing
Download raw message
On 2023-06-29 20:34, Miguel Ángel Moreno wrote:

> ---
>  src/rde/serializers/yaml.scm | 170 +++++++++++++++++++++++++++++++++++
>  1 file changed, 170 insertions(+)
>  create mode 100644 src/rde/serializers/yaml.scm
>
> diff --git a/src/rde/serializers/yaml.scm b/src/rde/serializers/yaml.scm
> new file mode 100644
> index 00000000..5f507a39
> --- /dev/null
> +++ b/src/rde/serializers/yaml.scm
> @@ -0,0 +1,170 @@
> +;;; rde --- Reproducible development environment.
> +;;;
> +;;; Copyright © 2023 Miguel Ángel Moreno <mail@migalmoreno.com>
> +;;;
> +;;; This file is part of rde.
> +;;;
> +;;; rde is free software; you can redistribute it and/or modify it
> +;;; under the terms of the GNU General Public License as published by
> +;;; the Free Software Foundation; either version 3 of the License, or (at
> +;;; your option) any later version.
> +;;;
> +;;; rde is distributed in the hope that it will be useful, but
> +;;; WITHOUT ANY WARRANTY; without even the implied warranty of
> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +;;; GNU General Public License for more details.
> +;;;
> +;;; You should have received a copy of the GNU General Public License
> +;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.
> +
> +(define-module (rde serializers yaml)
> +  #:use-module (rde serializers utils)
> +  #:use-module (gnu home services utils)
> +  #:use-module (gnu services configuration)
> +  #:use-module (guix diagnostics)
> +  #:use-module (guix gexp)
> +  #:use-module (guix ui)
> +  #:use-module (ice-9 match)
> +  #:use-module (ice-9 format)
> +  #:use-module (srfi srfi-1)
> +  #:use-module (srfi srfi-43)
> +  #:export (yaml-print
> +            yaml-config?
> +            yaml-serialize
> +
> +            serialize-yaml-term
> +            serialize-yaml-element
> +            serialize-yaml-config))
> +
> +(define yaml-config? list?)
> +
> +(define (yaml-term? t)
> +  (fold (lambda (x acc) (or acc (x t)))
> +        #f
> +        (list boolean? symbol? number? string? file-like? gexp?)))
> +
> +(define (serialize-yaml-string v)
> +  (format #f "~s" v))
> +
> +(define (serialize-yaml-symbol v)
> +  (object->snake-case-string

Unconditional case transformation in yaml serializer restricts the the
possible output values. Imagine you want to represent "bill-to: Bob".

> +   (string->symbol
> +    (format #f "~a" v))))
> +
> +(define (serialize-yaml-term term)
> +  (match term
> +    ((? boolean? v) (if v "true" "false"))
> +    ((? number? v) (number->string v))
> +    ((? string? v) (serialize-yaml-string v))
> +    ((? symbol? v) (serialize-yaml-symbol v))
> +    ((or (? gexp? v)
> +         (? file-like? v))
> +     v)
> +    (v (raise (formatted-message
> +               (G_ "\
> +YAML term should be boolean, number, string, symbol, or gexp. Provided term
> +is:\n ~a") v)))))
> +
> +(define (serialize-yaml-key k)
> +  (list
> +   (cond
> +    ((symbol? k) (serialize-yaml-symbol k))
> +    ((string? k) (serialize-yaml-string k))
> +    (else (raise (formatted-message
> +                  (G_ "\
> +YAML key should be symbol or string. Provided key is:\n ~a")
> +                  k))))))
> +
> +(define (serialize-yaml-newline pretty?)
> +  (if pretty? (list "\n") '()))
> +
> +(define (serialize-yaml-space pretty?)
> +  (if pretty? (list " ") '()))
> +
> +(define (serialize-yaml-indentation level pretty?)
> +  (if pretty?
> +      (list (format #f "~v_" (- (* 2 level) 2)))
> +      '()))
> +
> +(define (serialize-yaml-vector v level pretty?)
> +  (append
> +   (serialize-yaml-newline pretty?)
> +   (vector-fold
> +    (lambda (i acc e)
> +      (append acc
> +              (if (> i 0)
> +                  (serialize-yaml-newline pretty?)
> +                  '())
> +              (serialize-yaml-indentation (1+ level) pretty?)
> +              (list "- ")
> +              (match e
> +                ((? alist? e)
> +                 (serialize-yaml-vector-alist e (+ 1 level) pretty?))
> +                (_ (serialize-yaml-element e (1+ level) pretty?)))))
> +    '() v)))
> +
> +(define (serialize-yaml-list v pretty?)
> +  (append
> +   (list "[")
> +   (interpose
> +    (append-map
> +     (lambda (x)
> +       (serialize-yaml-element x 0 pretty?))
> +     v)
> +    ", ")
> +   (list "]")))
> +
> +(define (serialize-yaml-pair v level pretty?)
> +  (append
> +   (serialize-yaml-indentation level pretty?)
> +   (serialize-yaml-key (car v))
> +   (list ":")
> +   (serialize-yaml-space pretty?)
> +   (if (alist? (cdr v))
> +       (serialize-yaml-newline pretty?)
> +       (list ""))
> +   (serialize-yaml-element (cdr v) level pretty?)))
> +
> +(define (serialize-yaml-alist v level pretty?)
> +  (append
> +   (serialize-yaml-pair (car v) (1+ level) pretty?)
> +   (append-map
> +    (lambda (x)
> +      (append
> +       (serialize-yaml-newline pretty?)
> +       (serialize-yaml-pair x (1+ level) pretty?)))
> +    (cdr v))))
> +
> +(define (serialize-yaml-vector-alist v level pretty?)
> +  (append
> +   (serialize-yaml-pair (car v) (- level (- level 1)) pretty?)
> +   (append-map
> +    (lambda (x)
> +      (append
> +       (serialize-yaml-newline pretty?)
> +       (serialize-yaml-pair x (1+ level) pretty?)))
> +    (cdr v))))
> +
> +(define (serialize-yaml-element yaml level pretty?)
> +  (append
> +   (match yaml
> +     (() (list ""))
> +     ((? yaml-term? v) (list (serialize-yaml-term v)))
> +     ((? alist? v) (serialize-yaml-alist v level pretty?))
> +     ((? list? v) (serialize-yaml-list v pretty?))
> +     ((? vector? v) (serialize-yaml-vector v level pretty?))
> +     (e (throw 'yaml-invalid yaml)))))
> +
> +(define (serialize-yaml-config f c)
> +  #~(apply string-append
> +           (list #$@(serialize-yaml-element c 0 #t))))
> +
> +(define* (yaml-serialize config)
> +  "Returns a list of YAML strings which have to be concatenated.  It supports
> + gexps, file-likes, vectors -> arrays, alists -> dictionaries, etc."
> +  (serialize-yaml-config #f config))
> +
> +(define* (yaml-print yaml #:key (pretty? #t))
> +  "Prints the generated YAML, useful for debugging purposes."
> +  (display (apply string-append
> +                  (serialize-yaml-element yaml 0 pretty?))))
> -- 
> 2.40.1

It would be cool to add a few more test.  Maybe something from
specification or real-world application:
https://yaml.org/spec/1.2.2/#25-full-length-example

-- 
Best regards,
Andrew Tropin

[PATCH v3 1/3] serializers: Add yaml.

Details
Message ID
<2fd3c11448afb0ea3fa10b5675d4d3411c15008d.1691965992.git.mail@migalmoreno.com>
In-Reply-To
<cover.1678531169.git.contact@conses.eu> (view parent)
DKIM signature
missing
Download raw message
Patch: +168 -0
---
* Remove unconditional case transformation in symbol serialization
 src/rde/serializers/yaml.scm | 168 +++++++++++++++++++++++++++++++++++
 1 file changed, 168 insertions(+)
 create mode 100644 src/rde/serializers/yaml.scm

diff --git a/src/rde/serializers/yaml.scm b/src/rde/serializers/yaml.scm
new file mode 100644
index 00000000..ddec279b
--- /dev/null
+++ b/src/rde/serializers/yaml.scm
@@ -0,0 +1,168 @@
;;; rde --- Reproducible development environment.
;;;
;;; Copyright © 2023 Miguel Ángel Moreno <mail@migalmoreno.com>
;;;
;;; This file is part of rde.
;;;
;;; rde is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; rde is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.

(define-module (rde serializers yaml)
  #:use-module (rde serializers utils)
  #:use-module (gnu home services utils)
  #:use-module (gnu services configuration)
  #:use-module (guix diagnostics)
  #:use-module (guix gexp)
  #:use-module (guix ui)
  #:use-module (ice-9 match)
  #:use-module (ice-9 format)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-43)
  #:export (yaml-print
            yaml-config?
            yaml-serialize

            serialize-yaml-term
            serialize-yaml-element
            serialize-yaml-config))

(define yaml-config? list?)

(define (yaml-term? t)
  (fold (lambda (x acc) (or acc (x t)))
        #f
        (list boolean? symbol? number? string? file-like? gexp?)))

(define (serialize-yaml-string v)
  (format #f "~s" v))

(define (serialize-yaml-symbol v)
  (format #f "~a" v))

(define (serialize-yaml-term term)
  (match term
    ((? boolean? v) (if v "true" "false"))
    ((? number? v) (number->string v))
    ((? string? v) (serialize-yaml-string v))
    ((? symbol? v) (serialize-yaml-symbol v))
    ((or (? gexp? v)
         (? file-like? v))
     v)
    (v (raise (formatted-message
               (G_ "\
YAML term should be boolean, number, string, symbol, or gexp. Provided term
is:\n ~a") v)))))

(define (serialize-yaml-key k)
  (list
   (cond
    ((symbol? k) (serialize-yaml-symbol k))
    ((string? k) (serialize-yaml-string k))
    (else (raise (formatted-message
                  (G_ "\
YAML key should be symbol or string. Provided key is:\n ~a")
                  k))))))

(define (serialize-yaml-newline pretty?)
  (if pretty? (list "\n") '()))

(define (serialize-yaml-space pretty?)
  (if pretty? (list " ") '()))

(define (serialize-yaml-indentation level pretty?)
  (if pretty?
      (list (format #f "~v_" (- (* 2 level) 2)))
      '()))

(define (serialize-yaml-vector v level pretty?)
  (append
   (serialize-yaml-newline pretty?)
   (vector-fold
    (lambda (i acc e)
      (append acc
              (if (> i 0)
                  (serialize-yaml-newline pretty?)
                  '())
              (serialize-yaml-indentation (1+ level) pretty?)
              (list "- ")
              (match e
                ((? alist? e)
                 (serialize-yaml-vector-alist e (+ 1 level) pretty?))
                (_ (serialize-yaml-element e (1+ level) pretty?)))))
    '() v)))

(define (serialize-yaml-list v pretty?)
  (append
   (list "[")
   (interpose
    (append-map
     (lambda (x)
       (serialize-yaml-element x 0 pretty?))
     v)
    ", ")
   (list "]")))

(define (serialize-yaml-pair v level pretty?)
  (append
   (serialize-yaml-indentation level pretty?)
   (serialize-yaml-key (car v))
   (list ":")
   (serialize-yaml-space pretty?)
   (if (alist? (cdr v))
       (serialize-yaml-newline pretty?)
       (list ""))
   (serialize-yaml-element (cdr v) level pretty?)))

(define (serialize-yaml-alist v level pretty?)
  (append
   (serialize-yaml-pair (car v) (1+ level) pretty?)
   (append-map
    (lambda (x)
      (append
       (serialize-yaml-newline pretty?)
       (serialize-yaml-pair x (1+ level) pretty?)))
    (cdr v))))

(define (serialize-yaml-vector-alist v level pretty?)
  (append
   (serialize-yaml-pair (car v) (- level (- level 1)) pretty?)
   (append-map
    (lambda (x)
      (append
       (serialize-yaml-newline pretty?)
       (serialize-yaml-pair x (1+ level) pretty?)))
    (cdr v))))

(define (serialize-yaml-element yaml level pretty?)
  (append
   (match yaml
     (() (list ""))
     ((? yaml-term? v) (list (serialize-yaml-term v)))
     ((? alist? v) (serialize-yaml-alist v level pretty?))
     ((? list? v) (serialize-yaml-list v pretty?))
     ((? vector? v) (serialize-yaml-vector v level pretty?))
     (e (throw 'yaml-invalid yaml)))))

(define (serialize-yaml-config f c)
  #~(apply string-append
           (list #$@(serialize-yaml-element c 0 #t))))

(define* (yaml-serialize config)
  "Returns a list of YAML strings which have to be concatenated.  It supports
 gexps, file-likes, vectors -> arrays, alists -> dictionaries, etc."
  (serialize-yaml-config #f config))

(define* (yaml-print yaml #:key (pretty? #t))
  "Prints the generated YAML, useful for debugging purposes."
  (display (apply string-append
                  (serialize-yaml-element yaml 0 pretty?))))
-- 
2.41.0

-- 
Best regards,
Miguel Ángel Moreno

[PATCH v3 2/3] tests: serializers: Add yaml-test.

Details
Message ID
<03e5844396e584bf6b3eecd8b19c40232425ec58.1691965992.git.mail@migalmoreno.com>
In-Reply-To
<cover.1678531169.git.contact@conses.eu> (view parent)
DKIM signature
missing
Download raw message
Patch: +142 -0
---
* Add full-fledged test example with sample Synapse configuration
 tests/rde/serializers/yaml-test.scm | 142 ++++++++++++++++++++++++++++
 1 file changed, 142 insertions(+)
 create mode 100644 tests/rde/serializers/yaml-test.scm

diff --git a/tests/rde/serializers/yaml-test.scm b/tests/rde/serializers/yaml-test.scm
new file mode 100644
index 00000000..994d5ab3
--- /dev/null
+++ b/tests/rde/serializers/yaml-test.scm
@@ -0,0 +1,142 @@
;;; rde --- Reproducible development environment.
;;;
;;; Copyright © 2023 Miguel Ángel Moreno <mail@migalmoreno.com>
;;;
;;; This file is part of rde.
;;;
;;; rde is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; rde is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.

(define-module (rde serializers yaml-test)
  #:use-module (guix gexp)
  #:use-module (rde serializers yaml)
  #:use-module (rde tests)
  #:use-module (rde tests store)
  #:use-module (ice-9 match))

(define (serialize-yaml config)
  (eval-with-store (yaml-serialize config)))

(define-test yaml-terms
  (test-group "YAML basic values"
    (test-equal "number"
      "123"
      (serialize-yaml-term 123))
    (test-equal "string"
      "\"string here\""
      (serialize-yaml-term "string here"))
    (test-equal "symbol"
      "symbol_here"
      (serialize-yaml-term 'symbol_here))
    (test-assert "gexp"
      (gexp?
       (serialize-yaml-term #~"gexp")))
    (test-equal "true" "true" (serialize-yaml-term #t))
    (test-equal "false" "false" (serialize-yaml-term #f))
    (test-error "list" #t (serialize-yaml-term '(a b c)))
    (test-error "vector" #t (serialize-yaml-term #(a b c)))))

(define-test yaml-lists
  (test-group "YAML lists"
    (test-equal "basic list"
      "[a, b, c]"
      (serialize-yaml '(a b c))))
  (test-group "YAML alists"
    (test-equal "basic alist"
      "a: b"
      (serialize-yaml '((a . b))))
    (test-equal "nested alist"
      "logging: \

  print_level: debug"
      (serialize-yaml '((logging . ((print_level . debug))))))
    (test-error "invalid key" #t (serialize-yaml-config '((1 . test))))))

(define-test yaml-vectors
  (test-group "YAML vectors"
    (test-equal "basic vector"
      "
- a
- b
- c"
      (serialize-yaml #(a b c)))
    (test-equal "nested alist"
      "
- names: [client, federation]
  compress: false"
      (serialize-yaml #(((names . (client federation))
                         (compress . #f)))))
    (test-error "nested list" #t (serialize-yaml #(())))))

(define-test yaml-example-config
  (test-group "example config"
    (test-equal "full length example"
      "\
server_name: \"matrix.org\"
public_base_url: \"https://matrix.org\"
media_store_path: \"/var/lib/matrix-synapse/media_store\"
max_upload_size: \"50M\"
enable_registration: false
report_stats: true
database: \

  name: psycopg2
  allow_unsafe_locale: true
  args: \

    user: \"matrix-synapse\"
    database: \"matrix-synapse\"
    host: localhost
    port: 5432
    cp_min: 5
    cp_max: 10
listeners: \

  - port: 8008
    tls: false
    type: http
    x_forwarded: true
    bind_addresses: \

      - \"::1\"
      - \"127.0.0.1\"
    resources: \

      - names: [client, federation]
        compress: false
trusted_key_servers: \

  - server_name: \"matrix.org\""
      (serialize-yaml
       '((server_name . "matrix.org")
         (public_base_url . "https://matrix.org")
         (media_store_path . "/var/lib/matrix-synapse/media_store")
         (max_upload_size . "50M")
         (enable_registration . #f)
         (report_stats . #t)
         (database . ((name . psycopg2)
                      (allow_unsafe_locale . #t)
                      (args . ((user . "matrix-synapse")
                               (database . "matrix-synapse")
                               (host . localhost)
                               (port . 5432)
                               (cp_min . 5)
                               (cp_max . 10)))))
         (listeners . #(((port . 8008)
                         (tls . #f)
                         (type . http)
                         (x_forwarded . true)
                         (bind_addresses . #("::1" "127.0.0.1"))
                         (resources . #(((names . (client federation))
                                         (compress . #f)))))))
         (trusted_key_servers . #(((server_name . "matrix.org")))))))))
-- 
2.41.0

-- 
Best regards,
Miguel Ángel Moreno

[PATCH v3 3/3] home: Add udiskie-service-type.

Details
Message ID
<77c2a15be6f4ade3a2709634c0e91c8c66ca1985.1691965992.git.mail@migalmoreno.com>
In-Reply-To
<cover.1678531169.git.contact@conses.eu> (view parent)
DKIM signature
missing
Download raw message
Patch: +83 -0
---
 src/rde/home/services/desktop.scm | 83 +++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100644 src/rde/home/services/desktop.scm

diff --git a/src/rde/home/services/desktop.scm b/src/rde/home/services/desktop.scm
new file mode 100644
index 00000000..5b64f0f5
--- /dev/null
+++ b/src/rde/home/services/desktop.scm
@@ -0,0 +1,83 @@
;;; rde --- Reproducible development environment.
;;;
;;; Copyright © 2023 Miguel Ángel Moreno <mail@migalmoreno.com>
;;;
;;; This file is part of rde.
;;;
;;; rde is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; rde is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.

(define-module (rde home services desktop)
  #:use-module (gnu services)
  #:use-module (gnu services shepherd)
  #:use-module (gnu services configuration)
  #:use-module (gnu home services)
  #:use-module (gnu home services shepherd)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages freedesktop)
  #:use-module (guix packages)
  #:use-module (guix gexp)
  #:use-module (rde serializers yaml)
  #:export (home-udiskie-configuration
            home-udiskie-service-type))

(define-configuration/no-serialization home-udiskie-configuration
  (udiskie
   (package udiskie)
   "The udiskie package to use.")
  (config
   (yaml-config '())
   "Udiskie configuration."))

(define (home-udiskie-profile-service config)
  (list (home-udiskie-configuration-udiskie config)))

(define (home-udiskie-shepherd-service config)
  (list
   (shepherd-service
    (provision '(udiskie))
    (stop #~(make-kill-destructor))
    (start #~(make-forkexec-constructor
              (list
               #$(file-append
                  (home-udiskie-configuration-udiskie config)
                  "/bin/udiskie")))))))

(define (add-udiskie-configuration config)
  `(("udiskie/config.yml"
     ,(mixed-text-file "config.yml"
                       (yaml-serialize
                        (home-udiskie-configuration-config config))))))

(define home-udiskie-service-type
  (service-type
   (name 'udiskie)
   (extensions
    (list
     (service-extension
      home-profile-service-type
      home-udiskie-profile-service)
     (service-extension
      home-shepherd-service-type
      home-udiskie-shepherd-service)
     (service-extension
      home-xdg-configuration-files-service-type
      add-udiskie-configuration)))
   (description "Set up a udiskie daemon to automount removable media.")
   (default-value (home-udiskie-configuration))))

(define (generate-home-udiskie-documentation)
  (generate-documentation
   `((home-udiskie-configuration
      ,home-udiskie-configuration-fields))
   'home-udiskie-configuration))
-- 
2.41.0

-- 
Best regards,
Miguel Ángel Moreno

Re: [PATCH v3 3/3] home: Add udiskie-service-type.

Details
Message ID
<87350l7qe3.fsf@trop.in>
In-Reply-To
<77c2a15be6f4ade3a2709634c0e91c8c66ca1985.1691965992.git.mail@migalmoreno.com> (view parent)
DKIM signature
missing
Download raw message
On 2023-08-14 00:37, Miguel Ángel Moreno wrote:

> ---
>  src/rde/home/services/desktop.scm | 83 +++++++++++++++++++++++++++++++
>  1 file changed, 83 insertions(+)
>  create mode 100644 src/rde/home/services/desktop.scm
>
> diff --git a/src/rde/home/services/desktop.scm b/src/rde/home/services/desktop.scm
> new file mode 100644
> index 00000000..5b64f0f5
> --- /dev/null
> +++ b/src/rde/home/services/desktop.scm
> @@ -0,0 +1,83 @@
> +;;; rde --- Reproducible development environment.
> +;;;
> +;;; Copyright © 2023 Miguel Ángel Moreno <mail@migalmoreno.com>
> +;;;
> +;;; This file is part of rde.
> +;;;
> +;;; rde is free software; you can redistribute it and/or modify it
> +;;; under the terms of the GNU General Public License as published by
> +;;; the Free Software Foundation; either version 3 of the License, or (at
> +;;; your option) any later version.
> +;;;
> +;;; rde is distributed in the hope that it will be useful, but
> +;;; WITHOUT ANY WARRANTY; without even the implied warranty of
> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +;;; GNU General Public License for more details.
> +;;;
> +;;; You should have received a copy of the GNU General Public License
> +;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.
> +
> +(define-module (rde home services desktop)
> +  #:use-module (gnu services)
> +  #:use-module (gnu services shepherd)
> +  #:use-module (gnu services configuration)
> +  #:use-module (gnu home services)
> +  #:use-module (gnu home services shepherd)
> +  #:use-module (gnu packages linux)
> +  #:use-module (gnu packages freedesktop)
> +  #:use-module (guix packages)
> +  #:use-module (guix gexp)
> +  #:use-module (rde serializers yaml)
> +  #:export (home-udiskie-configuration
> +            home-udiskie-service-type))
> +
> +(define-configuration/no-serialization home-udiskie-configuration
> +  (udiskie
> +   (package udiskie)
> +   "The udiskie package to use.")
> +  (config
> +   (yaml-config '())
> +   "Udiskie configuration."))
> +
> +(define (home-udiskie-profile-service config)
> +  (list (home-udiskie-configuration-udiskie config)))
> +
> +(define (home-udiskie-shepherd-service config)
> +  (list
> +   (shepherd-service
> +    (provision '(udiskie))
> +    (stop #~(make-kill-destructor))
> +    (start #~(make-forkexec-constructor
> +              (list
> +               #$(file-append
> +                  (home-udiskie-configuration-udiskie config)
> +                  "/bin/udiskie")))))))
> +
> +(define (add-udiskie-configuration config)
> +  `(("udiskie/config.yml"
> +     ,(mixed-text-file "config.yml"
> +                       (yaml-serialize
> +                        (home-udiskie-configuration-config config))))))
> +
> +(define home-udiskie-service-type
> +  (service-type
> +   (name 'udiskie)
> +   (extensions
> +    (list
> +     (service-extension
> +      home-profile-service-type
> +      home-udiskie-profile-service)
> +     (service-extension
> +      home-shepherd-service-type
> +      home-udiskie-shepherd-service)
> +     (service-extension
> +      home-xdg-configuration-files-service-type
> +      add-udiskie-configuration)))
> +   (description "Set up a udiskie daemon to automount removable media.")
> +   (default-value (home-udiskie-configuration))))
> +
> +(define (generate-home-udiskie-documentation)
> +  (generate-documentation
> +   `((home-udiskie-configuration
> +      ,home-udiskie-configuration-fields))
> +   'home-udiskie-configuration))

Don't need to include this function.  Other than that LGTM.  Thank you
for working on this! :)

> -- 
> 2.41.0

-- 
Best regards,
Andrew Tropin

Re: [PATCH v3 2/3] tests: serializers: Add yaml-test.

Details
Message ID
<87zg2t6b91.fsf@trop.in>
In-Reply-To
<03e5844396e584bf6b3eecd8b19c40232425ec58.1691965992.git.mail@migalmoreno.com> (view parent)
DKIM signature
missing
Download raw message
On 2023-08-14 00:36, Miguel Ángel Moreno wrote:

> ---
> * Add full-fledged test example with sample Synapse configuration
>  tests/rde/serializers/yaml-test.scm | 142 ++++++++++++++++++++++++++++
>  1 file changed, 142 insertions(+)
>  create mode 100644 tests/rde/serializers/yaml-test.scm
>
> diff --git a/tests/rde/serializers/yaml-test.scm b/tests/rde/serializers/yaml-test.scm
> new file mode 100644
> index 00000000..994d5ab3
> --- /dev/null
> +++ b/tests/rde/serializers/yaml-test.scm
> @@ -0,0 +1,142 @@
> +;;; rde --- Reproducible development environment.
> +;;;
> +;;; Copyright © 2023 Miguel Ángel Moreno <mail@migalmoreno.com>
> +;;;
> +;;; This file is part of rde.
> +;;;
> +;;; rde is free software; you can redistribute it and/or modify it
> +;;; under the terms of the GNU General Public License as published by
> +;;; the Free Software Foundation; either version 3 of the License, or (at
> +;;; your option) any later version.
> +;;;
> +;;; rde is distributed in the hope that it will be useful, but
> +;;; WITHOUT ANY WARRANTY; without even the implied warranty of
> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +;;; GNU General Public License for more details.
> +;;;
> +;;; You should have received a copy of the GNU General Public License
> +;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.
> +
> +(define-module (rde serializers yaml-test)
> +  #:use-module (guix gexp)
> +  #:use-module (rde serializers yaml)
> +  #:use-module (rde tests)
> +  #:use-module (rde tests store)
> +  #:use-module (ice-9 match))
> +
> +(define (serialize-yaml config)
> +  (eval-with-store (yaml-serialize config)))
> +
> +(define-test yaml-terms
> +  (test-group "YAML basic values"
> +    (test-equal "number"
> +      "123"
> +      (serialize-yaml-term 123))
> +    (test-equal "string"
> +      "\"string here\""
> +      (serialize-yaml-term "string here"))
> +    (test-equal "symbol"
> +      "symbol_here"
> +      (serialize-yaml-term 'symbol_here))
> +    (test-assert "gexp"
> +      (gexp?
> +       (serialize-yaml-term #~"gexp")))
> +    (test-equal "true" "true" (serialize-yaml-term #t))
> +    (test-equal "false" "false" (serialize-yaml-term #f))
> +    (test-error "list" #t (serialize-yaml-term '(a b c)))
> +    (test-error "vector" #t (serialize-yaml-term #(a b c)))))
> +
> +(define-test yaml-lists
> +  (test-group "YAML lists"
> +    (test-equal "basic list"
> +      "[a, b, c]"
> +      (serialize-yaml '(a b c))))
> +  (test-group "YAML alists"
> +    (test-equal "basic alist"
> +      "a: b"
> +      (serialize-yaml '((a . b))))
> +    (test-equal "nested alist"
> +      "logging: \
> +
> +  print_level: debug"
> +      (serialize-yaml '((logging . ((print_level . debug))))))
> +    (test-error "invalid key" #t (serialize-yaml-config '((1 . test))))))
> +
> +(define-test yaml-vectors
> +  (test-group "YAML vectors"
> +    (test-equal "basic vector"
> +      "
> +- a
> +- b
> +- c"
> +      (serialize-yaml #(a b c)))
> +    (test-equal "nested alist"
> +      "
> +- names: [client, federation]
> +  compress: false"
> +      (serialize-yaml #(((names . (client federation))
> +                         (compress . #f)))))
> +    (test-error "nested list" #t (serialize-yaml #(())))))
> +
> +(define-test yaml-example-config
> +  (test-group "example config"
> +    (test-equal "full length example"
> +      "\
> +server_name: \"matrix.org\"
> +public_base_url: \"https://matrix.org\"
> +media_store_path: \"/var/lib/matrix-synapse/media_store\"
> +max_upload_size: \"50M\"
> +enable_registration: false
> +report_stats: true
> +database: \
> +
> +  name: psycopg2
> +  allow_unsafe_locale: true
> +  args: \
> +

Is an empty line intentional here?

> +    user: \"matrix-synapse\"
> +    database: \"matrix-synapse\"
> +    host: localhost
> +    port: 5432
> +    cp_min: 5
> +    cp_max: 10
> +listeners: \
> +
> +  - port: 8008
> +    tls: false
> +    type: http
> +    x_forwarded: true
> +    bind_addresses: \
> +
> +      - \"::1\"
> +      - \"127.0.0.1\"
> +    resources: \
> +
> +      - names: [client, federation]
> +        compress: false
> +trusted_key_servers: \
> +
> +  - server_name: \"matrix.org\""
> +      (serialize-yaml
> +       '((server_name . "matrix.org")
> +         (public_base_url . "https://matrix.org")
> +         (media_store_path . "/var/lib/matrix-synapse/media_store")
> +         (max_upload_size . "50M")
> +         (enable_registration . #f)
> +         (report_stats . #t)
> +         (database . ((name . psycopg2)
> +                      (allow_unsafe_locale . #t)
> +                      (args . ((user . "matrix-synapse")
> +                               (database . "matrix-synapse")
> +                               (host . localhost)
> +                               (port . 5432)
> +                               (cp_min . 5)
> +                               (cp_max . 10)))))
> +         (listeners . #(((port . 8008)
> +                         (tls . #f)
> +                         (type . http)
> +                         (x_forwarded . true)
> +                         (bind_addresses . #("::1" "127.0.0.1"))
> +                         (resources . #(((names . (client federation))
> +                                         (compress . #f)))))))
> +         (trusted_key_servers . #(((server_name . "matrix.org")))))))))
> -- 
> 2.41.0

-- 
Best regards,
Andrew Tropin

Re: [PATCH v3 2/3] tests: serializers: Add yaml-test.

Details
Message ID
<86fs4kv8pj.fsf@migalmoreno.com>
In-Reply-To
<87zg2t6b91.fsf@trop.in> (view parent)
DKIM signature
missing
Download raw message
On 2023-08-14 16:48, Andrew Tropin wrote:

> On 2023-08-14 00:36, Miguel Ángel Moreno wrote:
>
>> ---
>> * Add full-fledged test example with sample Synapse configuration
>>  tests/rde/serializers/yaml-test.scm | 142 ++++++++++++++++++++++++++++
>>  1 file changed, 142 insertions(+)
>>  create mode 100644 tests/rde/serializers/yaml-test.scm
>>
>> diff --git a/tests/rde/serializers/yaml-test.scm b/tests/rde/serializers/yaml-test.scm
>> new file mode 100644
>> index 00000000..994d5ab3
>> --- /dev/null
>> +++ b/tests/rde/serializers/yaml-test.scm
>> @@ -0,0 +1,142 @@
>> +;;; rde --- Reproducible development environment.
>> +;;;
>> +;;; Copyright © 2023 Miguel Ángel Moreno <mail@migalmoreno.com>
>> +;;;
>> +;;; This file is part of rde.
>> +;;;
>> +;;; rde is free software; you can redistribute it and/or modify it
>> +;;; under the terms of the GNU General Public License as published by
>> +;;; the Free Software Foundation; either version 3 of the License, or (at
>> +;;; your option) any later version.
>> +;;;
>> +;;; rde is distributed in the hope that it will be useful, but
>> +;;; WITHOUT ANY WARRANTY; without even the implied warranty of
>> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> +;;; GNU General Public License for more details.
>> +;;;
>> +;;; You should have received a copy of the GNU General Public License
>> +;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.
>> +
>> +(define-module (rde serializers yaml-test)
>> +  #:use-module (guix gexp)
>> +  #:use-module (rde serializers yaml)
>> +  #:use-module (rde tests)
>> +  #:use-module (rde tests store)
>> +  #:use-module (ice-9 match))
>> +
>> +(define (serialize-yaml config)
>> +  (eval-with-store (yaml-serialize config)))
>> +
>> +(define-test yaml-terms
>> +  (test-group "YAML basic values"
>> +    (test-equal "number"
>> +      "123"
>> +      (serialize-yaml-term 123))
>> +    (test-equal "string"
>> +      "\"string here\""
>> +      (serialize-yaml-term "string here"))
>> +    (test-equal "symbol"
>> +      "symbol_here"
>> +      (serialize-yaml-term 'symbol_here))
>> +    (test-assert "gexp"
>> +      (gexp?
>> +       (serialize-yaml-term #~"gexp")))
>> +    (test-equal "true" "true" (serialize-yaml-term #t))
>> +    (test-equal "false" "false" (serialize-yaml-term #f))
>> +    (test-error "list" #t (serialize-yaml-term '(a b c)))
>> +    (test-error "vector" #t (serialize-yaml-term #(a b c)))))
>> +
>> +(define-test yaml-lists
>> +  (test-group "YAML lists"
>> +    (test-equal "basic list"
>> +      "[a, b, c]"
>> +      (serialize-yaml '(a b c))))
>> +  (test-group "YAML alists"
>> +    (test-equal "basic alist"
>> +      "a: b"
>> +      (serialize-yaml '((a . b))))
>> +    (test-equal "nested alist"
>> +      "logging: \
>> +
>> +  print_level: debug"
>> +      (serialize-yaml '((logging . ((print_level . debug))))))
>> +    (test-error "invalid key" #t (serialize-yaml-config '((1 . test))))))
>> +
>> +(define-test yaml-vectors
>> +  (test-group "YAML vectors"
>> +    (test-equal "basic vector"
>> +      "
>> +- a
>> +- b
>> +- c"
>> +      (serialize-yaml #(a b c)))
>> +    (test-equal "nested alist"
>> +      "
>> +- names: [client, federation]
>> +  compress: false"
>> +      (serialize-yaml #(((names . (client federation))
>> +                         (compress . #f)))))
>> +    (test-error "nested list" #t (serialize-yaml #(())))))
>> +
>> +(define-test yaml-example-config
>> +  (test-group "example config"
>> +    (test-equal "full length example"
>> +      "\
>> +server_name: \"matrix.org\"
>> +public_base_url: \"https://matrix.org\"
>> +media_store_path: \"/var/lib/matrix-synapse/media_store\"
>> +max_upload_size: \"50M\"
>> +enable_registration: false
>> +report_stats: true
>> +database: \
>> +
>> +  name: psycopg2
>> +  allow_unsafe_locale: true
>> +  args: \
>> +
>
> Is an empty line intentional here?
>

Yes, I included a line escape so it takes into account the white space
after the colon.

>> +    user: \"matrix-synapse\"
>> +    database: \"matrix-synapse\"
>> +    host: localhost
>> +    port: 5432
>> +    cp_min: 5
>> +    cp_max: 10
>> +listeners: \
>> +
>> +  - port: 8008
>> +    tls: false
>> +    type: http
>> +    x_forwarded: true
>> +    bind_addresses: \
>> +
>> +      - \"::1\"
>> +      - \"127.0.0.1\"
>> +    resources: \
>> +
>> +      - names: [client, federation]
>> +        compress: false
>> +trusted_key_servers: \
>> +
>> +  - server_name: \"matrix.org\""
>> +      (serialize-yaml
>> +       '((server_name . "matrix.org")
>> +         (public_base_url . "https://matrix.org")
>> +         (media_store_path . "/var/lib/matrix-synapse/media_store")
>> +         (max_upload_size . "50M")
>> +         (enable_registration . #f)
>> +         (report_stats . #t)
>> +         (database . ((name . psycopg2)
>> +                      (allow_unsafe_locale . #t)
>> +                      (args . ((user . "matrix-synapse")
>> +                               (database . "matrix-synapse")
>> +                               (host . localhost)
>> +                               (port . 5432)
>> +                               (cp_min . 5)
>> +                               (cp_max . 10)))))
>> +         (listeners . #(((port . 8008)
>> +                         (tls . #f)
>> +                         (type . http)
>> +                         (x_forwarded . true)
>> +                         (bind_addresses . #("::1" "127.0.0.1"))
>> +                         (resources . #(((names . (client federation))
>> +                                         (compress . #f)))))))
>> +         (trusted_key_servers . #(((server_name . "matrix.org")))))))))
>> -- 
>> 2.41.0

-- 
Best regards,
Miguel Ángel Moreno

Re: [PATCH v3 3/3] home: Add udiskie-service-type.

Details
Message ID
<86bkf8v8m2.fsf@migalmoreno.com>
In-Reply-To
<87350l7qe3.fsf@trop.in> (view parent)
DKIM signature
missing
Download raw message
On 2023-08-14 16:35, Andrew Tropin wrote:

> On 2023-08-14 00:37, Miguel Ángel Moreno wrote:
>
>> ---
>>  src/rde/home/services/desktop.scm | 83 +++++++++++++++++++++++++++++++
>>  1 file changed, 83 insertions(+)
>>  create mode 100644 src/rde/home/services/desktop.scm
>>
>> diff --git a/src/rde/home/services/desktop.scm b/src/rde/home/services/desktop.scm
>> new file mode 100644
>> index 00000000..5b64f0f5
>> --- /dev/null
>> +++ b/src/rde/home/services/desktop.scm
>> @@ -0,0 +1,83 @@
>> +;;; rde --- Reproducible development environment.
>> +;;;
>> +;;; Copyright © 2023 Miguel Ángel Moreno <mail@migalmoreno.com>
>> +;;;
>> +;;; This file is part of rde.
>> +;;;
>> +;;; rde is free software; you can redistribute it and/or modify it
>> +;;; under the terms of the GNU General Public License as published by
>> +;;; the Free Software Foundation; either version 3 of the License, or (at
>> +;;; your option) any later version.
>> +;;;
>> +;;; rde is distributed in the hope that it will be useful, but
>> +;;; WITHOUT ANY WARRANTY; without even the implied warranty of
>> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> +;;; GNU General Public License for more details.
>> +;;;
>> +;;; You should have received a copy of the GNU General Public License
>> +;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.
>> +
>> +(define-module (rde home services desktop)
>> +  #:use-module (gnu services)
>> +  #:use-module (gnu services shepherd)
>> +  #:use-module (gnu services configuration)
>> +  #:use-module (gnu home services)
>> +  #:use-module (gnu home services shepherd)
>> +  #:use-module (gnu packages linux)
>> +  #:use-module (gnu packages freedesktop)
>> +  #:use-module (guix packages)
>> +  #:use-module (guix gexp)
>> +  #:use-module (rde serializers yaml)
>> +  #:export (home-udiskie-configuration
>> +            home-udiskie-service-type))
>> +
>> +(define-configuration/no-serialization home-udiskie-configuration
>> +  (udiskie
>> +   (package udiskie)
>> +   "The udiskie package to use.")
>> +  (config
>> +   (yaml-config '())
>> +   "Udiskie configuration."))
>> +
>> +(define (home-udiskie-profile-service config)
>> +  (list (home-udiskie-configuration-udiskie config)))
>> +
>> +(define (home-udiskie-shepherd-service config)
>> +  (list
>> +   (shepherd-service
>> +    (provision '(udiskie))
>> +    (stop #~(make-kill-destructor))
>> +    (start #~(make-forkexec-constructor
>> +              (list
>> +               #$(file-append
>> +                  (home-udiskie-configuration-udiskie config)
>> +                  "/bin/udiskie")))))))
>> +
>> +(define (add-udiskie-configuration config)
>> +  `(("udiskie/config.yml"
>> +     ,(mixed-text-file "config.yml"
>> +                       (yaml-serialize
>> +                        (home-udiskie-configuration-config config))))))
>> +
>> +(define home-udiskie-service-type
>> +  (service-type
>> +   (name 'udiskie)
>> +   (extensions
>> +    (list
>> +     (service-extension
>> +      home-profile-service-type
>> +      home-udiskie-profile-service)
>> +     (service-extension
>> +      home-shepherd-service-type
>> +      home-udiskie-shepherd-service)
>> +     (service-extension
>> +      home-xdg-configuration-files-service-type
>> +      add-udiskie-configuration)))
>> +   (description "Set up a udiskie daemon to automount removable media.")
>> +   (default-value (home-udiskie-configuration))))
>> +
>> +(define (generate-home-udiskie-documentation)
>> +  (generate-documentation
>> +   `((home-udiskie-configuration
>> +      ,home-udiskie-configuration-fields))
>> +   'home-udiskie-configuration))
>
> Don't need to include this function.  Other than that LGTM.  Thank you
> for working on this! :)
>

Sure, I'll remove it.  Merging this and marking it as APPLIED.

>> -- 
>> 2.41.0

-- 
Best regards,
Miguel Ángel Moreno
Reply to thread Export thread (mbox)