Subject: bug#36777: Guix Inferiors: Curious incorrect derivation output bug

From: Ludovic Courtès <[email-masked]>
Date: Sat, 27 Jul 2019 23:48:57 +0200

Ludovic Courtès <[email-masked]> skribis:

> For future reference, the bisect output is:
>
>   # first bad commit: [5cf4b26d52bcea382d98fb4becce89be9ee37b55] derivations: <derivation-input> now aggregates a <derivation>.

Does the patch below have any effect?

My understanding is that it shouldn’t have any effect (because inputs
have already been coalesced at that point), but that’s one place where
5cf4b26d52bcea382d98fb4becce89be9ee37b55 introduced a difference.

Thanks in advance,
Ludo’.

diff --git a/guix/derivations.scm b/guix/derivations.scm
index 92d50503ce..eb94fea55e 100644
--- a/guix/derivations.scm
+++ b/guix/derivations.scm
@@ -239,12 +239,17 @@ the store."
   "Return a list of inputs, such that when INPUTS contains the same DRV twice,
 they are coalesced, with their sub-derivations merged.  This is needed because
 Nix itself keeps only one of them."
+  (define (derivation-file-name* obj)
+    (if (derivation? obj)
+        (derivation-file-name obj)
+        obj))
+
   (fold (lambda (input result)
           (match input
-            (($ <derivation-input> (= derivation-file-name path) sub-drvs)
+            (($ <derivation-input> (= derivation-file-name* path) sub-drvs)
              ;; XXX: quadratic
              (match (find (match-lambda
-                            (($ <derivation-input> (= derivation-file-name p)
+                            (($ <derivation-input> (= derivation-file-name* p)
                                                    s)
                              (string=? p path)))
                           result)
@@ -685,7 +690,7 @@ name of each input with that input's hash."
                              (make-derivation-input hash sub-drvs))))
                         inputs)))
        (make-derivation outputs
-                        (sort inputs
+                        (sort (coalesce-duplicate-inputs inputs)
                               (lambda (drv1 drv2)
                                 (string<? (derivation-input-derivation drv1)
                                           (derivation-input-derivation drv2))))