[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Best practices for writing services
From: |
Joshua Branson |
Subject: |
Re: Best practices for writing services |
Date: |
Fri, 19 Mar 2021 12:12:06 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
Xinglu Chen <public@yoctocell.xyz> writes:
> Hi Guix,
>
> I am going to write an mcron service for `guix home`[1][2] and before
> proceding, I would like to get some suggestions on what the best
> practices are for writing services in Guix.
Please note that I am a guix documentation contributor, and I am not
quite a guix developer yet. :) Though I do have a patch pending on
http://issues.guix.gnu.org/39136 (not certain why the 2/2 patch does
not show, 'cause I saw that come through in my inbox).
>
> Currently there seems to be two main ways to do this, the first one
> is the define one or more records for the configuration field of a
> service using `define-record-type*`, see the tor service in (gnu
> services networking) for example. The other method is to use
> `define-configuration` to declare the configuration fields of a service,
> see the transmission service in (gnu services file-sharing) for example.
I believe that the first method via define-record-type* seems to be the
recommended method to do this. I only say that because I feel like more
services are defined that way now. :)
> The second method removes quite a lot of boilerplate and the developer
> will define different serializers that convert scheme syntax like lists,
> alist, boolean... to the "real" configuration syntax of the program. It
> also does some automatic typechecking to some degree and allows the
> developer to write docstrings for each configuration field. There is
> then a procedure called `generate-documentation` which can automatically
> generate texinfo documenation from the docstrings.
I do like that generate-documentation procedure. Perhaps we could add
that for the define-record-type* somehow...
>
> I couldn't find any information in the manual regarding what conventions
> should be used when writing services for Guix and would like to hear
> from more experienced Guix hackers what the best practices are.
You might try asking in irc in #guix too!
I've been working on a sway service and an endlessh service in my
hacking videos
(https://video.hardlimit.com/accounts/joshua_branson/video-channels). I
was running into issues, where I could compile the service, but trying
to reconfigure my system would result in errors. The errors messages
were a little vague. I will also say that the better method I have
found in writing a guix service is to
1) write the service as simply as possible first. I personally would
copy the simplest service that you can find in gnu/services/ and modify
that via a M-x anzu-query-replace-regexp. If re-configuring works, make a
commit.
2) If possible, containerize the service. If it works, make a commit.
3) Now start adding in all the features you left out before.
--
Joshua Branson (joshuaBPMan in #guix)
Sent from Emacs and Gnus
https://gnucode.me
https://video.hardlimit.com/accounts/joshua_branson/video-channels
https://propernaming.org
"You can have whatever you want, as long as you help
enough other people get what they want." - Zig Ziglar