Am Sonntag, dem 26.11.2023 um 17:49 +0100 schrieb Edouard Klein: > Thank you Liliana and Attila for the swift and actionable feedback :) > > Below is a revised proposition. > > Here is a minimal working example of an os declaration: > ------------------mwe.scm--------------- > (use-modules > (beaver system) > (beaver functional-services) > (gnu packages version-control) > (gnu services web) > (gnu services telephony) > (gnu services ssh) > (gnu services base) > (guix gexp)) > > (-> (minimal-ovh "osef") > (instantiate nginx) I do wish you spelled out service. Also, instantiate takes as much characters to type as add-service. > (instantiate mumble-server > (welcome-text "coucou") > (port 64738)) > (extend openssh `(("alice" ,(local-file > "/home/edouard/.ssh/id_rsa.pub")))) > (modify openssh > (password-authentication? #f) > (allow-empty-passwords? #t)) > (remove guix)) > ------------------------------------------------------- > > To see the value of this syntactic sugar, try to replicate this MWE > with the standard syntax. It's not horrendous, but it *is* off- > putting to many newcomers to git, whereas this sugary piece is more > readable for them (sample size of 1, p=0.00000005). Well, that'd be (let ((base (minimal-ovh "osef"))) (operating-system (inherit base) (services (cons* (service nginx-service-type) (service mumble-service-type (mumble-configuration (welcome-text "couocu") (port 64738))) (service openssh-service-type (openssh-configuation (password-authentication? #f) (allow-empty-passwords? #t) (authorized-keys <your-keys))) (operating-system-user-services base)) or (-> (minimal-ovh "osef") (lambda (base) …))
On that note, we also have extend-openssh-authorized-keys for the use with modify-services. > Here is the revised functional-services.scm, not yet commited and > pushed, and only lightly tested in local containers, but not in > production: > > Advice and comments welcome :) > > > ------------functional-services.scm-------------- > > > (define-module (beaver functional-services) > #:use-module (gnu system) > #:use-module (gnu services) > #:export (instantiate extend modify remove)) > > (define syntax->string (compose symbol->string syntax->datum)) > > (define (service-configuration stx service) > "Return the syntax one can use to refer to xxx-configuration for > the given > service" > (datum->syntax stx (string->symbol > (string-append > (syntax->string service) > "-configuration")))) > > (define (service-type stx service) > "Return the syntax one can use to refer to xxx-service-type for the > given > service" > (datum->syntax stx (string->symbol > (string-append > (syntax->string service) > "-service-type")))) > > (define-syntax instantiate > (lambda (stx) > (syntax-case stx () > [(_ os service-name) > (with-syntax > ([service-type (service-type stx #'service-name)]) > #'(begin > ((lambda (x) ;; It is wrapped in a lamba to make sure os > is > ;; evaluated once only. It it wasn't in a labmda, > whatever > ;; form os is in the calling code would be repeated > ;; multiple times, and so if the form was e.g. (some- > func > ;; os), then some-func would be called multiple times, > ;; which may not be desirable. Isn't it also wrapped in a lambda, because -> is a threading macro that takes functions rather than syntax? Cheers