Subject: [bug#60788] [PATCH] services: Add vnstat-service-type.

From: Ludovic Courtès <[email-masked]>
Date: Thu, 20 Apr 2023 12:09:54 +0200

Hello!

Bruno Victal <[email-masked]> skribis:

>>> +@item @code{database-dir} (default: @code{"/var/lib/vnstat"}) (type: string)
>> 
>> [...]
>> 
>>> +@item @code{create-dirs?} (default: @code{#t}) (type: maybe-boolean)
>> 
>> For consistency, both within this record and with the rest of Guix, I
>> suggest avoiding abbreviations.  Since this will be part of the API,
>> better fix it now than later.
>
> I should mention that almost all of the field names here are near verbatim
> vnstat config-file directives, i.e. a near 1-1 Scheme translation of vnstat config.
> This has the benefit that it makes serialization pretty much straightforward.
>
> It's possible to override their names by the use of the custom serializer parameter
> but would it be acceptable to leave them as-is?

Hmm, I’d say that if the cost of using “nice names” is “really high”,
then yes.  But perhaps we can make that cost low by having a map for the
few cases where we use a name different from upstream?

  (define field-name-mapping
    '((database-directory . "database_dir") …))

> (define-module (gnu tests vnstat)

Woohoo, you rock!

>             (test-assert "vnstatd is logging"
>               ;; pump garbage into the "discard" service within the vm
>               ;; TODO: guile socket client instead? Is it feasible?
>               (let* ((socat #$(file-append socat "/bin/socat"))
>                      (dest-addr #$(format #f "TCP4:localhost:~d"
>                                           forwarded-port))
>                      (args `("socat" "-u" "/dev/zero" ,dest-addr))
>                      ;; XXX: Guile bug (22/03/2023, Guile 3.0.9)
>                      ;;      Fixed in main: <https://issues.guix.gnu.org/61073>
>                      #;(output-port (%make-void-port "w"))
>                      (garbage-pump-pid (spawn socat args)))

You can probably connect directly to DEST-ADDR from Guile instead of
going through ‘socat’?

If not, you can either pass ‘#:guile guile-3.0-latest’ to
‘gexp->derivation’ so you get ‘spawn’ (3.0.9 is the default in
‘core-updates’ anyway), or use ‘primitive-fork’.

HTH!

Ludo’.