Subject: bug#76110: Broken i686 package on x86_64 since commit 28e4018e59

From: David Elsing <[email-masked]>
Date: Sat, 08 Feb 2025 13:01:26 +0000

Hi,

Denis 'GNUtoo' Carikli <[email-masked]> writes:

> And the process gave the commit 28e4018e59d30efb3d52aa950ce2261f11b69b33
> ("grafts: Allow file-like objects in the ‘replacement’ field of
> <graft>.").
>
> However I didn't look into how to repair the behavior above as I'm not
> familiar at all with the code that the 28e4018e59 patch touches.

The problematic change with commit 28e4018e59 is that the 'system'
argument in `input-graft' (and `system' and `target' in
`input-cross-graft') is no longer respected for the replacement, such
that the 'origin' and 'replacement' fields are built for a different
system. Therefore, I would suggest to indeed add another wrapping by
`with-parameters' to `input-graft' and `input-cross-graft' (but keeping
the `with-parameters' wrapping which sets %grafts in
`graft-derivation/shallow', even if it doesn't do anything yet [2]).

Attached is a patch with the change. Unlike other parameters, for which
`with-parameters' currently does not work with packages [2],
`%current-system' and `%current-target-system' are treated specially and
are working correctly.

However, this still does not really solve the issue for your package:
It still (correctly) calls `package->derivation' with the 'system'
argument set to "x86_64-linux", which is then overridden by the #:system
argument in the system package in `bag->derivation'.
The same is not the case however for grafts, and `graft-derivation*' is
still called with "x86_64-linux", which is arguably correct, but
inconsistent with the #:system package argument. IIUC, this leads to
grafts being missed, as some are calculated for "x86_64-linux" (which
are not applicable) and some for "i686-linux".

For reference, is setting #:system in a package even intended? It seems
more coincidental to me that it works, as the #:system argument of a package
overrides the previous #:system argument in `bag->derivation'.
I think it makes more sense to use `with-parameters', which works
correctly in this case (also without the new patch):

--8<---------------cut here---------------start------------->8---
(with-parameters
    ((%current-system "i686-linux"))
  postgresql-14)
--8<---------------cut here---------------end--------------->8---

Cheers,
David

[1] https://issues.guix.gnu.org/70895
[2] https://issues.guix.gnu.org/75879

diff --git a/guix/packages.scm b/guix/packages.scm
index 78726b089ae..43125bac61a 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -1824,7 +1824,9 @@ (define (input-graft system)
                         (return (graft
                                   (origin orig)
                                   (origin-output output)
-                                  (replacement replacement)
+                                  (replacement
+                                   (with-parameters ((%current-system system))
+                                     replacement))
                                   (replacement-output output))))
                       package output system)
              (return #f))))
@@ -1846,7 +1848,10 @@ (define (input-cross-graft target system)
                (return (graft
                          (origin orig)
                          (origin-output output)
-                         (replacement replacement)
+                         (replacement
+                          (with-parameters ((%current-system system)
+                                            (%current-target-system target))
+                            replacement))
                          (replacement-output output))))
              (return #f))))
       (_