Subject: bug#65665: [PATCH] Really get all the implicit inputs.

From: Ulf Herrman <[email-masked]>
Date: Sat, 16 Sep 2023 04:45:23 -0500

This patch series causes package-mapping to recurse into package and bag
arguments when #:deep? #t is given.  It also recurses into gexps and
gexp inputs in search of packages to devour.  It also ensures that build
systems leave all of their implicit package arguments in the bag
arguments, ready to be found by package-mapping.  It also fixes a couple
build system errors I came across while modifying 40+ build systems and
testing a deep package transformation.

- ulfvonbelow

From 73b2dfe98591073104fd069622ede2acab0c7655 Mon Sep 17 00:00:00 2001
Message-Id: <[email-masked]>
From: Ulf Herrman <[email-masked]>
Date: Fri, 15 Sep 2023 07:38:24 -0500
Subject: [PATCH 1/5] guix: packages: rewrite arguments with `package-mapping'.

* guix/gexp.scm (make-gexp, gexp-references, gexp-self-modules,
  gexp-self-extensions, gexp-proc, %gexp-location): export.
* guix/packages.scm (build-system-with-package-mapping): replace `rewrite'
  argument with `rewrite-input' and `rewrite-argument' arguments.  Use
  `rewrite-argument' to rewrite bag arguments.
  (package-mapping): rewrite package arguments when `deep?' is true.
---
 guix/gexp.scm     |  7 ++++++
 guix/packages.scm | 56 ++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/guix/gexp.scm b/guix/gexp.scm
index 0fe4f1c98a..6acd3116d4 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -39,6 +39,13 @@ (define-module (guix gexp)
   #:use-module (ice-9 match)
   #:export (gexp
             gexp?
+            make-gexp
+            gexp-references
+            gexp-self-modules
+            gexp-self-extensions
+            gexp-proc
+            %gexp-location
+
             sexp->gexp
             with-imported-modules
             with-extensions
diff --git a/guix/packages.scm b/guix/packages.scm
index ba98bb0fb4..1334def142 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -1431,7 +1431,7 @@ (define* (package-closure packages #:key (system (%current-system)))
                    (vhash-consq package #t visited)
                    (fold set-insert closure dependencies))))))))
 
