Subject: bug#63263: closed (Re: bug#63263: [PATCH] gexp: Stop generating unreadable builder scripts.)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 02 Sep 2023 10:40:01 +0000

Your bug report

#63263: [PATCH] gexp: Stop generating unreadable builder scripts.

which was filed against the guix-patches package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
63263: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63263
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#63263: [PATCH] gexp: Stop generating unreadable builder scripts.
From: Christopher Baines <[email-masked]>
To: Maxim Cournoyer <[email-masked]>
Cc: [email-masked]
Date: Sat, 02 Sep 2023 11:36:43 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Maxim Cournoyer <[email-masked]> writes:

> Hi Christopher,
>
> Christopher Baines <[email-masked]> writes:
>
> [...]
>
>>>> I think pretty much all the i586-gnu derivations
>>>
>>> Oh, I see.  I’m less surprised then.  :-)
>>>
>>>> were broken in this way, on core-updates but then after the merge to
>>>> master too. I think I've "fixed" it now, although I think my change
>>>> [1] needs some improvement (I fixed some issues in [2], but I saw an
>>>> error when cross building).
>>>
>>> I think we’re good now, right?
>>
>> I spotted problems again today. I'm not sure if they're new, or just
>> things I missed in the last round of fixes.
>>
>> I'm waiting for the data service to give it's opinion on these changes:
>>
>>   https://issues.guix.gnu.org/63416
>
> Was the problem resolved?  If so, can we close this issue?

Nope, but the issue covering this is #62051.

We can close this patch issue though, as I think there were objections
to the approach.

Subject: [PATCH] gexp: Stop generating unreadable builder scripts.
From: Christopher Baines <[email-masked]>
To: [email-masked]
Date: Thu, 4 May 2023 12:24:48 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

In Guile, it's possible to produce output from write that can't be read, and
this applies to the code staged through g-expressions for derivations.  This
commit detects this early when the derivation is being created, rather than
leaving the error to happen when the derivation is built.

This is important as it means that tools like guix lint will indicate that
there's a problem, hopefully reducing the number of broken derivations in
Guix.

* guix/gexp.scm (gexp->derivation): Check that the builder script can be read.
---
 guix/gexp.scm | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/guix/gexp.scm b/guix/gexp.scm
index 0fe4f1c98a..7af9302ccf 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -1215,9 +1215,18 @@ (define (add-modules exp modules)
                                                          #:target target)
                                        (return #f)))
                        (guile -> (lowered-gexp-guile lowered))
-                       (builder  (text-file script-name
-                                            (sexp->string
-                                             (lowered-gexp-sexp lowered)))))
+                       (builder  (text-file
+                                  script-name
+                                  (let ((builder-string
+                                         (sexp->string
+                                          (lowered-gexp-sexp lowered))))
+                                    (catch 'read-error
+                                      (lambda ()
+                                        (call-with-input-string builder-string
+                                          read)
+                                        builder-string)
+                                      (lambda (key . args)
+                                        (error "invalid gexp" name exp  args)))))))
     (mbegin %store-monad
       (set-grafting graft?)                       ;restore the initial setting
       (raw-derivation name
-- 
2.39.1