Subject: bug#53915: No way of replacing an input in modify-input syntax structure but keep all the outputs

From: Ludovic Courtès <[email-masked]>
Date: Tue, 08 Mar 2022 17:11:36 +0100

Hi,

Gordon Quad <[email-masked]> skribis:

> poppler package include glib as a native-input with "bin" output.
>
> If I am doing the following:
>
> (package/inherit poppler
>     (native-inputs
>         (modify-inputs (package-native-inputs poppler)
>             (replace "glib" my-glib))))
>
> poppler's build will fail becuase replace syntax will replace "glib"
> package erasing its outputs.

Indeed:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,use(gnu packages pdf)
scheme@(guile-user)> ,use(guix)
scheme@(guile-user)> (package-native-inputs poppler)
$4 = (("pkg-config" #<package [email-masked] gnu/packages/pkg-config.scm:36 7f9b13a30580>) ("glib" #<package [email-masked] gnu/packages/glib.scm:180 7f9b12990000> "bin") ("gobject-introspection" #<package [email-masked] gnu/packages/glib.scm:428 7f9b12994e70>))
scheme@(guile-user)> (package-propagated-inputs poppler)
$5 = (("glib" #<package [email-masked] gnu/packages/glib.scm:180 7f9b12990000>))
scheme@(guile-user)> (modify-inputs (append $5 $4)
		       (replace "glib" xpdf))
$6 = (("glib" #<package [email-masked] gnu/packages/pdf.scm:395 7f9b1457c9a0>) ("pkg-config" #<package [email-masked] gnu/packages/pkg-config.scm:36 7f9b13a30580>) ("glib" #<package [email-masked] gnu/packages/pdf.scm:395 7f9b1457c9a0>) ("gobject-introspection" #<package [email-masked] gnu/packages/glib.scm:428 7f9b12994e70>))
--8<---------------cut here---------------end--------------->8---

We see that both ‘glib’ packages have been replaced, but the “bin” part
has been removed from the second one.

With the patch below, we get more sensible behavior:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (modify-inputs (append $5 $4)
		       (replace "glib" xpdf))
$8 = (("glib" #<package [email-masked] gnu/packages/pdf.scm:395 7f9b1457c9a0>) ("pkg-config" #<package [email-masked] gnu/packages/pkg-config.scm:36 7f9b13a30580>) ("glib" #<package [email-masked] gnu/packages/pdf.scm:395 7f9b1457c9a0> "bin") ("gobject-introspection" #<package [email-masked] gnu/packages/glib.scm:428 7f9b12994e70>))
--8<---------------cut here---------------end--------------->8---

If that makes sense to you, I’ll go ahead with this change and adjust
documentation accordingly.

Thanks for bringing it up!

Ludo’.

diff --git a/guix/packages.scm b/guix/packages.scm
index 3f0262602d..288ae37523 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -1091,11 +1091,11 @@ (define (replace-input name replacement inputs)
   "Replace input NAME by REPLACEMENT within INPUTS."
   (map (lambda (input)
          (match input
-           (((? string? label) . _)
+           (((? string? label) _ . outputs)
             (if (string=? label name)
                 (match replacement        ;does REPLACEMENT specify an output?
                   ((_ _) (cons label replacement))
-                  (_     (list label replacement)))
+                  (_     (cons* label replacement outputs)))
                 input))))
        inputs))