Subject: Re: [bug#71928] [PATCH v2] gnu: Throw error when extending services that do not use extensions.

From: Ludovic Courtès <[email-masked]>
Date: Mon, 30 Sep 2024 22:43:36 +0200

Hello,

Richard Sent <[email-masked]> skribis:

> * gnu/services.scm (fold-services): Add error handling when using service
> extensions.
>
> Fixes: https://issues.guix.gnu.org/71887
> Change-Id: Ic8d631674bfddde495c93952d9e6cd5649bb287d

[...]

> @@ -1223,12 +1224,22 @@ (define* (fold-services services
>                       (params     -> (service-value sink))
>                       (service
>                        ->
> -                      ;; Distinguish COMPOSE and EXTEND because PARAMS typically
> -                      ;; has a different type than the elements of EXTENSIONS.
> -                      (if extend
> -                          (service (service-kind sink)
> -                                   (extend params (compose extensions)))
> -                          sink)))
> +                      (begin
> +                        (unless (or (null? extensions)
> +                                    ;; A value of #t is a convention for "make
> +                                    ;; sure the service is present."
> +                                    (every (cut eq? #t <>) extensions)
> +                                    (and extend compose))
> +                          (error (format #f "Extensions are not supported in \
> +~a yet the following service types extend it:~{~%   ~a~}"
> +                                         (service-kind sink)
> +                                         (map service-kind dependents))))
> +                        ;; Distinguish COMPOSE and EXTEND because PARAMS typically
> +                        ;; has a different type than the elements of EXTENSIONS.
> +                        (if extend
> +                            (service (service-kind sink)
> +                                     (extend params (compose extensions)))
> +                            sink))))

I understand the current situation where extensions to a non-extensible
service are silently swallowed is suboptimal, but I wonder about the
implications of the semantic change here.

Currently the “#t means ensure the service is present” convention is not
enforced; is it even widely followed in the Guix repo?  But then, what
about repos out there that provide services?

It would seem to me that this is something that cannot be changed
overnight without running the risk to break people’s code.  So perhaps
the first step (and maybe last step?) would be to print a warning.

WDYT?

Thanks,
Ludo’.