unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: Xinglu Chen <public@yoctocell.xyz>
Cc: guix-devel@gnu.org
Subject: Re: Best practices for writing services
Date: Wed, 21 Apr 2021 14:05:00 -0400	[thread overview]
Message-ID: <8735vjcy43.fsf@gmail.com> (raw)
In-Reply-To: <87k0ov7w72.fsf@yoctocell.xyz> (Xinglu Chen's message of "Wed, 21 Apr 2021 12:45:21 +0200")

Hi Xinglu,

Xinglu Chen <public@yoctocell.xyz> writes:

> Hi,
>
> On Tue, Apr 20 2021, Maxim Cournoyer wrote:
>
>> That's a very good question, which I asked myself recently when
>> attempting to write my first non-trivial service for Guix
>> (jami-daemon-service-type).  I'd say 'define-configuration' is
>> technically superior because of the automatic type checking it provides.
>> It's also neat to be able to define the doc at one place and
>> auto-generate it (although that's still manual for now).
>
> You mean that one has to manually evaluate the ‘generate-documentation’
> sexp and paste the output of it in the manual?  I thought it would
> automatically update the manual when running ‘make’. ;)

Yes, that's my current understanding of how things are.  It could be
changed, for sure.

>> It has definitely been collecting some dust compared to the simpler
>> approach using 'define-record-type*' directly, and the doc output it
>> can generate doesn't match what is currently the norm in the manual,
>> so it'd need a bit of a refresh.
>
> Yeah, I noticed that some sections in the manual looked a bit different
> than the rest.
>
> One thing that I find a little annoying is that you have to specify a
> default value for the fields.  This doesn’t make much sense in some
> cases, e.g. there is no good default value for ‘user.name = NAME’ in the
> Git config, the user should have to specify that themselves.

There's a 'define-maybe' that can be used to declare a field that can
take more than one type, e.g.:

(define-maybe string)

Will generate a definition like so:

--8<---------------cut here---------------start------------->8---
(define (maybe-string? val)
               (or (eq? val 'disabled) (string? val)))
--8<---------------cut here---------------end--------------->8---

Which the validator of define-configuration will use if you specify a
field with the type 'maybe-string'.

'disabled is a bit semantically broken in some cases ('unspecified'
could be nicer), but it does the job.

> Another thing is that I don’t always want to “serialize-” the value for a
> field, so I sometimes end up defining a bunch of dummy serializers that
> just return an empty string.

Good point!  I've tried addressing that, without success so far [0].

Maxim

[0]  https://lists.gnu.org/archive/html/guix-devel/2021-04/msg00184.html


  reply	other threads:[~2021-04-21 18:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18 15:23 Best practices for writing services Xinglu Chen
2021-03-19 16:12 ` Joshua Branson
2021-03-19 17:01   ` Xinglu Chen
2021-04-21  3:54 ` Maxim Cournoyer
2021-04-21 10:45   ` Xinglu Chen
2021-04-21 18:05     ` Maxim Cournoyer [this message]
2021-04-22  7:27       ` Xinglu Chen
2021-04-23  4:42         ` Maxim Cournoyer
2021-04-23  6:04           ` Xinglu Chen
2021-04-21 22:10     ` raingloom
2021-04-22  7:19       ` Xinglu Chen
2021-04-26 20:29         ` raingloom

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8735vjcy43.fsf@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=guix-devel@gnu.org \
    --cc=public@yoctocell.xyz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).