Subject: Re: bug#65665: package-mapping with #:deep? #t doesn't get all the implicit inputs

From: Ludovic Courtès <[email-masked]>
Date: Thu, 12 Oct 2023 16:06:47 +0200

Ulf Herrman <[email-masked]> skribis:

> -(define (build-system-with-package-mapping bs rewrite)
> +(define (build-system-with-package-mapping bs rewrite-input rewrite-argument)
>    "Return a variant of BS, a build system, that rewrites a bag's inputs by
>  passing them through REWRITE, a procedure that takes an input tuplet and
>  returns a \"rewritten\" input tuplet."
> @@ -1442,9 +1442,10 @@ (define (build-system-with-package-mapping bs rewrite)
>      (let ((lowered (apply lower args)))
>        (bag
>          (inherit lowered)
> -        (build-inputs (map rewrite (bag-build-inputs lowered)))
> -        (host-inputs (map rewrite (bag-host-inputs lowered)))
> -        (target-inputs (map rewrite (bag-target-inputs lowered))))))
> +        (build-inputs (map rewrite-input (bag-build-inputs lowered)))
> +        (host-inputs (map rewrite-input (bag-host-inputs lowered)))
> +        (target-inputs (map rewrite-input (bag-target-inputs lowered)))
> +        (arguments (map rewrite-argument (bag-arguments lowered))))))

Aah, now I understand.  :-)

It’s indeed the case that arguments can capture references to packages
that won’t be caught by ‘package-mapping’.  For instance, if you write:

  (package
    …
    (arguments (list … #~(whatever #$coreutils))))

… then ‘coreutils’ here cannot be replaced.

To address this, the recommendation is to always add dependencies to
input fields and to use self-references within arguments.  The example
above should be written like this:

  (package
    …
    (arguments
     (list … #~(whatever #$(this-package-input "coreutils")))))

It’s just a recommendation and one can perfectly ignore it, and I
suppose that was the impetus for this patch.

This is one of the things discussed while designing this change:

  https://guix.gnu.org/en/blog/2021/the-big-change/
  (search for “self-referential records”)

  https://issues.guix.gnu.org/49169

My take was and still is that it’s an acceptable limitation.  Packagers
need to follow the guideline above if they want proper support for
rewriting, ‘guix graph’, and other tools.

WDYT?

Thanks,
Ludo’.