From: Michal Atlas <michal_atlas+gnu@posteo.net>
To: guix-devel@gnu.org
Subject: Re: Syntactic Diabetes (was Re: A friendlier API for operating-system declarations)
Date: Sun, 26 Nov 2023 05:36:00 +0000 [thread overview]
Message-ID: <2da427d0-7f7c-f226-8c54-20ad669956aa@posteo.net> (raw)
In-Reply-To: <jnjf5B_RIA-iDBpFDNOAW8x81BRfH-iJa4Sglg6cC0yM2HPz3UbDtjsyGrdtf4UQSwn3PRM15kabJS6c9LGbuenMYBq0dbkfgnYnYeN7TrE=@lendvai.name>
Hello guix,
I'll chime in because I've been playing around with this kind of thing
in my channel [1]
for a bit now and perhaps some of the ideas will be deemed useful.
> (service+ OS SERVICE [CONF])
> (service- OS SERVICE)
> (modify-service OS SERVICE UPDATE)
I found that defining a functional API like this is about as convenient
as the original version, more examples: [2].
Another small change I tried was to not have -> be a macro but rather a
simple fold.
I took what the dot-macro form expands to and made it a curried function
called services
(but remove and modify could be equivalently defined),
which takes a service and then returns a lambda that takes an OS and
modifies it
just as the beaver-labs macros do with that extra service.
(define ((services . new) os)
(operating-system
(inherit os)
(user-services
(append new (operating-system-user-services os)))))
(define (-> system . services)
(fold (cut <> <>) system services))
(-> os (services (service openssh-service-type)) ...) ; yields os with
added openssh
((services (service openssh-service-type)) os) ; equivalent
The one macro that is indispensable for terse configurations is still
some sort of service+ (I use &s as the name),
which appends -service-type, surrounds the body in a -configuration [3],
and in my case calls `services` on it for good measure to get the os
modifying lambda straight from the service+ clause.
(-> os
(&s openssh)
(&s guix-publish
(advertise? #t))
...)
This ends up save for 2 extra characters being syntactically almost
identical to the original version,
just passes around lambdas instead of getting manipulated by nested macros.
Them being functions they're now easier to work with with in more
traditional Scheme ways,
for example compose works, and we can wrap them in other functions that
for example apply them only in some circumstances.
Or combine transformations into new ones. The definitions for which end
up being remarkably short and generalizable.
(-> os
(compose (os/hostname "the-dam.org") (&s gpm)) ; freely composable
with other functions of the same sort
(%services-with-arguments ...) ; indifferent to being composed on the
spot even in the middle of threading
(if-host "hydra" (&s openssh)) ; only adds openssh if the host is
named hydra, simple function
; since the second argument is just a function that may or
may not be applied by the new lambda
((mapped-file-systems <some-devices> ...)
<more-devices-that-depend-on-former> ...))) ; not threading by
macro allows more complex structures without confusion
Then again none of this has had proper field testing, the fact that it
has less gotchas is just a personal opinion.
Cheers, and all the best
[1]:
https://git.sr.ht/~michal_atlas/guix-channel/tree/a31b68b46da60002383e2793eba88b99fc5c2382/item/atlas/combinators.scm
(modified from the original beaver-labs version).
[2]:
https://git.sr.ht/~michal_atlas/dotfiles/tree/8c78f53139ae176ff0a4cab82ad0fb64bce6989b/item/atlas/config/system/services.scm#L56
[3]:
https://git.sr.ht/~michal_atlas/guix-channel/tree/master/item/atlas/utils/services.scm#L53
next prev parent reply other threads:[~2023-11-26 19:05 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-23 8:06 A friendlier API for operating-system declarations Edouard Klein
2023-03-23 18:48 ` Josselin Poiret
2023-03-23 20:23 ` Edouard Klein
2023-03-23 21:05 ` Liliana Marie Prikler
2023-04-13 9:42 ` Ludovic Courtès
2023-05-18 14:37 ` Edouard Klein
2023-11-24 21:43 ` Syntactic Diabetes (was Re: A friendlier API for operating-system declarations) Edouard Klein
2023-11-24 22:50 ` Liliana Marie Prikler
2023-11-25 20:14 ` Attila Lendvai
2023-11-26 5:36 ` Michal Atlas [this message]
2023-11-26 16:49 ` Edouard Klein
2023-11-26 18:32 ` Liliana Marie Prikler
2023-11-26 20:46 ` Edouard Klein
2023-11-27 21:09 ` Liliana Marie Prikler
2023-11-29 20:12 ` Attila Lendvai
2023-11-29 23:39 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
2023-11-30 11:16 ` Attila Lendvai
2023-12-01 18:18 ` Michal Atlas
2024-02-01 13:29 ` Introducing Guix "Features"! (Was: Syntactic Diabetes) Felix Lechner via Development of GNU Guix and the GNU System distribution.
2024-02-01 19:43 ` Liliana Marie Prikler
2024-02-01 20:30 ` Attila Lendvai
2024-02-01 20:46 ` Liliana Marie Prikler
2024-02-02 20:11 ` Attila Lendvai
2024-02-01 21:02 ` Ricardo Wurmus
2024-02-02 19:36 ` Attila Lendvai
2024-02-02 20:21 ` Vagrant Cascadian
2024-02-02 21:25 ` Attila Lendvai
2024-02-02 0:03 ` Introducing Guix "Features"! Carlo Zancanaro
2024-02-18 15:07 ` Introducing Guix "Features"! (Was: Syntactic Diabetes) Edouard Klein
2023-12-09 10:12 ` Syntactic Diabetes (was Re: A friendlier API for operating-system declarations) Ludovic Courtès
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=2da427d0-7f7c-f226-8c54-20ad669956aa@posteo.net \
--to=michal_atlas+gnu@posteo.net \
--cc=guix-devel@gnu.org \
/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).