(address . bug-guix@gnu.org)
Suppose you have a package that is using a gexp in its argument list
and, like a good citizen of the gexp world, it uses this-package-input
to refer to its own input packages. In fact, let's suppose that it's
the model citizen depicted in
"G-expressions and self-referential records" heading:
(define hello
(package
(name "hello")
;; …
(arguments
(list #:configure-flags
#~(list (string-append "--with-gawk="
#$(this-package-input "gawk")))))
(inputs `(("gawk" ,gawk)))))
If we define a variant like so:
(define hello-variant
(package
(inherit hello)
(name "hello-variant")
(inputs `(("gawk" ,gawk-4.0)))))
it will work just fine. But if we define a variant like SO:
(define hello-variant
(package
(inherit hello)
(name "hello-variant")
(inputs `(("gawk" ,gawk-4.0)))
(arguments
(substitute-keyword-arguments (package-arguments hello)
((#:configure-flags flags #~'())
#~(cons "--with-hospitality=ice-cream"
#$flags))))))
it will NOT work just fine. When (package-arguments hello) is
evaluated, it will execute the field definition for `hello' with
`this-package' bound to `hello', rather than `hello-variant'.
Consequently, `this-package-input' will return gawk rather than
gawk-4.0. We need a way to access the "parent" package's fields while
keeping `this-package' bound to its current value. The most general
form of this would look something like this:
(define (package-arguments-with-package p0 p)
(match p0
(($ <package> _ _ _ _ arguments-proc)
(arguments-proc p))))
Then hello-variant could be changed to use
(package-arguments-with-package hello this-package)
instead of (package-arguments hello). This may be needlessly general,
though; the problem could also be solved with an interface more along
the lines of
(parent-package-arguments hello)
which expands into the aforementioned package-arguments-with-package
call.
Another option would be to, yet again, extend the record syntax. It's
always bugged me a bit to have to explicitly reference the original
record in more than one place when using derived fields, so this might
be generally useful as well:
(define hello-variant
(package
(inherit hello
(arguments hello-arguments))
(name "hello-variant")
(inputs `(("gawk" ,gawk-4.0)))
(arguments
(substitute-keyword-arguments hello-arguments
((#:configure-flags flags #~'())
#~(cons "--with-hospitality=ice-cream"
#$flags))))))
This would create a macro named `hello-arguments' within the scope of
the (package ...) form which expands into something equivalent to a
`parent-package-arguments' call. Adjust syntax to taste.
Thoughts?
- Ulf
-----BEGIN PGP SIGNATURE-----
iQHIBAEBCAAyFiEEn6BUn0yca1D9JsMa1lV76sJM9mgFAmUowBoUHHN0cmluZXNz
QHRpbGRlLmNsdWIACgkQ1lV76sJM9mhMggv+KB3jA1cTdS9iUoGC2tJWHNvWYAjp
tq6kaKJgop/2hgxcdPuhB37Lcx3TOCTJoVFzL7Mpni6o4k2UolgERYMy9hUCzXul
XZhqoLrSvDWfQEpoKzFNMZaVGC6PSirFdFb3XteyrfiWyjH/INgL/IX+V91g93Si
/ZR7Ks6CiRuQ5MReW2LzyhiDx64KXEnE3oUCnqKUfDJgLtHD/bFqqK3ZqjIPeIir
4pPDfq2pyH8MqQAx5cQjfmQwVoX1RNKITISHlvIAZvTVsp7oCJV0Rvg/Pg+8kpFI
P6eKyzsJJbZx4NYVRpXAXXpfcn5D02CjGErOYrFolK+HLT5KlyNc6FYFQstOyoB2
vAu/WYaSBD4rfaT6iSL4m9zH4kMb6pl2sLkgMP5QPYK2i0zsnvjAqBc+2SPOwpvE
n52+uq7w/WtqzcZCYzmezunTK9VvGy50+HkfC2aVDpckpC3HSklotkDhJkn8PHwy
bxxxDRP9nfcG9YirGPJrJ+Y5G0UmBvAniMkR
=8Su+
-----END PGP SIGNATURE-----