[bug#63985,RFC,0/5] Generic INI serializer & SRFI-171 for define-configuration

Message ID cover.1686343642.git.mirai@makinata.eu
Headers
Series Generic INI serializer & SRFI-171 for define-configuration |

Message

Bruno Victal June 9, 2023, 9:18 p.m. UTC
This RFC patch series (more like 3 patch series for the price of 1)
implements the following:

* Serializer Keyword arguments parameter in define-configuration.
  Allows for serializing procedures to be specified as:
    (define* (serialize-string field-name value #:key …)
      …)
  Examples in the unit tests.

* Express serialize-configuration with SRFI-171 transducers.
  The ‘base-transducer’ can be used to craft more specialized
  configuration record serializers.

* Generic INI serializer.
  This procedure can be used for crafting INI files from a
  record-type defined with define-configuration.
  Example for generic-ini in action can be found in the unit test.


These changes are motivated in part by a (in progress) refactoring of
the NetworkManager service-type.

Notes:
* I've left Generic-INI and serializer-kwargs undocumented since this
  is at its RFC stage.
* The (gnu services configuration generic-ini) module contains some trailing
  notes that should be removed before merging in.
* jami-account->alist explicitly checks for the empty-string.
  (which I consider to be a serialization “artifact” arising from define-maybe)
  This is the only (relevant) test that failed and will need to be investigated.

Bruno Victal (5):
  services: configuration: Simplify normalize-extra-args.
  services: configuration: Use transducers within
    serialize-configuration.
  services: fstrim-service-type: Serialize with SRFI-171 transducers.
  services: configuration: Add serializer-kwargs field.
  services: configuration: New generic-ini module.

 Makefile.am                                  |   1 +
 gnu/local.mk                                 |   1 +
 gnu/services/configuration.scm               |  86 +++++++++----
 gnu/services/configuration/generic-ini.scm   | 129 +++++++++++++++++++
 gnu/services/linux.scm                       |  11 +-
 tests/services/configuration.scm             |  38 +++++-
 tests/services/configuration/generic-ini.scm | 106 +++++++++++++++
 7 files changed, 333 insertions(+), 39 deletions(-)
 create mode 100644 gnu/services/configuration/generic-ini.scm
 create mode 100644 tests/services/configuration/generic-ini.scm


base-commit: c348b1be3891e6eb47bbdd9fc1587aba2b6ab0b7
  

Comments

Bruno Victal June 26, 2023, 9:57 p.m. UTC | #1
This patch-series is an agglomeration of smaller but weakly-related
patch-series, done so in order to build up the case for the changes.
I structured the series in order to make it suitable for cherry-picking.


Summary of changes:

* Plumbing changes to serialize-configuration

By orienting it around SRFI-171 transducers, it's now easier
to build custom configuration serializing procedures.

* New define-configuration syntax: serializer-options

Serializers may now accept more than two arguments.

* New module (gnu services configuration generic-ini)

* Deduplicate often used predicates.

* network-manager-service-type cleanup & new fields.



Notable changes since v2:

* Documentation changes

The documentation for define-configuration was reworded to make later
syntax extensions easier to document.
In addition, the new 'serializer-options' is now documented.


* (gnu services configuration) changes

** New predicates.

Reduce code duplication by migrating some commonly used predicates into
this module.


* generic-ini changes

** Initial field testing

Some deficiencies were found & corrected while doing a first field
testing when network-manager-service-type was refactored to make use
of this module.

** generic-ini- serializers

** Handling of multiple entries

Implemented as a transducer, this is useful to deal with escape-hatch
fields.


* network-manager-service-type changes

** Use define-configuration for <network-manager-configuration>

** Refactored serialization process to use the new generic-ini module

** New configuration fields: log-configuration and extra-options

Provides an escape hatch for options not yet implemented in the
record type.

** Renamed fields: 'network-manager' to 'package'

Naming the field 'package' is more informative & less confusing than a
reduplication of the package-name with the field-name itself.



Omissions in generic-ini:

For now, I've omitted:
* Custom leading (presumed to be whitespace) characters for entries
  à la gitconfig, mostly beautifying purposes
* Configurable delimiter (\n, \r\n, \0, ...)
* Configurable Key-value separator (this is usually =)

These can be implemented later if required.



Notes:

The interface in (gnu services configuration generic-ini) is still in its
infancy and might require further adjustments/additions and I'm still
thinking about its potential generalizations to TOML & co.
For the time being I'd prefer not to promise any interface stability.



Nice to haves:

I didn't have much luck in replacing the memq approach in the predicate
with define-enumeration:

--8<---------------cut here---------------start------------->8---
;; This works.
(define (network-manager-log-level? x)
  (memq x '(off err warn info debug trace)))

;; This does not.
(define-enumeration network-manager-log-level?
  (off err warn info debug trace)
  network-manager-log-level-set)

;; While executing meta-command:
;; ERROR:
;;   1. &origin: "network-manager-log-level?"
;;   2. &message: "not a member of the set"
;;   3. &syntax:
;;      form: #f
;;      subform: #f
--8<---------------cut here---------------end--------------->8---

Would be nice to know what went wrong and whether an enumeration could
be used here instead.


Bruno Victal (11):
  services: configuration: Simplify normalize-extra-args.
  services: configuration: Use transducers within
    serialize-configuration.
  services: fstrim-service-type: Serialize with SRFI-171 transducers.
  doc: Rewrite define-configuration.
  services: configuration: Add serializer-options field.
  services: configuration: New generic-ini module.
  services: configuration: Add some commonly used predicates.
  services: NetworkManager: Use define-configuration and generic-ini.
  services: NetworkManager: Prefer package over network-manager.
  services: NetworkManager: add log-configuration field.
  services: NetworkManager: Add extra-options field.

 Makefile.am                                  |   1 +
 doc/guix.texi                                | 161 +++++----
 gnu/local.mk                                 |   1 +
 gnu/services/audio.scm                       |   7 +-
 gnu/services/configuration.scm               | 108 ++++--
 gnu/services/configuration/generic-ini.scm   | 165 +++++++++
 gnu/services/linux.scm                       |  11 +-
 gnu/services/networking.scm                  | 352 ++++++++++++++-----
 gnu/services/telephony.scm                   |  49 ++-
 tests/services/configuration.scm             |  88 ++++-
 tests/services/configuration/generic-ini.scm | 129 +++++++
 11 files changed, 861 insertions(+), 211 deletions(-)
 create mode 100644 gnu/services/configuration/generic-ini.scm
 create mode 100644 tests/services/configuration/generic-ini.scm


base-commit: ac86174e22fcd762893bd4515786b1376af9397b
  
Bruno Victal Oct. 7, 2023, 3:57 p.m. UTC | #2
Notable changes since v3:
* Reduced series scope for SRFI-171 related changes and documentation
improvements.
* Added docstrings.
  Note: docstring for `serialize-configuration' lifted from guix.texi.
* Addressed feedback from v3.

Bruno Victal (5):
  services: configuration: Simplify normalize-extra-args.
  services: configuration: Use transducers within
    serialize-configuration.
  services: fstrim-service-type: Serialize with SRFI-171 transducers.
  doc: Rewrite define-configuration.
  services: configuration: Add some commonly used predicates.

 doc/guix.texi                    | 108 +++++++++++++------------------
 gnu/services/audio.scm           |   7 +-
 gnu/services/configuration.scm   |  81 +++++++++++++++++------
 gnu/services/linux.scm           |  11 ++--
 gnu/services/telephony.scm       |  49 ++++++--------
 tests/services/configuration.scm |   6 +-
 6 files changed, 136 insertions(+), 126 deletions(-)


base-commit: b566e1a98a74d84d3978cffefd05295602c9445d