Subject: Re: bug#65062: [PATCH core-updates] packages: Lookup inputs by specification.

From: Ludovic Courtès <[email-masked]>
Date: Wed, 20 Dec 2023 22:26:51 +0100

Hi,

Hilton Chain <[email-masked]> skribis:

> * guix/packages.scm (specification->inputs): New procedure.
> (lookup-input,replace-input): Use it.
> (delete-input): New procedure.
> (modify-inputs)[delete]: Use it.

I’ve been thinking about this change lately.

The problem we have now is that it looks like input labels are gone, but
they’re not; in particular ‘modify-inputs’ preserves labels, which is a
source of confusion.  For instance, if you do:

  (modify-inputs x
    (replace "openmpi" mpich))

then ‘mpich’ remains associated with the “openmpi” label.  Ugh.

So I sympathize with the goal.  I think we can do something simpler
though:

>  (define (lookup-input inputs name)
>    "Lookup NAME among INPUTS, an input list."
>    ;; Note: Currently INPUTS is assumed to be an input list that contains input
>    ;; labels.  In the future, input labels will be gone and this procedure will
>    ;; check package names.
> -  (match (assoc-ref inputs name)
> -    ((obj) obj)
> -    ((obj _) obj)
> -    (#f #f)))
> +  (let ((candidates (specification->inputs name inputs)))
> +    (and (not (null? candidates))
> +         (second (first candidates)))))

How about:

  (find (match-lambda
          ((_ (? package? package) . _)
           (string=? (package-name package) name))
          (_ #f))
        inputs)

?

That way, ‘lookup-input’ would honor package names and ignore labels.

> +(define (delete-input name inputs)
> +  "Delete input NAME within INPUTS."
> +  (let ((to-delete (specification->inputs name inputs)))
> +    (lset-difference equal? inputs to-delete)))

And we do something similar here.

Thus, no need to fiddle with specifications.

How does that sound?

Now, I think this is the way forward, but I also think it’s going to
break many packages and workflows (‘--with-input’…).  So it should go
hand in hand with an effort to fully remove labels in Guix.

Thanks,
Ludo’.