-(define (build-system-with-package-mapping bs rewrite)
+(define (build-system-with-package-mapping bs rewrite-input rewrite-argument)
   "Return a variant of BS, a build system, that rewrites a bag's inputs by
 passing them through REWRITE, a procedure that takes an input tuplet and
 returns a \"rewritten\" input tuplet."
@@ -1442,9 +1442,10 @@ (define (build-system-with-package-mapping bs rewrite)
     (let ((lowered (apply lower args)))
       (bag
         (inherit lowered)
-        (build-inputs (map rewrite (bag-build-inputs lowered)))
-        (host-inputs (map rewrite (bag-host-inputs lowered)))
-        (target-inputs (map rewrite (bag-target-inputs lowered))))))
+        (build-inputs (map rewrite-input (bag-build-inputs lowered)))
+        (host-inputs (map rewrite-input (bag-host-inputs lowered)))
+        (target-inputs (map rewrite-input (bag-target-inputs lowered)))
+        (arguments (map rewrite-argument (bag-arguments lowered))))))
 
   (build-system
     (inherit bs)
@@ -1456,13 +1457,32 @@ (define* (package-mapping proc #:optional (cut? (const #f))
 depended on and returns the resulting package.  The procedure stops recursion
 when CUT? returns true for a given package.  When DEEP? is true, PROC is
 applied to implicit inputs as well."
-  (define (rewrite input)
+  (define (rewrite-input input)
     (match input
       ((label (? package? package) outputs ...)
        (cons* label (replace package) outputs))
       (_
        input)))
 
+  (define (rewrite-argument arg)
+    (match arg
+      ((? package? p)
+       (replace p))
+      ((? gexp-input? gi)
+       (gexp-input (rewrite-argument (gexp-input-thing gi))
+                   (gexp-input-output gi)
+                   #:native? (gexp-input-native? gi)))
+      ((? gexp? gxp)
+       (make-gexp (map rewrite-argument (gexp-references gxp))
+                  (gexp-self-modules gxp)
+                  (gexp-self-extensions gxp)
+                  (gexp-proc gxp)
+                  (%gexp-location gxp)))
+      ((lst ...)
+       (map rewrite-argument lst))
+      (_
+       arg)))
+
   (define mapping-property
     ;; Property indicating whether the package has already been processed.
     (gensym " package-mapping-done"))
@@ -1484,7 +1504,8 @@ (define* (package-mapping proc #:optional (cut? (const #f))
                      (inherit p)
                      (location (package-location p))
                      (replacement (package-replacement p))
-                     (propagated-inputs (map rewrite (package-propagated-inputs p)))
+                     (propagated-inputs (map rewrite-input
+                                             (package-propagated-inputs p)))
                      (properties `((,mapping-property . #t)
                                    ,@(package-properties p)))))))
 
@@ -1500,11 +1521,26 @@ (define* (package-mapping proc #:optional (cut? (const #f))
                  (location (package-location p))
                  (build-system (if deep?
                                    (build-system-with-package-mapping
-                                    (package-build-system p) rewrite)
+                                    (package-build-system p)
+                                    rewrite-input
+                                    rewrite-argument)
                                    (package-build-system p)))
-                 (inputs (map rewrite (package-inputs p)))
-                 (native-inputs (map rewrite (package-native-inputs p)))
-                 (propagated-inputs (map rewrite (package-propagated-inputs p)))
+                 (inputs (map rewrite-input (package-inputs p)))
+                 (native-inputs (map rewrite-input (package-native-inputs p)))
+                 (propagated-inputs
+                  (map rewrite-input (package-propagated-inputs p)))
+                 (arguments
+                  (match p
+                       (($ <package> _ _ _ _ args-proc)
+                        ;; If we let ARGS-PROC be passed its original package,
+                        ;; we somehow end up in an infinite (or maybe just
+                        ;; exponential? Never seen it end...) loop.  Should
+                        ;; probably figure out what's causing that at some
+                        ;; point.
+                        (let ((args (args-proc this-package)))
+                          (if deep?
+                              (map rewrite-argument args)
+                              args)))))
                  (replacement (and=> (package-replacement p) replace))
                  (properties `((,mapping-property . #t)
                                ,@(package-properties p)))))))))

base-commit: bfb480e76f7968f8e39e37e64681b0fd062edb1e
prerequisite-patch-id: b512735cd31c9f7564894ed3a5c1c3b921eeaed3
prerequisite-patch-id: d782bad3845786f3ef367822aeb146a1e5e994d7
prerequisite-patch-id: c277154bb5fbcb1e6a2af576d6f7eebde308b010
prerequisite-patch-id: 088174854de84cd796d4fe7f39386b1539a3df51
prerequisite-patch-id: 083848588d3bae9d392fb1270b64990f13209dbe
prerequisite-patch-id: 36801b82c0a0365ab18a3a6ad3814e8fbe1b0630
prerequisite-patch-id: de0adff180c2ea6e9d1c34f8f0b1d62ec7863ccf
prerequisite-patch-id: 7054626c27a5208550912b11e92bb16dab15fb34
prerequisite-patch-id: 5736a5673877a8185a80d0c9767f288bddc239d3
prerequisite-patch-id: 4e23b3ba151bebb40d56816915f9d0503fe1566b
prerequisite-patch-id: 4edcd21bef307dbe07a9605314aaa446f45a943f
prerequisite-patch-id: 0a98f8e01ac1df033a86b5f42d01dd9baece0807
prerequisite-patch-id: e55e0c751b9772a31656decb1aec8bcc193685b0
prerequisite-patch-id: 837b6cf8db48bdb22c7573ce0fb63a1a6255640b
prerequisite-patch-id: 0c07d4138fc33f6d976b7c7ff2d25b93145dc417
prerequisite-patch-id: 1875c8e646ce329f8a72da90367c3725c953b5c2
prerequisite-patch-id: 8c429132b33f94d9f910413f56e9b3ca18d0db43
prerequisite-patch-id: 121cf7bd1b560e8db138132990840a20c20c6636
prerequisite-patch-id: e9662377bc432936ffbfffaa10dff3a285eacd26
prerequisite-patch-id: cfd757e3df23f22fbd88441ecabfe21f37b4d140
prerequisite-patch-id: a563c6b6f53532a7a6fb7fe8ebbb11d237947b7f
prerequisite-patch-id: da271d8023063a789328959f5dc6389675d5d46a
prerequisite-patch-id: 271b2952dc050715c90848953e3586b35e21d184
prerequisite-patch-id: 92caaf95030c644dec30fc139a63e25b1dc8d48c
prerequisite-patch-id: e03d9290c61f083c96b084403e6dc69394ee2faa
prerequisite-patch-id: 3ca7c6fd53e9cd1c07bfb2e16763ecaf6d0cc4eb
prerequisite-patch-id: 018b82c741ee4e1370df059b22cc86aa4735644b
prerequisite-patch-id: a26834894fcd1380dfd5a979088114d50d0df392
prerequisite-patch-id: 8916b1ce832d695ecb86e4f36b3fe1a5529552dc
prerequisite-patch-id: 2230d379e61787c3327f89ef02c8de3ab879090d
prerequisite-patch-id: fb4536c142e85bb0a6610203ae25a74f7342351d
prerequisite-patch-id: dc0a3e2e36977cf203ad0c74650844758446c115
prerequisite-patch-id: f9e2903e96a7e6e08f9a9ce10e8f35650a2bc9d0
prerequisite-patch-id: 52609b8f7999fe1bfd2ad90aba421042b1e39a50
prerequisite-patch-id: 4b6138782ae74502be87966344f7bb5d88e8734c
prerequisite-patch-id: 411c9c605a4e89efe01841517486a3d6015be917
prerequisite-patch-id: e07e206a39a0b173786207d335740f08d0baecb2
prerequisite-patch-id: 424af6d825a003e67545f8f23fc292407a029a4e
prerequisite-patch-id: cd9480f3fbb837834ef9294aec9d25e797927456
prerequisite-patch-id: 2f401351ac266c92a77cbcf54549ce5bee78e93e
prerequisite-patch-id: aff161c12c59578d3d1e4569ad3bea0ab7fa231d
prerequisite-patch-id: 156e04e25c5f214fd5e9ba3a4548b960bf8d5142
prerequisite-patch-id: 61869ccfd561784d16df3d62dae522790b182ea0
prerequisite-patch-id: a19bb63b9c373c4f153545de121024c2f0008e03
prerequisite-patch-id: 92eb3cfcdb4791daed167477aa19d34400455f2b
prerequisite-patch-id: 7e00825d11982a64a671116fc30ebe34ff562974
prerequisite-patch-id: a920acf76ea0ed8484888c28f5803def46b496e8
prerequisite-patch-id: a2f4feda897c80d54fefac2979b34dc8755d2562
prerequisite-patch-id: 66bd73e2012a407a0ae8c07ead463bb87ac7ceb1
prerequisite-patch-id: c7703e99c566323d908bfdd31896401c61d9c6e9
prerequisite-patch-id: b05dec5daf49254938536568b1f0e259f85a5f27
prerequisite-patch-id: 2ec62060c8d777a316cb35a5956fca2d6340c238
prerequisite-patch-id: 5e47032571af5476c2a4d9bbbe9c98ac62736acf
prerequisite-patch-id: f3f2d80dc4d970ec7e27221b1713303a752602db
prerequisite-patch-id: cf272874f837a1089867a3c578ba773b9722e4bc
prerequisite-patch-id: 26b133febfaa8e56cacf9695fec9e47ac7752437
prerequisite-patch-id: 2370164c61289dc27dacd1a3fce404b42a5cd306
prerequisite-patch-id: 8e151f495e68d05d7ae3a58b75965ed6ad402cb3
prerequisite-patch-id: 1e1d8a1a5c3d2e7c012c3800b2f162bbfb11830e
prerequisite-patch-id: 20b2ba87fb4a1d22b2e5d189868953deb1b8432d
prerequisite-patch-id: 4b7a45d0216169dddf32b0556847edcf1fe83c77
prerequisite-patch-id: a7caa886acb871c8fae58942ea33c4830c1bf50a
prerequisite-patch-id: 4cb809d1af72bfb4160541432f84e7f7a2ec377c
prerequisite-patch-id: b8bba3077b9e27a14b7a4500145a546e2551920b
prerequisite-patch-id: 42371e75be346f69a66f1af370f10e19118d3666
prerequisite-patch-id: fbcbda683c60fc49fb0acb35e8fcba3632e33c1d
prerequisite-patch-id: 5a7497e62af0532f2262e825ecfffdc87b46a4cd
prerequisite-patch-id: 39515c3e9d305eca348d158422e1db32d02a2f6f
prerequisite-patch-id: cb139244b5614b18feeb19793713a1836e637e23
prerequisite-patch-id: 095b7088b6d2e2738d07a2c5409f9116640f1e8c
prerequisite-patch-id: 36e9e48ae432da7f9e0438ff3bd2476fb4ee17ef
prerequisite-patch-id: a0be866c6a75021f6d9ae024a5ebeb94f14ef039
prerequisite-patch-id: 0d424f7822bad63211e0f5f2e8432053fcc2280d
prerequisite-patch-id: a59b7626f41bf5570f2119e4b148c7da4370c604
prerequisite-patch-id: 3d4f86e81bda469eb2cac04b6781847f32ba2d4b
prerequisite-patch-id: d364cccdb604ed9d3d9b98d821ef1bcba2f93dd4
prerequisite-patch-id: ad4bbb2ffa1a81c85e6f7a3da474648c57abeb08
prerequisite-patch-id: b2ccfb33f49dcee45d0eae151d63c20619eba269
prerequisite-patch-id: 370503f330a01247f61b6f8da90cc1874addca9d
prerequisite-patch-id: bf97596682da5aa565d63e58806e64c57501bfbf
prerequisite-patch-id: ff1ce6c53974f6458a24f5d68d656514a49b496a
prerequisite-patch-id: abec97caff0781ddf8bac457259e336956d31f56
prerequisite-patch-id: 10b5231fdd5214c7ce994d13e9bc4accd9c3e98b
prerequisite-patch-id: 6c3ff15435a372b3c176d0ec839507093e7f75d5
prerequisite-patch-id: d874c3ae8cc9643fe65c0def0ab9f62a30ef265e
prerequisite-patch-id: 301b58dab98c976159b086b6d9b215f6cfc32560
prerequisite-patch-id: d946ee345019733d07c28073643c11d6a0265887
prerequisite-patch-id: eb86ebc23516ee5a1c69fad149fbf5a82fbf44e2
prerequisite-patch-id: f3aae14f0dc6bd6c07b5405db4efb8677eb109db
prerequisite-patch-id: a596041f0af7a7fb2ff8fc39e61c75d1add0b21a
prerequisite-patch-id: 6dc272118cfeb1aea0819a796beace8fa8305be7
prerequisite-patch-id: 8dea513488503b59c1971a20b6e5af36fab30f16
prerequisite-patch-id: 489930e028059725a437833f8144cba5b5f88275
prerequisite-patch-id: 101a681e226bba3d782559f9966ed75f6cfac4d0
prerequisite-patch-id: 02d84b8de56dcf379619cb73975e08541258a744
prerequisite-patch-id: 22eb2f65315c0eec851686f01a43772184be67c2
prerequisite-patch-id: f4013eaef497b4e39d5680ae87c388f5e90d962c
prerequisite-patch-id: e774f3f01024e9b0522c62d7f0e2e745d1eec9d6
prerequisite-patch-id: 6fea198a4035448351e7ab3c859f5ba7a9974e3e
prerequisite-patch-id: 9f9ee707bc7da130f29d23398775b7648345fddd
prerequisite-patch-id: fef59953278e9b5c86db36ff047117203aac756c
prerequisite-patch-id: 076981cbfd6fdf83498b0abbfab4aa41b17bf32f
prerequisite-patch-id: 63746b98da1e924ec78b707e0cab29e1913793e6
prerequisite-patch-id: 4c8b859607b829c54ea2bc94d8fd1807054e347f
prerequisite-patch-id: ca54f1fae5954706f3f4b46427b39f3096193e20
prerequisite-patch-id: 8d1176310f67c10d84f7d409152c45584637a5e1
prerequisite-patch-id: d973cfefc6c2621052370ef917c5a30b4b4c6153
prerequisite-patch-id: a16615ac67d4cfb2d7f991d41d7b88e536b8d1e6
prerequisite-patch-id: c99f1ac1c8f31966ab5eace82966b38d7683c7b6
prerequisite-patch-id: ea8cbbe7d266c8e01f92cf47c67a2b77ba2e2f2a
prerequisite-patch-id: 87f853bef8078737d6ee37152f9540dc318577b8
prerequisite-patch-id: 624ebedc4b5efd852396af22dfee278e81e18607
prerequisite-patch-id: b0386c11c46382a027d6feb7f8cee077fd1ce7f0
prerequisite-patch-id: f30932e3c494a7e2e758c71a15600f7d02e5fe3c
prerequisite-patch-id: c6e5542e49b9e990abfd941b82e6c8f47cce82eb
prerequisite-patch-id: 8ed51ac5bb592e2b9a3726d009b390eaf3d02a22
prerequisite-patch-id: 3eb38c477f4039d6dad8ea7657461d5b69582cea
prerequisite-patch-id: 604ec349a2100c97da1a9e86443e5fe670fc9aff
prerequisite-patch-id: 0ec9b5ad92a820364e736176265cbf38a6aa9865
prerequisite-patch-id: 9f9f6f4f5e6f3f38d57c8fc51dd6d1d1b13614aa
prerequisite-patch-id: 3084be13b8e6449d0739a66199d78fd83b273dc9
prerequisite-patch-id: 38129e693708c4068b779fe561befa0789da4e68
prerequisite-patch-id: e599d0af678fca48957ba931713ba46acf57cd26
prerequisite-patch-id: 82676aa787f2d5896dbcc966014c85933ee203bd
prerequisite-patch-id: 4e1a39929ca7eb97be4a265ab2961ebb00ac2494
prerequisite-patch-id: 928b20a27997c43597c625e6e431e9963b8a6cdc
prerequisite-patch-id: eea41f1a51b1062b9f7fe17ba9b0827bce4f7f8d
prerequisite-patch-id: 94d48d21b6e420f0d9bf99d9488136b667d047b4
prerequisite-patch-id: c06f0d333b33836de8800323e814d6dcf214fd78
prerequisite-patch-id: 44515b47a0e5f194b1e782bbbdf4597418c46f77
prerequisite-patch-id: 94eeb31189a81ccbf18dda42a72db715bec3a279
prerequisite-patch-id: d02e7863404940800b63dca3f328547df5cac24f
prerequisite-patch-id: c47b08cb4e7ab0a024a2be4b250c4b60ab0bab65
prerequisite-patch-id: fb2396bde2637b96c4412df6ef6a09e9c38e3365
prerequisite-patch-id: 7068eef2aa4f77ef304869b3661c25238f7497e5
prerequisite-patch-id: a2f06d63b11dce495cddad29f5f507a380ff23c2
prerequisite-patch-id: b21a55b8bf2bd23485e0d7d6433ec1f29acd6226
prerequisite-patch-id: 7fd6c9378b4c96bbc7e109f759fd4e7ff6bacba2
prerequisite-patch-id: b109590bb6082361a59547bf252f576a574b75e8
prerequisite-patch-id: f5aa2b7352ffec54c23277d9d4715bbd95c1eb79
prerequisite-patch-id: 2a9907079587beb938680221ededa8f5e0e7d4b2
prerequisite-patch-id: 90f4e54d0b451db6166dbd1d2067e07696e092bf
prerequisite-patch-id: 999ec11aaddd785d065911dcb1fc7385ccf053d6
prerequisite-patch-id: cc250a0b2267760feea1427573482db1bb8328e6
prerequisite-patch-id: b593f9fd55bbd9e855baba4b1037d844d5773916
prerequisite-patch-id: 74e3c356cee5e56d4dc3f5bc4f5705cd2ce75a1d
prerequisite-patch-id: 7443872a7242e134d8f95398c53f47d4ae21a23b
prerequisite-patch-id: da89093d1a5bb1dd8bb6436f4daf70eb4025eae9
prerequisite-patch-id: 3be9735669c6510ef29e75588bbf907d57733834
prerequisite-patch-id: 976e476ba476fe3cd730ac29c825fad81c6331d1
prerequisite-patch-id: 889a29b57cea9cb18f4f4a9c22b04d151b216e1d
prerequisite-patch-id: 6b6690e68606f4359e22656a7c6aeae5c58ea017
prerequisite-patch-id: c46954eddc80453f6d7c045fa22ec99a694d9693
prerequisite-patch-id: bdccc141b570181273512c2089d95e4ebcdae453
prerequisite-patch-id: ee3338d64821748f9a7d8ed9cf5e9181c2027252
prerequisite-patch-id: 7f7da1ba32e01163b013d5c4ac96aa468f6e908e
prerequisite-patch-id: 83a09cce225aaaa626b3f5d2f3a092055f61a909
prerequisite-patch-id: 7f31991b2e91782e9dd1c1a6fda5f055fdff3234
prerequisite-patch-id: 831310b4d4842a08ad12fdf5c07ce55b57db049d
prerequisite-patch-id: 9588d67009d034f36ceef115b158556b8cacb680
prerequisite-patch-id: e0807504b7c5f14f0af8bdbbdd800754888dd8f8
prerequisite-patch-id: 6e3d6e24505bd188d776720913c18c4b874c896c
prerequisite-patch-id: e20a2cd4b5a85889b97a5733863175fb56420d01
-- 
2.40.1

From dcd9b6505fa46d139d40141cf29d7eef15c46481 Mon Sep 17 00:00:00 2001
Message-Id: <[email-masked]>
In-Reply-To: <[email-masked]>
References: <[email-masked]>
From: Ulf Herrman <[email-masked]>
Date: Fri, 15 Sep 2023 07:48:48 -0500
Subject: [PATCH 2/5] build-system: asdf: use substitute-keyword-arguments with
 default.

A two-argument substitute-keyword-arguments clause won't be evaluated when
there isn't already a keyword in the argument list.  Using a three-argument
clause allows the phases-transformer to be run in all cases.

* guix/build-system/asdf.scm (package-with-build-system): use %standard-phases
  as default value of `phases', use gexps.
---
 guix/build-system/asdf.scm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/guix/build-system/asdf.scm b/guix/build-system/asdf.scm
index 2b17cee37b..cd041eed4f 100644
--- a/guix/build-system/asdf.scm
+++ b/guix/build-system/asdf.scm
@@ -218,7 +218,8 @@ (define* (package-with-build-system from-build-system to-build-system
           (build-system to-build-system)
           (arguments
            (substitute-keyword-arguments base-arguments
-             ((#:phases phases) (list phases-transformer phases))))
+             ((#:phases phases #~%standard-phases)
+              #~(#$phases-transformer #$phases))))
           (inputs (new-inputs package-inputs))
           (propagated-inputs (new-propagated-inputs))
           (native-inputs (append (if target-is-source?
-- 
2.40.1

From 4b42f9501284ad66d4de04f5b94bdaf412008d5d Mon Sep 17 00:00:00 2001
Message-Id: <[email-masked]>
In-Reply-To: <[email-masked]>
References: <[email-masked]>
From: Ulf Herrman <[email-masked]>
Date: Fri, 15 Sep 2023 08:31:58 -0500
Subject: [PATCH 3/5] build-system: include all argument packages in bag args
 explicitly.

Deep package transformations currently miss several implicit input packages
because they are introduced via the bag->derivation builder procedure.  This
is the case with, for example, qtbase in qt-build-system.  This can be avoided
by ensuring that those arguments are always explicitly specified in the bag
arguments list.  Notably, this is also the case for the guile used by the
generated build script, so every single build system that uses
gexp->derivation needs to be modified.

* guix/build-system/agda.scm (lower): include guile in bag arguments.
* guix/build-system/android-ndk.scm (lower): include guile in bag arguments.
* guix/build-system/ant.scm (lower): include guile in bag arguments.
* guix/build-system/asdf.scm (lower, lower/source):
  include guile in bag arguments.
* guix/build-system/cargo.scm (lower): include guile in bag arguments.
* guix/build-system/chicken.scm (lower): include guile in bag arguments.
* guix/build-system/clojure.scm (lower): include guile in bag arguments.
* guix/build-system/cmake.scm (lower): include guile in bag arguments.
* guix/build-system/copy.scm (lower): include guile in bag arguments.
* guix/build-system/dub.scm (lower): include guile in bag arguments.
* guix/build-system/dune.scm (lower): include guile in bag arguments.
* guix/build-system/elm.scm (lower): include guile in bag arguments.
* guix/build-system/emacs.scm (lower): include guile in bag arguments.
* guix/build-system/font.scm (lower): include guile in bag arguments.
* guix/build-system/glib-or-gtk.scm (lower): include guile in bag arguments.
* guix/build-system/gnu.scm (lower): include guile in bag arguments.
* guix/build-system/go.scm (lower): include guile in bag arguments.
* guix/build-system/guile.scm (lower): include guile in bag arguments.
* guix/build-system/haskell.scm (lower): include guile in bag arguments.
* guix/build-system/julia.scm (lower): include guile in bag arguments.
* guix/build-system/linux-module.scm (lower): include guile in bag arguments.
* guix/build-system/maven.scm (lower): include guile in bag arguments.
* guix/build-system/meson.scm (lower): include guile in bag arguments.
* guix/build-system/minify.scm (lower): include guile in bag arguments.
* guix/build-system/node.scm (lower): include guile in bag arguments.
* guix/build-system/ocaml.scm (lower): include guile in bag arguments.
* guix/build-system/perl.scm (lower): include guile in bag arguments.
* guix/build-system/pyproject.scm (lower): include guile in bag arguments.
* guix/build-system/python.scm (lower): include guile in bag arguments.
* guix/build-system/qt.scm (lower): include guile and qtbase in bag
  arguments.
* guix/build-system/r.scm (lower): include guile in bag arguments.
* guix/build-system/rakudo.scm (lower): include guile in bag arguments.
* guix/build-system/rebar.scm (lower): include guile in bag arguments.
* guix/build-system/renpy.scm (lower): include guile in bag arguments.
* guix/build-system/ruby.scm (lower): include guile in bag arguments.
* guix/build-system/scons.scm (lower): include guile in bag arguments.
* guix/build-system/texlive.scm (lower): include guile in bag arguments.
* guix/build-system/tree-sitter.scm (lower): include guile in bag arguments.
* guix/build-system/trivial.scm (lower): include guile in bag arguments.
---
 guix/build-system/agda.scm         |  6 +++++-
 guix/build-system/android-ndk.scm  |  6 +++++-
 guix/build-system/ant.scm          |  6 +++++-
 guix/build-system/asdf.scm         | 12 ++++++++++--
 guix/build-system/cargo.scm        |  6 +++++-
 guix/build-system/chicken.scm      |  6 +++++-
 guix/build-system/clojure.scm      |  7 +++++--
 guix/build-system/cmake.scm        |  6 +++++-
 guix/build-system/copy.scm         |  6 +++++-
 guix/build-system/dub.scm          |  6 +++++-
 guix/build-system/dune.scm         |  5 ++++-
 guix/build-system/elm.scm          |  6 +++++-
 guix/build-system/emacs.scm        |  6 +++++-
 guix/build-system/font.scm         |  6 +++++-
 guix/build-system/glib-or-gtk.scm  |  6 +++++-
 guix/build-system/gnu.scm          |  6 +++++-
 guix/build-system/go.scm           |  6 +++++-
 guix/build-system/guile.scm        |  5 ++++-
 guix/build-system/haskell.scm      |  4 +++-
 guix/build-system/julia.scm        |  6 +++++-
 guix/build-system/linux-module.scm |  6 +++++-
 guix/build-system/maven.scm        |  6 +++++-
 guix/build-system/meson.scm        |  6 +++++-
 guix/build-system/minify.scm       |  6 +++++-
 guix/build-system/node.scm         |  6 +++++-
 guix/build-system/ocaml.scm        |  6 +++++-
 guix/build-system/perl.scm         |  6 +++++-
 guix/build-system/pyproject.scm    |  6 +++++-
 guix/build-system/python.scm       |  6 +++++-
 guix/build-system/qt.scm           |  7 ++++++-
 guix/build-system/r.scm            |  6 +++++-
 guix/build-system/rakudo.scm       |  6 +++++-
 guix/build-system/rebar.scm        |  6 +++++-
 guix/build-system/renpy.scm        |  6 +++++-
 guix/build-system/ruby.scm         |  6 +++++-
 guix/build-system/scons.scm        |  6 +++++-
 guix/build-system/texlive.scm      |  6 +++++-
 guix/build-system/tree-sitter.scm  |  6 +++++-
 guix/build-system/trivial.scm      |  3 ++-
 guix/build-system/waf.scm          |  6 +++++-
 40 files changed, 199 insertions(+), 42 deletions(-)

diff --git a/guix/build-system/agda.scm b/guix/build-system/agda.scm
index 64983dff60..511f1f11b5 100644
--- a/guix/build-system/agda.scm
+++ b/guix/build-system/agda.scm
@@ -47,6 +47,7 @@ (define %default-modules
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (agda (default-agda))
+                (guile (default-guile))
                 gnu-and-haskell?
                 #:allow-other-keys
                 #:rest arguments)
@@ -73,7 +74,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build agda-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (agda-build name inputs
                      #:key
diff --git a/guix/build-system/android-ndk.scm b/guix/build-system/android-ndk.scm
index 047f884b19..064aacceaa 100644
--- a/guix/build-system/android-ndk.scm
+++ b/guix/build-system/android-ndk.scm
@@ -82,6 +82,7 @@ (define* (android-ndk-build name inputs
 
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -106,7 +107,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build android-ndk-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define android-ndk-build-system
   (build-system
diff --git a/guix/build-system/ant.scm b/guix/build-system/ant.scm
index cfb033f6a5..d4998b26e1 100644
--- a/guix/build-system/ant.scm
+++ b/guix/build-system/ant.scm
@@ -69,6 +69,7 @@ (define* (lower name
                 (jdk (default-jdk))
                 (ant (default-ant))
                 (zip (default-zip))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -92,7 +93,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build ant-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (ant-build name inputs
                     #:key
diff --git a/guix/build-system/asdf.scm b/guix/build-system/asdf.scm
index cd041eed4f..1adbe7d996 100644
--- a/guix/build-system/asdf.scm
+++ b/guix/build-system/asdf.scm
@@ -73,6 +73,7 @@ (define (default-lisp implementation)
 
 (define* (lower/source name
                        #:key source inputs outputs native-inputs system target
+                       (guile (default-guile))
                        #:allow-other-keys
                        #:rest arguments)
   "Return a bag for NAME"
@@ -91,7 +92,10 @@ (define* (lower/source name
          (build-inputs native-inputs)
          (outputs outputs)
          (build asdf-build/source)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (asdf-build/source name inputs
                             #:key source outputs
@@ -245,6 +249,7 @@ (define (lower lisp-type)
   (lambda* (name
             #:key source inputs outputs native-inputs system target
             (lisp (default-lisp (string->symbol lisp-type)))
+            (guile (default-guile))
             #:allow-other-keys
             #:rest arguments)
     "Return a bag for NAME"
@@ -264,7 +269,10 @@ (define (lower lisp-type)
                            ,@native-inputs))
            (outputs outputs)
            (build (asdf-build lisp-type))
-           (arguments (strip-keyword-arguments private-keywords arguments))))))
+           (arguments
+            (substitute-keyword-arguments
+                (strip-keyword-arguments private-keywords arguments)
+              ((#:guile _ #t) guile)))))))
 
 (define (asdf-build lisp-type)
   (lambda* (name inputs
diff --git a/guix/build-system/cargo.scm b/guix/build-system/cargo.scm
index 912400a191..84efea019e 100644
--- a/guix/build-system/cargo.scm
+++ b/guix/build-system/cargo.scm
@@ -238,6 +238,7 @@ (define* (lower name
                 (rust (default-rust))
                 (cargo-inputs '())
                 (cargo-development-inputs '())
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -264,7 +265,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build cargo-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define cargo-build-system
   (build-system
diff --git a/guix/build-system/chicken.scm b/guix/build-system/chicken.scm
index 9f518e66e6..ac1c5804ac 100644
--- a/guix/build-system/chicken.scm
+++ b/guix/build-system/chicken.scm
@@ -53,6 +53,7 @@ (define (default-chicken)
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (chicken (default-chicken))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -77,7 +78,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build chicken-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (chicken-build name inputs
                         #:key
diff --git a/guix/build-system/clojure.scm b/guix/build-system/clojure.scm
index fb897356bc..921edab912 100644
--- a/guix/build-system/clojure.scm
+++ b/guix/build-system/clojure.scm
@@ -75,6 +75,7 @@ (define* (lower name
                 (clojure (force %default-clojure))
                 (jdk (force %default-jdk))
                 (zip (force %default-zip))
+                (guile (default-guile))
                 outputs system
                 #:allow-other-keys
                 #:rest arguments)
@@ -98,8 +99,10 @@ (define* (lower name
                              ,@native-inputs))
              (outputs outputs)
              (build clojure-build)
-             (arguments (strip-keyword-arguments private-keywords
-                                                 arguments))))))
+             (arguments
+              (substitute-keyword-arguments
+                  (strip-keyword-arguments private-keywords arguments)
+                ((#:guile _ #t) guile)))))))
 
 (define* (clojure-build name inputs
                         #:key
diff --git a/guix/build-system/cmake.scm b/guix/build-system/cmake.scm
index aa187c9844..8db841992c 100644
--- a/guix/build-system/cmake.scm
+++ b/guix/build-system/cmake.scm
@@ -57,6 +57,7 @@ (define (default-cmake target)
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (cmake (default-cmake target))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -93,7 +94,10 @@ (define* (lower name
                        '()))
     (outputs outputs)
     (build (if target cmake-cross-build cmake-build))
-    (arguments (strip-keyword-arguments private-keywords arguments))))
+    (arguments
+     (substitute-keyword-arguments
+         (strip-keyword-arguments private-keywords arguments)
+       ((#:guile _ #t) guile)))))
 
 (define* (cmake-build name inputs
                       #:key guile source
diff --git a/guix/build-system/copy.scm b/guix/build-system/copy.scm
index d58931b33c..2507d77bcc 100644
--- a/guix/build-system/copy.scm
+++ b/guix/build-system/copy.scm
@@ -57,6 +57,7 @@ (define (default-glibc)
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (glibc (default-glibc))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME from the given arguments."
@@ -75,7 +76,10 @@ (define* (lower name
     (build-inputs native-inputs)
     (outputs outputs)
     (build copy-build)
-    (arguments (strip-keyword-arguments private-keywords arguments))))
+    (arguments
+     (substitute-keyword-arguments
+         (strip-keyword-arguments private-keywords arguments)
+       ((#:guile _ #t) guile)))))
 
 (define* (copy-build name inputs
                      #:key
diff --git a/guix/build-system/dub.scm b/guix/build-system/dub.scm
index b4011cdb83..1b9f21b052 100644
--- a/guix/build-system/dub.scm
+++ b/guix/build-system/dub.scm
@@ -106,6 +106,7 @@ (define* (lower name
                 (dub (default-dub))
                 (pkg-config (default-pkg-config))
                 (ld-gold-wrapper (default-ld-gold-wrapper))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -131,7 +132,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build dub-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define dub-build-system
   (build-system
diff --git a/guix/build-system/dune.scm b/guix/build-system/dune.scm
index c45f308349..bad523b9eb 100644
--- a/guix/build-system/dune.scm
+++ b/guix/build-system/dune.scm
@@ -57,6 +57,7 @@ (define* (lower name
                 (dune (default-dune))
                 (ocaml (ocaml:default-ocaml))
                 (findlib (ocaml:default-findlib))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -92,7 +93,9 @@ (define* (lower name
            (build dune-build)
            (arguments (append
                        `(#:dune-release-flags ,dune-release-flags)
-                       (strip-keyword-arguments private-keywords arguments)))))))
+                       (substitute-keyword-arguments
+                           (strip-keyword-arguments private-keywords arguments)
+                         ((#:guile _ #t) guile))))))))
 
 (define* (dune-build name inputs
                      #:key
diff --git a/guix/build-system/elm.scm b/guix/build-system/elm.scm
index f5321f811b..1c2b4a003e 100644
--- a/guix/build-system/elm.scm
+++ b/guix/build-system/elm.scm
@@ -119,6 +119,7 @@ (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (implicit-elm-package-inputs? #t)
                 (elm (default-elm))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -165,7 +166,10 @@ (define* (lower name
          ,@(standard-packages)))
       (outputs outputs)
       (build elm-build)
-      (arguments (strip-keyword-arguments private-keywords arguments))))))
+      (arguments
+       (substitute-keyword-arguments
+           (strip-keyword-arguments private-keywords arguments)
+         ((#:guile _ #t) guile)))))))
 
 (define* (elm-build name inputs
                     #:key
diff --git a/guix/build-system/emacs.scm b/guix/build-system/emacs.scm
index ebf97a5344..4ab2883769 100644
--- a/guix/build-system/emacs.scm
+++ b/guix/build-system/emacs.scm
@@ -57,6 +57,7 @@ (define (default-emacs)
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (emacs (default-emacs))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -78,7 +79,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build emacs-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (emacs-build name inputs
                       #:key source
diff --git a/guix/build-system/font.scm b/guix/build-system/font.scm
index c57c304f52..018b5c69dd 100644
--- a/guix/build-system/font.scm
+++ b/guix/build-system/font.scm
@@ -44,6 +44,7 @@ (define %font-build-system-modules
 
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -69,7 +70,10 @@ (define* (lower name
                                ("xz" xz))))))
     (outputs outputs)
     (build font-build)
-    (arguments (strip-keyword-arguments private-keywords arguments))))
+    (arguments
+     (substitute-keyword-arguments
+         (strip-keyword-arguments private-keywords arguments)
+       ((#:guile _ #t) guile)))))
 
 (define* (font-build name inputs
                      #:key source
diff --git a/guix/build-system/glib-or-gtk.scm b/guix/build-system/glib-or-gtk.scm
index 726d19efad..f8d5a0fa24 100644
--- a/guix/build-system/glib-or-gtk.scm
+++ b/guix/build-system/glib-or-gtk.scm
@@ -87,6 +87,7 @@ (define* (lower name
                 (implicit-inputs? #t)
                 (implicit-cross-inputs? #t)
                 (strip-binaries? #t)
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -120,7 +121,10 @@ (define* (lower name
                        '()))
     (outputs outputs)
     (build (if target glib-or-gtk-cross-build glib-or-gtk-build))
-    (arguments (strip-keyword-arguments private-keywords arguments))))
+    (arguments
+     (substitute-keyword-arguments
+         (strip-keyword-arguments private-keywords arguments)
+       ((#:guile _ #t) guile)))))
 
 (define* (glib-or-gtk-build name inputs
                             #:key guile source
diff --git a/guix/build-system/gnu.scm b/guix/build-system/gnu.scm
index c1aa187c42..7945efa1c3 100644
--- a/guix/build-system/gnu.scm
+++ b/guix/build-system/gnu.scm
@@ -278,6 +278,7 @@ (define* (lower name
                 #:key source inputs native-inputs outputs target
                 (implicit-inputs? #t) (implicit-cross-inputs? #t)
                 (strip-binaries? #t) system
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME from the given arguments."
@@ -319,7 +320,10 @@ (define* (lower name
                  outputs
                  (delete "debug" outputs)))
     (build (if target gnu-cross-build gnu-build))
-    (arguments (strip-keyword-arguments private-keywords arguments))))
+    (arguments
+     (substitute-keyword-arguments
+         (strip-keyword-arguments private-keywords arguments)
+       ((#:guile _ #t) guile)))))
 
 (define %license-file-regexp
   ;; Regexp matching license files.
diff --git a/guix/build-system/go.scm b/guix/build-system/go.scm
index 0a9761aac7..e27633b624 100644
--- a/guix/build-system/go.scm
+++ b/guix/build-system/go.scm
@@ -120,6 +120,7 @@ (define (make-go-std)
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (go (default-go))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -164,7 +165,10 @@ (define* (lower name
 
     (outputs outputs)
     (build (if target go-cross-build go-build))
-    (arguments (strip-keyword-arguments private-keywords arguments))))
+    (arguments
+     (substitute-keyword-arguments
+         (strip-keyword-arguments private-keywords arguments)
+       ((#:guile _ #t) guile)))))
 
 (define* (go-build name inputs
                    #:key
diff --git a/guix/build-system/guile.scm b/guix/build-system/guile.scm
index 1bd292e267..49d8cc77a7 100644
--- a/guix/build-system/guile.scm
+++ b/guix/build-system/guile.scm
@@ -68,7 +68,10 @@ (define* (lower name
                           '())))
     (outputs outputs)
     (build (if target guile-cross-build guile-build))
-    (arguments (strip-keyword-arguments private-keywords arguments))))
+    (arguments
+     (substitute-keyword-arguments
+         (strip-keyword-arguments private-keywords arguments)
+       ((#:guile _ #t) (default-guile))))))
 
 (define %compile-flags
   ;; Flags passed to 'guild compile' by default.  We choose a common
diff --git a/guix/build-system/haskell.scm b/guix/build-system/haskell.scm
index f8568e33db..b860550998 100644
--- a/guix/build-system/haskell.scm
+++ b/guix/build-system/haskell.scm
@@ -77,6 +77,7 @@ (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (haskell (default-haskell))
                 cabal-revision
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -122,7 +123,8 @@ (define* (lower name
                             (match (package-transitive-propagated-inputs pkg)
                               (((propagated-names . _) ...)
                                (cons name propagated-names))))))
-                       extra-directories))))))))
+                       extra-directories)))
+            ((#:guile _ #t) guile))))))
 
 (define* (haskell-build name inputs
                         #:key source
diff --git a/guix/build-system/julia.scm b/guix/build-system/julia.scm
index b5521e38e4..b4fc7f6576 100644
--- a/guix/build-system/julia.scm
+++ b/guix/build-system/julia.scm
@@ -53,6 +53,7 @@ (define (default-julia)
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (julia (default-julia))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -74,7 +75,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build julia-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (julia-build name inputs
                       #:key source
diff --git a/guix/build-system/linux-module.scm b/guix/build-system/linux-module.scm
index e46195b53c..d286ea9cee 100644
--- a/guix/build-system/linux-module.scm
+++ b/guix/build-system/linux-module.scm
@@ -112,6 +112,7 @@ (define* (lower name
                 #:key source inputs native-inputs outputs
                 system target
                 (linux (default-linux))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -148,7 +149,10 @@ (define* (lower name
                        '()))
     (outputs outputs)
     (build (if target linux-module-build-cross linux-module-build))
-    (arguments (strip-keyword-arguments private-keywords arguments))))
+    (arguments
+     (substitute-keyword-arguments
+         (strip-keyword-arguments private-keywords arguments)
+       ((#:guile _ #t) guile)))))
 
 (define* (linux-module-build name inputs
                              #:key
diff --git a/guix/build-system/maven.scm b/guix/build-system/maven.scm
index 4bbeaed6a4..b7734a1a07 100644
--- a/guix/build-system/maven.scm
+++ b/guix/build-system/maven.scm
@@ -116,6 +116,7 @@ (define* (lower name
                 (maven-plugins (default-maven-plugins))
                 (local-packages '())
                 (exclude %default-exclude)
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -139,7 +140,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build maven-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (maven-build name inputs
                       #:key
diff --git a/guix/build-system/meson.scm b/guix/build-system/meson.scm
index 7c617bffb0..13e2e87b58 100644
--- a/guix/build-system/meson.scm
+++ b/guix/build-system/meson.scm
@@ -125,6 +125,7 @@ (define* (lower name
                 (meson (default-meson))
                 (ninja (default-ninja))
                 (glib-or-gtk? #f)
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -156,7 +157,10 @@ (define* (lower name
                        '()))
     (outputs outputs)
     (build (if target meson-cross-build meson-build))
-    (arguments (strip-keyword-arguments private-keywords arguments))))
+    (arguments
+     (substitute-keyword-arguments
+         (strip-keyword-arguments private-keywords arguments)
+       ((#:guile _ #t) guile)))))
 
 (define* (meson-build name inputs
                       #:key
diff --git a/guix/build-system/minify.scm b/guix/build-system/minify.scm
index 787235deeb..384748908c 100644
--- a/guix/build-system/minify.scm
+++ b/guix/build-system/minify.scm
@@ -50,6 +50,7 @@ (define (default-uglify-js)
 (define* (lower name
                 #:key source inputs native-inputs outputs system
                 (uglify-js (default-uglify-js))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -68,7 +69,10 @@ (define* (lower name
                     ,@native-inputs))
     (outputs outputs)
     (build minify-build)
-    (arguments (strip-keyword-arguments private-keywords arguments))))
+    (arguments
+     (substitute-keyword-arguments
+         (strip-keyword-arguments private-keywords arguments)
+       ((#:guile _ #t) guile)))))
 
 (define* (minify-build name inputs
                        #:key
diff --git a/guix/build-system/node.scm b/guix/build-system/node.scm
index 3f73390809..0b1c1f1ddd 100644
--- a/guix/build-system/node.scm
+++ b/guix/build-system/node.scm
@@ -48,6 +48,7 @@ (define (default-node)
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (node (default-node))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -74,7 +75,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build node-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (node-build name inputs
                      #:key
diff --git a/guix/build-system/ocaml.scm b/guix/build-system/ocaml.scm
index 582d00b4cd..91dda0c391 100644
--- a/guix/build-system/ocaml.scm
+++ b/guix/build-system/ocaml.scm
@@ -229,6 +229,7 @@ (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (ocaml (default-ocaml))
                 (findlib (default-findlib))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -251,7 +252,10 @@ (define* (lower name
                          ,@(standard-packages)))
          (outputs outputs)
          (build ocaml-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (ocaml-build name inputs
                       #:key
diff --git a/guix/build-system/perl.scm b/guix/build-system/perl.scm
index 7c6deb34bf..99e952a531 100644
--- a/guix/build-system/perl.scm
+++ b/guix/build-system/perl.scm
@@ -58,6 +58,7 @@ (define* (lower name
                 #:key source inputs native-inputs outputs
                 system target
                 (perl (default-perl))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -99,7 +100,10 @@ (define* (lower name
     (build (if target
                perl-cross-build
                perl-build))
-    (arguments (strip-keyword-arguments private-keywords arguments))))
+    (arguments
+     (substitute-keyword-arguments
+         (strip-keyword-arguments private-keywords arguments)
+       ((#:guile _ #t) guile)))))
 
 (define* (perl-build name inputs
                      #:key source
diff --git a/guix/build-system/pyproject.scm b/guix/build-system/pyproject.scm
index 2a2c3af3f3..41b4d2c23f 100644
--- a/guix/build-system/pyproject.scm
+++ b/guix/build-system/pyproject.scm
@@ -60,6 +60,7 @@ (define sanity-check.py
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (python (default-python))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -82,7 +83,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs (append outputs '(wheel)))
          (build pyproject-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (pyproject-build name inputs
                           #:key source
diff --git a/guix/build-system/python.scm b/guix/build-system/python.scm
index cca009fb28..f8657662af 100644
--- a/guix/build-system/python.scm
+++ b/guix/build-system/python.scm
@@ -142,6 +142,7 @@ (define (strip-python2-variant p)
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (python (default-python))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -164,7 +165,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build python-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (python-build name inputs
                        #:key source
diff --git a/guix/build-system/qt.scm b/guix/build-system/qt.scm
index 978aed0fc1..97f870a698 100644
--- a/guix/build-system/qt.scm
+++ b/guix/build-system/qt.scm
@@ -80,6 +80,7 @@ (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (cmake (default-cmake))
                 (qtbase (default-qtbase))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -116,7 +117,11 @@ (define* (lower name
                        '()))
     (outputs outputs)
     (build (if target qt-cross-build qt-build))
-    (arguments (strip-keyword-arguments private-keywords arguments))))
+    (arguments
+     (substitute-keyword-arguments
+         (strip-keyword-arguments private-keywords arguments)
+       ((#:qtbase _ #t) qtbase)
+       ((#:guile _ #t) guile)))))

 (define* (qt-build name inputs
diff --git a/guix/build-system/r.scm b/guix/build-system/r.scm
index 657346bea3..ed70d7b758 100644
--- a/guix/build-system/r.scm
+++ b/guix/build-system/r.scm
@@ -79,6 +79,7 @@ (define (default-r)
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (r (default-r))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -100,7 +101,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build r-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (r-build name inputs
                   #:key
diff --git a/guix/build-system/rakudo.scm b/guix/build-system/rakudo.scm
index 3b30fdfd0e..654b0c362b 100644
--- a/guix/build-system/rakudo.scm
+++ b/guix/build-system/rakudo.scm
@@ -68,6 +68,7 @@ (define* (lower name
                 (zef (default-zef))
                 (with-prove6? #t)
                 (with-zef? #t)
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -95,7 +96,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build rakudo-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (rakudo-build name inputs
                        #:key
diff --git a/guix/build-system/rebar.scm b/guix/build-system/rebar.scm
index de1294ec3f..e89f82b768 100644
--- a/guix/build-system/rebar.scm
+++ b/guix/build-system/rebar.scm
@@ -74,6 +74,7 @@ (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (rebar (default-rebar3))
                 (erlang (default-erlang))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME from the given arguments."
@@ -95,7 +96,10 @@ (define* (lower name
                          ,@(standard-packages)))
          (outputs outputs)
          (build rebar-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (rebar-build name inputs
                        #:key
diff --git a/guix/build-system/renpy.scm b/guix/build-system/renpy.scm
index 3039e3c63b..75d546fedc 100644
--- a/guix/build-system/renpy.scm
+++ b/guix/build-system/renpy.scm
@@ -49,6 +49,7 @@ (define %renpy-build-system-modules
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (renpy (default-renpy))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -70,7 +71,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build renpy-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (renpy-build name inputs
                       #:key
diff --git a/guix/build-system/ruby.scm b/guix/build-system/ruby.scm
index a3793a9381..be8df2a93c 100644
--- a/guix/build-system/ruby.scm
+++ b/guix/build-system/ruby.scm
@@ -50,6 +50,7 @@ (define (default-ruby)
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (ruby (default-ruby))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -71,7 +72,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build ruby-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (ruby-build name inputs
                      #:key source
diff --git a/guix/build-system/scons.scm b/guix/build-system/scons.scm
index 046ddef740..95c75c817f 100644
--- a/guix/build-system/scons.scm
+++ b/guix/build-system/scons.scm
@@ -50,6 +50,7 @@ (define (default-scons)
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (scons (default-scons))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -71,7 +72,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build scons-build)
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (scons-build name inputs
                       #:key
diff --git a/guix/build-system/texlive.scm b/guix/build-system/texlive.scm
index 88372faa58..941fa37b5f 100644
--- a/guix/build-system/texlive.scm
+++ b/guix/build-system/texlive.scm
@@ -98,6 +98,7 @@ (define* (lower name
                 system target
                 (texlive-latex-bin? #true)
                 (texlive-bin (default-texlive-bin))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -122,7 +123,10 @@ (define* (lower name
                     ,@native-inputs))
     (outputs outputs)
     (build texlive-build)
-    (arguments (strip-keyword-arguments private-keywords arguments))))
+    (arguments
+     (substitute-keyword-arguments
+         (strip-keyword-arguments private-keywords arguments)
+       ((#:guile _ #t) guile)))))
 
 (define* (texlive-build name inputs
                         #:key
diff --git a/guix/build-system/tree-sitter.scm b/guix/build-system/tree-sitter.scm
index 21c4eb35b2..1ea0c58817 100644
--- a/guix/build-system/tree-sitter.scm
+++ b/guix/build-system/tree-sitter.scm
@@ -38,6 +38,7 @@ (define %tree-sitter-build-system-modules
 
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME from the given arguments."
@@ -87,7 +88,10 @@ (define* (lower name
                (("out") (cons "js" outputs))
                (_ outputs)))
     (build (if target tree-sitter-cross-build tree-sitter-build))
-    (arguments (strip-keyword-arguments private-keywords arguments))))
+    (arguments
+     (substitute-keyword-arguments
+         (strip-keyword-arguments private-keywords arguments)
+       ((#:guile _ #t) guile)))))
 
 (define* (tree-sitter-build name inputs
                             #:key
diff --git a/guix/build-system/trivial.scm b/guix/build-system/trivial.scm
index e08884baf1..37798cbf7a 100644
--- a/guix/build-system/trivial.scm
+++ b/guix/build-system/trivial.scm
@@ -26,7 +26,8 @@ (define-module (guix build-system trivial)
 
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
-                guile builder (modules '()) allowed-references)
+                (guile (default-guile)) builder (modules '())
+                allowed-references)
   "Return a bag for NAME."
   (bag
     (name name)
diff --git a/guix/build-system/waf.scm b/guix/build-system/waf.scm
index 91b3d0d100..abb87156c7 100644
--- a/guix/build-system/waf.scm
+++ b/guix/build-system/waf.scm
@@ -47,6 +47,7 @@ (define %waf-build-system-modules
 (define* (lower name
                 #:key source inputs native-inputs outputs system target
                 (python (default-python))
+                (guile (default-guile))
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
@@ -68,7 +69,10 @@ (define* (lower name
                          ,@native-inputs))
          (outputs outputs)
          (build waf-build) ; only change compared to 'lower' in python.scm
-         (arguments (strip-keyword-arguments private-keywords arguments)))))
+         (arguments
+          (substitute-keyword-arguments
+              (strip-keyword-arguments private-keywords arguments)
+            ((#:guile _ #t) guile))))))
 
 (define* (waf-build name inputs
                     #:key source
-- 
2.40.1

From 9ec825fd06f32757f45f31880e7b238bba769884 Mon Sep 17 00:00:00 2001
Message-Id: <[email-masked]>
In-Reply-To: <[email-masked]>
References: <[email-masked]>
From: Ulf Herrman <[email-masked]>
Date: Fri, 15 Sep 2023 08:45:39 -0500
Subject: [PATCH 4/5] build-system: {cargo,dune,ocaml,scons}: use drv
 guile-for-build.

These all pass a guile *package* to gexp->derivation in their bag->derivation
builders, but it wants a derivation.

* guix/build-system/cargo.scm (cargo-build): use package->derivation to get
  guile for build.
* guix/build-system/dune.scm (dune-build): same.
* guix/build-system/ocaml.scm (ocaml-build): same.
* guix/build-system/scons.scm (scons-build): same.
---
 guix/build-system/cargo.scm | 12 +++++++-----
 guix/build-system/dune.scm  | 14 ++++++++------
 guix/build-system/ocaml.scm | 13 ++++++++-----
 guix/build-system/scons.scm | 13 ++++++++-----
 4 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/guix/build-system/cargo.scm b/guix/build-system/cargo.scm
index 84efea019e..30d6d2ead9 100644
--- a/guix/build-system/cargo.scm
+++ b/guix/build-system/cargo.scm
@@ -120,11 +120,13 @@ (define* (cargo-build name inputs
                                           (map search-path-specification->sexp
                                                search-paths))))))
 
-  (gexp->derivation name builder
-                    #:system system
-                    #:target #f
-                    #:graft? #f
-                    #:guile-for-build guile))
+  (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
+                                                  system #:graft? #f)))
+    (gexp->derivation name builder
+                      #:system system
+                      #:target #f
+                      #:graft? #f
+                      #:guile-for-build guile)))
 
 (define (package-cargo-inputs p)
   (apply
diff --git a/guix/build-system/dune.scm b/guix/build-system/dune.scm
index bad523b9eb..1bf93361aa 100644
--- a/guix/build-system/dune.scm
+++ b/guix/build-system/dune.scm
@@ -21,6 +21,7 @@
 
 (define-module (guix build-system dune)
   #:use-module (guix store)
+  #:use-module (guix monads)
   #:use-module (guix utils)
   #:use-module (guix gexp)
   #:use-module (guix search-paths)
@@ -154,12 +155,13 @@ (define* (dune-build name inputs
                       #:strip-binaries? #$strip-binaries?
                       #:strip-flags #$strip-flags
                       #:strip-directories #$strip-directories))))
-
-  (gexp->derivation name builder
-                    #:system system
-                    #:target #f
-                    #:graft? #f
-                    #:guile-for-build guile))
+  (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
+                                                  system #:graft? #f)))
+    (gexp->derivation name builder
+                      #:system system
+                      #:target #f
+                      #:graft? #f
+                      #:guile-for-build guile)))
 
 (define dune-build-system
   (build-system
diff --git a/guix/build-system/ocaml.scm b/guix/build-system/ocaml.scm
index 91dda0c391..20327295f9 100644
--- a/guix/build-system/ocaml.scm
+++ b/guix/build-system/ocaml.scm
@@ -21,6 +21,7 @@ (define-module (guix build-system ocaml)
   #:use-module (guix store)
   #:use-module (guix utils)
   #:use-module (guix gexp)
+  #:use-module (guix monads)
   #:use-module (guix search-paths)
   #:use-module (guix build-system)
   #:use-module (guix build-system gnu)
@@ -309,11 +310,13 @@ (define* (ocaml-build name inputs
                        #:strip-flags #$strip-flags
                        #:strip-directories #$strip-directories))))
 
-  (gexp->derivation name builder
-                    #:system system
-                    #:target #f
-                    #:graft? #f
-                    #:guile-for-build guile))
+  (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
+                                                  system #:graft? #f)))
+    (gexp->derivation name builder
+                      #:system system
+                      #:target #f
+                      #:graft? #f
+                      #:guile-for-build guile)))
 
 (define ocaml-build-system
   (build-system
diff --git a/guix/build-system/scons.scm b/guix/build-system/scons.scm
index 95c75c817f..e504db90c2 100644
--- a/guix/build-system/scons.scm
+++ b/guix/build-system/scons.scm
@@ -22,6 +22,7 @@ (define-module (guix build-system scons)
   #:use-module (guix packages)
   #:use-module (guix monads)
   #:use-module (guix gexp)
+  #:use-module (guix store)
   #:use-module (guix search-paths)
   #:use-module (guix build-system)
   #:use-module (guix build-system gnu)
@@ -121,11 +122,13 @@ (define* (scons-build name inputs
                                  (map search-path-specification->sexp
                                       search-paths)))))))
 
-  (gexp->derivation name builder
-                    #:system system
-                    #:target #f
-                    #:graft? #f
-                    #:guile-for-build guile))
+  (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
+                                                  system #:graft? #f)))
+    (gexp->derivation name builder
+                      #:system system
+                      #:target #f
+                      #:graft? #f
+                      #:guile-for-build guile)))
 
 (define scons-build-system
   (build-system
-- 
2.40.1

From 32a455ab2852c6ff015a2126953075c67a3371b9 Mon Sep 17 00:00:00 2001
Message-Id: <[email-masked]>
In-Reply-To: <[email-masked]>
References: <[email-masked]>
From: Ulf Herrman <[email-masked]>
Date: Fri, 15 Sep 2023 08:53:10 -0500
Subject: [PATCH 5/5] build-system: dub: add #:ld-gold-wrapper to
 private-keywords.

This isn't an accepted keyword to dub-build, so it will currently cause an
error if it is specified, which rather defeats the purpose of having it as an
argument.  Putting it in private-keywords will cause it to be stripped from
the final bag arguments.

* guix/build-system/dub.scm (lower): add #:ld-gold-wrapper to
  private-keywords.
---
 guix/build-system/dub.scm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/guix/build-system/dub.scm b/guix/build-system/dub.scm
index 1b9f21b052..b325357589 100644
--- a/guix/build-system/dub.scm
+++ b/guix/build-system/dub.scm
@@ -112,7 +112,8 @@ (define* (lower name
   "Return a bag for NAME."
 
   (define private-keywords
-    '(#:target #:ldc #:dub #:pkg-config #:inputs #:native-inputs #:outputs))
+    '(#:target #:ldc #:dub #:pkg-config #:ld-gold-wrapper
+      #:inputs #:native-inputs #:outputs))
 
   (and (not target) ;; TODO: support cross-compilation
        (bag
-- 
2.40.1