* bug#66510: `this-package' references reintroduce pre-transformation packages.
@ 2023-10-13 3:57 Ulf Herrman
2024-04-09 14:06 ` bug#66510: Unexpected `this-package(-native)-input` Jake
0 siblings, 1 reply; 2+ messages in thread
From: Ulf Herrman @ 2023-10-13 3:57 UTC (permalink / raw)
To: 66510
[-- Attachment #1: Type: text/plain, Size: 2927 bytes --]
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
https://guix.gnu.org/en/blog/2021/the-big-change/ under the
"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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 686 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* bug#66510: Unexpected `this-package(-native)-input`
2023-10-13 3:57 bug#66510: `this-package' references reintroduce pre-transformation packages Ulf Herrman
@ 2024-04-09 14:06 ` Jake
0 siblings, 0 replies; 2+ messages in thread
From: Jake @ 2024-04-09 14:06 UTC (permalink / raw)
To: 66510
[-- Attachment #1: Type: text/plain, Size: 714 bytes --]
Hi Ulf
Has any progress been made on this?
I ran into the same thing, except with native-inputs instead of inputs.
I spent a fair amount of time trying to pin it down, since I don't know
much guile and it requires a combination of conditions to manifest.
Is it worth documenting this behaviour? Or do we expect a solution will be
implemented soon enough?
For now, is the following guideline accurate enough to avoid these
surprises?
If we inherit a package that uses (either directly or through inheritance)
this-package-native-input (or this-package-input), we should not modify the
native inputs (or inputs) via replace if substitute-keyword-arguments is
used anywhere in the inheritance chain.
Thanks
Jake
[-- Attachment #2: Type: text/html, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-09 14:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-13 3:57 bug#66510: `this-package' references reintroduce pre-transformation packages Ulf Herrman
2024-04-09 14:06 ` bug#66510: Unexpected `this-package(-native)-input` Jake
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).