Subject: [PATCH v3 core-updates] various cross-compilation fixes in guix/build/utils.scm

From: Maxime Devos <[email-masked]>
Date: Tue, 01 Jun 2021 21:53:17 +0200

Hi guix,

This is version three of the patch series,
which (no pun intended) incorporates feedback
from Ludovic Courtès.

This version adds a 'search-input-file' procedure
to (guix build utils). It is used like:

  (wrap-script something #:guile
    (search-input-file inputs "bin/guile")
    [...])

Explicitely setting #:guile instead of defaulting
to (which "guile") is required for cross-compilation,
to make sure the guile eventually used is compiled for
the correct architecture.

This patch series also extends 'wrap-program' with
a #:sh keyword argument, which has the same purpose
as #:guile for 'wrap-script'.

Some differences to v2:

  * The #:sh and #:guile arguments are optional.
    The default value should be good when compiling natively,
    but not when cross-compiling.

    Eventually, we may look into making them required,
    but let's pun for later.

  * I left 'wrap-qt-program' alone for now.

  * I left documenting 'wrap-program' and 'wrap-script' for later.

  * I didn't adjust all uses of wrap-program to set #:sh,
    only a few.

For testing wrap-program:
Write to "a.sh":

  #!/stuff/etcetera
  echo "hello world!"

From ./pre-inst-env guix repl, do:

  (use-modules (guix build utils))
  (wrap-program "a.sh" #:sh "/bin/sh" '("PATH" = ("stuff")))

Now look at "a.sh":

  #!/bin/sh
  export PATH="stuff"
  exec -a "$0" "[current working directory]/.a.sh-real" "$@"

There are some tests in tests/build-utils.scm for 'search-input-file'.

I also ran "make && ./pre-inst-env guix build hello wireguard-tools".
(Not sure about which packages I tested actually.) This successfully
built "hello" (and all its dependencies, this can take a lot of time!).

Building wireguard-tools failed at first. It turned out I made a mistake
in 'wrap-program': the following ...

  (define vars/filtered
    (match vars
      ((#:sh . vars) vars)
      (vars vars)))

... should have been ...

 (define vars/filtered
    (match vars
      ((#:sh _ . vars) vars)
      (vars vars)))

That has been corrected. I tested the corrected "wrap-program" in a REPL
as above, but haven't tried building wireguard-tools again (that would
entail doing the whole bootstrapping process again).

This patch series is on top of commit 9ba35475ede5eb61bfeead096bc6b73f123ac891
on core-updates.

Greetings,
Maxime.
From 02d2b52458fae1c391e79f89a89696f3b07fdb2b Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 18:22:31 +0200
Subject: [PATCH 01/18] =?UTF-8?q?build:=20Allow=20overriding=20the=20shell?=
 =?UTF-8?q?=20interpreter=20in=20=E2=80=98wrap-program=E2=80=99.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Previously, when creating new wrappers, 'wrap-program' would search
for an interpreter to use in PATH. However, this is incorrect when
cross-compiling. Allow overriding the shell interpreter to use,
via an optional keyword argument #:sh.

In time, when all users of 'wrap-program' have been corrected,
this keyword argument can be made mandatory.

* guix/build/utils.scm (wrap-program): Introduce a #:sh keyword
  argument, defaulting to (which "sh"). Use this keyword argument.

Partially-Fixes: <https://issues.guix.gnu.org/47869>
---
 guix/build/utils.scm | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index dbfc0a9142..c6731b37ae 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -7,6 +7,7 @@
 ;;; Copyright © 2018, 2019 Ricardo Wurmus <[email-masked]>
 ;;; Copyright © 2020 Efraim Flashner <[email-masked]>
 ;;; Copyright © 2020, 2021 Maxim Cournoyer <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1234,7 +1235,7 @@ known as `nuke-refs' in Nixpkgs."
          (and (string-prefix? "." base)
               (string-suffix? "-real" base)))))
 
-(define* (wrap-program prog #:rest vars)
+(define* (wrap-program prog #:key (sh (which "bash")) #:rest vars)
   "Make a wrapper for PROG.  VARS should look like this:
 
   '(VARIABLE DELIMITER POSITION LIST-OF-DIRECTORIES)
@@ -1261,7 +1262,12 @@ programs that expect particular shared libraries to be in $LD_LIBRARY_PATH, or
 modules in $GUILE_LOAD_PATH, etc.
 
 If PROG has previously been wrapped by 'wrap-program', the wrapper is extended
-with definitions for VARS."
+with definitions for VARS. If it is not, SH will be used as interpreter."
+  (define vars/filtered
+    (match vars
+      ((#:sh _ . vars) vars)
+      (vars vars)))
+
   (define wrapped-file
     (string-append (dirname prog) "/." (basename prog) "-real"))
 
@@ -1315,7 +1321,7 @@ with definitions for VARS."
         (for-each (lambda (var)
                     (display (export-variable var) port)
                     (newline port))
-                  vars)
+                  vars/filtered)
         (display last port)
         (close-port port))
 
@@ -1327,8 +1333,8 @@ with definitions for VARS."
           (lambda (port)
             (format port
                     "#!~a~%~a~%exec -a \"$0\" \"~a\" \"$@\"~%"
-                    (which "bash")
-                    (string-join (map export-variable vars) "\n")
+                    sh
+                    (string-join (map export-variable vars/filtered) "\n")
                     (canonicalize-path wrapped-file))))
 
         (chmod prog-tmp #o755)
-- 
2.31.1

From f598c0168bfcb75f718cc8edf990b7a560334405 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 18:36:09 +0200
Subject: [PATCH 02/18] =?UTF-8?q?build:=20Define=20=E2=80=98search-input-f?=
 =?UTF-8?q?ile=E2=80=99=20procedure.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The procedure ‘which’ from (guix build utils)
is used for two different purposes:

  1. for finding the absolute file name of a binary
     that needs to run during the build process

  2. for finding the absolute file name of a binary,
     for the target system (as in --target=TARGET),
     e.g. for substituting sh->/gnu/store/.../bin/sh,
     python->/gnu/store/.../bin/python.

When compiling natively (target=#f in Guix parlance),
this is perfectly fine.

However, when cross-compiling, there is a problem.
"which" looks in $PATH for binaries.  That's good for purpose (1),
but incorrect for (2), as the $PATH contains binaries from native-inputs
instead of inputs.

This commit defines a ‘search-input-file’ procedure. It functions
like 'which', but instead of searching in $PATH, it searches in
the 'inputs' of the build phase, which must be passed to
‘search-input-file’ as an argument. Also, the file name must
include "bin/" or "sbin/" as appropriate.

* guix/build/utils.scm (search-input-file): New procedure.
* tests/build-utils.scm
  ("search-input-file: exception if not found")
  ("search-input-file: can find if existent"): Test it.
* doc/guix.texi (File Search): Document it.

Partially-Fixes: <https://issues.guix.gnu.org/47869>
---
 doc/guix.texi         | 13 +++++++++++++
 guix/build/utils.scm  |  9 +++++++++
 tests/build-utils.scm | 11 +++++++++++
 3 files changed, 33 insertions(+)

diff --git a/doc/guix.texi b/doc/guix.texi
index 535e7614fd..f9d2322ea7 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -8661,6 +8661,19 @@ Return the complete file name for @var{program} as found in
 @code{$PATH}, or @code{#f} if @var{program} could not be found.
 @end deffn
 
+@deffn {Scheme Procedure} search-input-file @var{inputs} @var{name}
+Return the complete file name for @var{name} as found in @var{inputs}.
+If @var{name} could not be found, an exception is raised instead.
+Here, @var{inputs} is an association list like @var{inputs} and
+@var{native-inputs} as available to build phases.
+
+This procedure can be used for telling @code{wrap-script} and
+@code{wrap-program} (currently undocumented) where the Guile
+binary or shell binary are located. In fact, that's the
+purpose for which @code{search-input-file} has been created
+in the first place.
+@end deffn
+
 @subsection Build Phases
 
 @cindex build phases
diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index c6731b37ae..2ae8478ef7 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -80,6 +80,7 @@
             search-path-as-string->list
             list->search-path-as-string
             which
+            search-input-file
 
             every*
             alist-cons-before
@@ -614,6 +615,14 @@ PROGRAM could not be found."
   (search-path (search-path-as-string->list (getenv "PATH"))
                program))
 
+(define (search-input-file inputs file)
+  "Find a file named FILE among the INPUTS and return its absolute file name.
+
+FILE must be a string like \"bin/sh\". If FILE is not found, an exception is
+raised."
+  (or (search-path (map cdr inputs) file)
+      (error "could not find ~a among the inputs" file)))
+
 
 ;;;
 ;;; Phases.
diff --git a/tests/build-utils.scm b/tests/build-utils.scm
index 31be7ff80f..33685c6468 100644
--- a/tests/build-utils.scm
+++ b/tests/build-utils.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2012, 2015, 2016, 2019, 2020 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2019 Ricardo Wurmus <[email-masked]>
 ;;; Copyright © 2021 Maxim Cournoyer <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -263,4 +264,14 @@ print('hello world')"))
          (lambda _
            (get-string-all (current-input-port))))))))
 
+(test-assert "search-input-file: exception if not found"
+  (not (false-if-exception
+         (search-input-file '() "does-not-exist"))))
+
+(test-equal "search-input-file: can find if existent"
+  (which "guile")
+  (search-input-file
+    `(("guile/bin" . ,(dirname (which "guile"))))
+    "guile"))
+
 (test-end)
-- 
2.31.1

From 98856ca64218bd98c0d066a25ac93038a98c7ff5 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Tue, 1 Jun 2021 21:47:01 +0200
Subject: [PATCH 03/18] glib-or-gtk-build-system: Look up the interpreter in
 'inputs'.

* guix/build/glib-or-gtk-build-system.scm (wrap-all-programs): Pass
  the shell interpreter from 'inputs' to 'wrap-program' using
  'search-input-file'.

Partially-Fixes: <https://issues.guix.gnu.org/47869>
---
 guix/build/glib-or-gtk-build-system.scm | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/guix/build/glib-or-gtk-build-system.scm b/guix/build/glib-or-gtk-build-system.scm
index ccb3138fe2..8d3c3684d3 100644
--- a/guix/build/glib-or-gtk-build-system.scm
+++ b/guix/build/glib-or-gtk-build-system.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2014 Federico Beffa <[email-masked]>
 ;;; Copyright © 2014, 2015 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2018 Mark H Weaver <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -136,6 +137,11 @@ Wrapping is not applied to outputs whose name is listed in
 GLIB-OR-GTK-WRAP-EXCLUDED-OUTPUTS.  This is useful when an output is known not
 to contain any GLib or GTK+ binaries, and where wrapping would gratuitously
 add a dependency of that output on GLib and GTK+."
+  ;; Do not require bash to be present in the package inputs
+  ;; even when there is nothing to wrap.
+  ;; Also, calculate (sh) only once to prevent some I/O.
+  (define %sh (delay (search-input-file inputs "bin/bash")))
+  (define (sh) (force %sh))
   (define handle-output
     (match-lambda
      ((output . directory)
@@ -165,36 +171,36 @@ add a dependency of that output on GLib and GTK+."
                     #f)))
           (cond
            ((and data-env-var gtk-mod-env-var gio-mod-env-var)
-            (for-each (cut wrap-program <>
+            (for-each (cut wrap-program <> #:sh (sh)
                            data-env-var
                            gtk-mod-env-var
                            gio-mod-env-var)
                       bin-list))
            ((and data-env-var gtk-mod-env-var (not gio-mod-env-var))
-            (for-each (cut wrap-program <>
+            (for-each (cut wrap-program <> #:sh (sh)
                            data-env-var
                            gtk-mod-env-var)
                       bin-list))
            ((and data-env-var (not gtk-mod-env-var) gio-mod-env-var)
-            (for-each (cut wrap-program <>
+            (for-each (cut wrap-program <> #:sh (sh)
                            data-env-var
                            gio-mod-env-var)
                       bin-list))
            ((and (not data-env-var) gtk-mod-env-var gio-mod-env-var)
-            (for-each (cut wrap-program <>
+            (for-each (cut wrap-program <> #:sh (sh)
                            gio-mod-env-var
                            gtk-mod-env-var)
                       bin-list))
            ((and data-env-var (not gtk-mod-env-var) (not gio-mod-env-var))
-            (for-each (cut wrap-program <>
+            (for-each (cut wrap-program <> #:sh (sh)
                            data-env-var)
                       bin-list))
            ((and (not data-env-var) gtk-mod-env-var (not gio-mod-env-var))
-            (for-each (cut wrap-program <>
+            (for-each (cut wrap-program <> #:sh (sh)
                            gtk-mod-env-var)
                       bin-list))
            ((and (not data-env-var) (not gtk-mod-env-var) gio-mod-env-var)
-            (for-each (cut wrap-program <>
+            (for-each (cut wrap-program <> #:sh (sh)
                            gio-mod-env-var)
                       bin-list))))))))
 
-- 
2.31.1

From bc0085b79dd42e586cc5fcffa6f4972db9f42563 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Tue, 1 Jun 2021 21:48:44 +0200
Subject: [PATCH 04/18] python-build-system: Look up the interpreter in
 'inputs'.

* guix/build/python-build-system.scm (wrap): Pass the shell
  interpreter from 'inputs' to 'wrap-program' using 'search-input-file'.

Partially-Fixes: <https://issues.guix.gnu.org/47869>
---
 guix/build/python-build-system.scm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/guix/build/python-build-system.scm b/guix/build/python-build-system.scm
index 5b1339d14c..08871f60cd 100644
--- a/guix/build/python-build-system.scm
+++ b/guix/build/python-build-system.scm
@@ -10,6 +10,7 @@
 ;;; Copyright © 2020 Jakub Kądziołka <[email-masked]>
 ;;; Copyright © 2020 Efraim Flashner <[email-masked]>
 ;;; Copyright © 2021 Lars-Dominik Braun <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -234,12 +235,18 @@ running checks after installing the package."
                          (string-append dir "/sbin"))))
                 outputs))
 
+  ;; Do not require "bash" to be present in the package inputs
+  ;; even when there is nothing to wrap.
+  ;; Also, calculate (sh) only once to prevent some I/O.
+  (define %sh (delay (search-input-file inputs "bin/bash")))
+  (define (sh) (force %sh))
+
   (let* ((var `("GUIX_PYTHONPATH" prefix
                 ,(search-path-as-string->list
                   (or (getenv "GUIX_PYTHONPATH") "")))))
     (for-each (lambda (dir)
                 (let ((files (list-of-files dir)))
-                  (for-each (cut wrap-program <> var)
+                  (for-each (cut wrap-program <> #:sh (sh) var)
                             files)))
               bindirs)))
 
-- 
2.31.1

From 0370ad982e90c3e4def9cd5245cbd6769fda2830 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 19:20:12 +0200
Subject: [PATCH 05/18] qt-build-system: Look up the interpreter in 'inputs'.

* guix/build/qt-build-system.scm (wrap-all-programs): Pass
  the shell interpreter from 'inputs' to 'wrap-program' using
  'search-input-file'.

Partially-Fixes: <https://issues.guix.gnu.org/47869>
---
 guix/build/qt-build-system.scm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/guix/build/qt-build-system.scm b/guix/build/qt-build-system.scm
index 762fd8a2ee..ec7ceb38bd 100644
--- a/guix/build/qt-build-system.scm
+++ b/guix/build/qt-build-system.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2014, 2015, 2021 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2018 Mark H Weaver <[email-masked]>
 ;;; Copyright © 2019, 2020 Hartmut Goebel <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -126,6 +127,12 @@ add a dependency of that output on Qt."
            (((_ . dir) ...)
             dir)))
 
+  ;; Do not require bash to be present in the package inputs
+  ;; even when there is nothing to wrap.
+  ;; Also, calculate (sh) only once to prevent some I/O.
+  (define %sh (delay (search-input-file inputs "bin/bash")))
+  (define (sh) (force %sh))
+
   (define handle-output
     (match-lambda
      ((output . directory)
@@ -135,7 +142,7 @@ add a dependency of that output on Qt."
                              (append (list directory)
                                      input-directories))))
           (when (not (null? vars-to-wrap))
-            (for-each (cut apply wrap-program <> vars-to-wrap)
+            (for-each (cut apply wrap-program <> #:sh (sh) vars-to-wrap)
                       bin-list)))))))
 
   (for-each handle-output outputs)
-- 
2.31.1

From 92278afdc58430e8e9f6887d481964e1d73e551c Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 19:21:16 +0200
Subject: [PATCH 06/18] rakudo-build-system: Look up the interpreter in
 'inputs'.

* guix/build/rakudo-build-system.scm (wrap): Pass
  the shell interpreter from 'inputs' to 'wrap-program' using
  'search-input-file'.

Partially-Fixes: <https://issues.guix.gnu.org/47869>
---
 guix/build/rakudo-build-system.scm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/guix/build/rakudo-build-system.scm b/guix/build/rakudo-build-system.scm
index b2c090f946..5cf1cc55bc 100644
--- a/guix/build/rakudo-build-system.scm
+++ b/guix/build/rakudo-build-system.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2019 Efraim Flashner <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -108,6 +109,12 @@
                         (string-append dir "/sbin"))))
                 outputs))
 
+  ;; Do not require bash to be present in the package inputs
+  ;; even when there is nothing to wrap.
+  ;; Also, calculate (sh) only once to prevent some I/O.
+  (define %sh (delay (search-input-file inputs "bin/bash")))
+  (define (sh) (force %sh))
+
   (let* ((out  (assoc-ref outputs "out"))
          (var `("PERL6LIB" "," prefix
                 ,(cons (string-append out "/share/perl6/lib,"
@@ -117,7 +124,7 @@
                         (or (getenv "PERL6LIB") "") #\,)))))
     (for-each (lambda (dir)
                 (let ((files (list-of-files dir)))
-                  (for-each (cut wrap-program <> var)
+                  (for-each (cut wrap-program <> #:sh (sh) var)
                             files)))
               bindirs)
     #t))
-- 
2.31.1

From e8b21fba6cd6a45cbaaab6547f8906b84618a38e Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 19:41:22 +0200
Subject: [PATCH 07/18] gnu: carla: Set #:guile argument of 'wrap-script'.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/audio.scm
  (carla)[arguments]<#:phases>{wrap-executables}:
  Set #:guile argument of ‘wrap-script’.
---
 gnu/packages/audio.scm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/audio.scm b/gnu/packages/audio.scm
index f677d46a7f..930c111d5e 100644
--- a/gnu/packages/audio.scm
+++ b/gnu/packages/audio.scm
@@ -4711,9 +4711,10 @@ as is the case with audio plugins.")
                (chmod (string-append out "/share/carla/carla") #o555)
                #t)))
          (add-after 'install 'wrap-executables
-           (lambda* (#:key outputs #:allow-other-keys)
+           (lambda* (#:key inputs outputs #:allow-other-keys)
              (let ((out (assoc-ref outputs "out")))
                (wrap-script (string-append out "/bin/carla")
+                            #:guile (search-input-file inputs "bin/guile")
                             `("GUIX_PYTHONPATH" ":" prefix (,(getenv "GUIX_PYTHONPATH"))))
                #t))))))
     (inputs
-- 
2.31.1

From 7a337fa6576ed1b797cbae5c6d26e0dd90a744fa Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 19:42:58 +0200
Subject: [PATCH 08/18] gnu: bats: Set #:guile argument of 'wrap-script'.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/bash.scm
  (bats)[arguments]<#:builder>: Set #:guile argument
  of ‘wrap-script’.
---
 gnu/packages/bash.scm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index 8dfbd7834e..7e98367bbb 100644
--- a/gnu/packages/bash.scm
+++ b/gnu/packages/bash.scm
@@ -402,6 +402,7 @@ capturing.")
          ;; Install phase
          (invoke "./install.sh" %output)
          (wrap-script (string-append %output "/bin/bats")
+                      #:guile (search-input-file %build-inputs "bin/guile")
                       (list "PATH" 'prefix (string-split (getenv "PATH")
                                                          #\:))))))
     (build-system trivial-build-system)
-- 
2.31.1

From 3cca28ba7694ee32f252c089d88d7e2834d1c415 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 19:46:22 +0200
Subject: [PATCH 09/18] gnu: proteinortho: Set #:guile argument of
 'wrap-script'.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/bioinformatics.scm
  (proteinortho)[arguments]<#:phases>{wrap-programs}:
  Set #:guile argument of ‘wrap-script’.
---
 gnu/packages/bioinformatics.scm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/bioinformatics.scm b/gnu/packages/bioinformatics.scm
index 85f785955e..7d8496e692 100644
--- a/gnu/packages/bioinformatics.scm
+++ b/gnu/packages/bioinformatics.scm
@@ -5447,9 +5447,11 @@ predicts the locations of structural units in the sequences.")
          (add-after 'install 'wrap-programs
            (lambda* (#:key inputs outputs #:allow-other-keys)
              (let ((path (getenv "PATH"))
-                   (out (assoc-ref outputs "out")))
+                   (out (assoc-ref outputs "out"))
+                   (guile (search-input-file inputs "bin/guile")))
                (for-each (lambda (script)
-                           (wrap-script script `("PATH" ":" prefix (,path))))
+                           (wrap-script script #:guile guile
+                                        `("PATH" ":" prefix (,path))))
                          (cons (string-append out "/bin/proteinortho")
                                (find-files out "\\.(pl|py)$"))))
              #t)))))
-- 
2.31.1

From a60dd8b0cd55e27f1e5d72f75cb5cbfb59acfb48 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 19:48:19 +0200
Subject: [PATCH 10/18] gnu: prinseq: Set #:guile argument of 'wrap-script'.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/bioinformatics.scm
  (prinseq)[arguments]<#:phases>{install}:
  Set #:guile argument of ‘wrap-script’.
---
 gnu/packages/bioinformatics.scm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/bioinformatics.scm b/gnu/packages/bioinformatics.scm
index 7d8496e692..37483984ec 100644
--- a/gnu/packages/bioinformatics.scm
+++ b/gnu/packages/bioinformatics.scm
@@ -7557,7 +7557,8 @@ experience substantial biological insertions and deletions.")
            (lambda* (#:key outputs #:allow-other-keys)
              (let* ((out (assoc-ref outputs "out"))
                     (bin (string-append out "/bin"))
-                    (scripts (find-files "." "prinseq.*.pl")))
+                    (scripts (find-files "." "prinseq.*.pl"))
+                    (guile (search-input-file "bin/guile")))
                (substitute* scripts
                  (("\"perl -pe")
                   (string-append "\"" (which "perl") " -pe")))
@@ -7565,6 +7566,7 @@ experience substantial biological insertions and deletions.")
                            (chmod file #o555)
                            (install-file file bin)
                            (wrap-script (string-append bin "/" (basename file))
+                                        #:guile guile
                                         `("PERL5LIB" ":" prefix
                                           (,(getenv "PERL5LIB")))))
                          scripts)))))))
-- 
2.31.1

From 0ef6b12b7b5645b9e17bfbe9e65ed341146eec80 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 19:50:07 +0200
Subject: [PATCH 11/18] gnu: gess: Set #:guile argument of 'wrap-script'.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/bioinformatics.scm
  (gess)[arguments]<#:phases>{install}
  Set #:guile argument of ‘wrap-script’.
---
 gnu/packages/bioinformatics.scm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/bioinformatics.scm b/gnu/packages/bioinformatics.scm
index 37483984ec..965e26b812 100644
--- a/gnu/packages/bioinformatics.scm
+++ b/gnu/packages/bioinformatics.scm
@@ -7554,7 +7554,7 @@ experience substantial biological insertions and deletions.")
          (delete 'configure)
          (delete 'build)
          (replace 'install
-           (lambda* (#:key outputs #:allow-other-keys)
+           (lambda* (#:key inputs outputs #:allow-other-keys)
              (let* ((out (assoc-ref outputs "out"))
                     (bin (string-append out "/bin"))
                     (scripts (find-files "." "prinseq.*.pl"))
@@ -10239,6 +10239,7 @@ matplotlib.use('Agg')
 " line)))
                ;; Make sure GESS has all modules in its path
                (wrap-script (string-append target "GESS.py")
+                 #:guile (search-input-file inputs "bin/guile")
                  `("GUIX_PYTHONPATH" ":" = (,target ,(getenv "GUIX_PYTHONPATH"))))
                (mkdir-p bin)
                (symlink (string-append target "GESS.py")
-- 
2.31.1

From bb4599d61bebe0a9db8863542349d1558163b468 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 19:54:49 +0200
Subject: [PATCH 12/18] gnu: nanopolish: Set #:guile argument of 'wrap-script'.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/bioinformatics.scm
  (nanopolish)[arguments]<#:phases>{wrap-programs}:
  Set #:guile argument of ‘wrap-script’.
---
 gnu/packages/bioinformatics.scm | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gnu/packages/bioinformatics.scm b/gnu/packages/bioinformatics.scm
index 965e26b812..fc2fc867ac 100644
--- a/gnu/packages/bioinformatics.scm
+++ b/gnu/packages/bioinformatics.scm
@@ -13583,16 +13583,18 @@ choosing which reads pass the filter.")
                            (find-files "scripts" ".*"))
                  #t)))
            (add-after 'install 'wrap-programs
-             (lambda* (#:key outputs #:allow-other-keys)
+             (lambda* (#:key inputs outputs #:allow-other-keys)
                (let ((pythonpath (getenv "GUIX_PYTHONPATH"))
                      (perl5lib (getenv "PERL5LIB"))
                      (scripts (string-append (assoc-ref outputs "out")
-                                             "/share/nanopolish/scripts")))
+                                             "/share/nanopolish/scripts"))
+                     (guile (search-input-file inputs "bin/guile")))
                  (for-each (lambda (file)
                              (wrap-program file `("GUIX_PYTHONPATH" ":" prefix (,pythonpath))))
                            (find-files scripts "\\.py"))
                  (for-each (lambda (file)
-                             (wrap-script file `("PERL5LIB" ":" prefix (,perl5lib))))
+                             (wrap-script file #:guile guile
+                                          `("PERL5LIB" ":" prefix (,perl5lib))))
                            (find-files scripts "\\.pl"))))))))
       (inputs
        `(("guile" ,guile-3.0) ; for wrappers
-- 
2.31.1

From 0e8be56ecd1c4509d1b4ccdf51ec178a0ec1baaf Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 19:58:53 +0200
Subject: [PATCH 13/18] gnu: sieve-connect: Set #:guile argument of
 'wrap-script'.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/mail.scm
  (sieve-connect)[arguments]<#:phases>{wrap-program}:
  Set #:guile argument of ‘wrap-script’.
---
 gnu/packages/mail.scm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gnu/packages/mail.scm b/gnu/packages/mail.scm
index a885e2417c..7aed1aa5bd 100644
--- a/gnu/packages/mail.scm
+++ b/gnu/packages/mail.scm
@@ -2924,6 +2924,7 @@ transfer protocols.")
              (let ((out (assoc-ref outputs "out"))
                    (path (getenv "PERL5LIB")))
                (wrap-script (string-append out "/bin/sieve-connect")
+                 #:guile (search-input-file inputs "bin/guile")
                  `("PERL5LIB" ":" = (,path)))
                #t))))))
     (inputs
-- 
2.31.1

From 9f71e9330382689e6a79f19568d456e36df3087e Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 20:04:30 +0200
Subject: [PATCH 14/18] gnu: clipmenu: Set #:guile argument of 'wrap-script'.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/xdisorg.scm
  (clipmenu)[arguments]<#:phases>{wrap-script}:
  Set #:guile argument of ‘wrap-script’.
---
 gnu/packages/xdisorg.scm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/xdisorg.scm b/gnu/packages/xdisorg.scm
index de2cba8e57..d339851f51 100644
--- a/gnu/packages/xdisorg.scm
+++ b/gnu/packages/xdisorg.scm
@@ -2555,10 +2555,12 @@ tools to complement clipnotify.")
                       (gawk              (assoc-ref inputs "gawk"))
                       (util-linux        (assoc-ref inputs "util-linux"))
                       (xdotool           (assoc-ref inputs "xdotool"))
-                      (xsel              (assoc-ref inputs "xsel")))
+                      (xsel              (assoc-ref inputs "xsel"))
+                      (guile             (search-input-file inputs "bin/guile")))
                  (for-each
                   (lambda (prog)
                     (wrap-script (string-append out "/bin/" prog)
+                      #:guile guile
                       `("PATH" ":" prefix
                         ,(map (lambda (dir)
                                 (string-append dir "/bin"))
-- 
2.31.1

From 7ecf6502fc902959fd2a233c5f772180678e9f35 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 20:06:12 +0200
Subject: [PATCH 15/18] gnu: vpnc-scripts: Set #:guile argument of
 'wrap-script'.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/vpn.scm
  (vpnc-scripts)[arguments]<#:phases>{wrap-scripts}:
  Set #:guile argument of ‘wrap-script’.
---
 gnu/packages/vpn.scm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/vpn.scm b/gnu/packages/vpn.scm
index a952e3f0db..33ef87c52d 100644
--- a/gnu/packages/vpn.scm
+++ b/gnu/packages/vpn.scm
@@ -192,10 +192,12 @@ Only \"Universal TUN/TAP device driver support\" is needed in the kernel.")
              ;; Wrap scripts with paths to their common hard dependencies.
              ;; Optional dependencies will need to be installed by the user.
              (lambda* (#:key inputs outputs #:allow-other-keys)
-               (let ((out (assoc-ref outputs "out")))
+               (let ((out (assoc-ref outputs "out"))
+                     (guile (search-input-file inputs "bin/guile")))
                  (for-each
                   (lambda (script)
                     (wrap-script (string-append out "/etc/vpnc/" script)
+                      #:guile guile
                       `("PATH" ":" prefix
                         ,(map (lambda (name)
                                 (let ((input (assoc-ref inputs name)))
-- 
2.31.1

From 5a18f07c5d7ea73d306e3b66ff72f285f38376ac Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 20:09:45 +0200
Subject: [PATCH 16/18] gnu: openconnect-sso: Set #:sh argument of
 'wrap-program'.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/vpn.scm
  (openconnect-sso)[arguments]<#:phases>{wrap-qt-process-path}
  Set #:sh argument of ‘wrap-program’.
---
 gnu/packages/vpn.scm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gnu/packages/vpn.scm b/gnu/packages/vpn.scm
index 33ef87c52d..584ff0ec84 100644
--- a/gnu/packages/vpn.scm
+++ b/gnu/packages/vpn.scm
@@ -326,6 +326,7 @@ and probably others.")
                                        (assoc-ref inputs "qtwebengine")
                                        "/lib/qt5/libexec/QtWebEngineProcess")))
                (wrap-program bin
+                 #:sh (search-input-file inputs "bin/bash")
                  `("QTWEBENGINEPROCESS_PATH" = (,qt-process-path)))
                #t))))))
     (inputs
-- 
2.31.1

From b180eb2b419ca8b09412ab30c0442f54ae14775f Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 20:11:50 +0200
Subject: [PATCH 17/18] gnu: protonvpn-cli: Set #:sh argument of
 'wrap-program'.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/vpn.scm
  (protonvpn-cli)[arguments]<#:phases>{wrap-wrapper}:
  Set #:sh argument of ‘wrap-program’.
---
 gnu/packages/vpn.scm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gnu/packages/vpn.scm b/gnu/packages/vpn.scm
index 584ff0ec84..66c103e75f 100644
--- a/gnu/packages/vpn.scm
+++ b/gnu/packages/vpn.scm
@@ -440,6 +440,7 @@ traversing network address translators (@dfn{NAT}s) and firewalls.")
              (let ((entrypoint (string-append (assoc-ref outputs "out")
                                               "/bin/.protonvpn-real")))
                (wrap-program entrypoint
+                            #:sh (search-input-file inputs "bin/bash")
                             `("PATH" ":" prefix
                               ,(map (lambda (name)
                                       (let ((input (assoc-ref inputs name)))
-- 
2.31.1

From c1ab0f5161254e66ae3515df60440dd4bcb46fd4 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 31 May 2021 20:12:55 +0200
Subject: [PATCH 18/18] gnu: wireguard-tools: Set #:sh argument of
 'wrap-program'.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/vpn.scm
  (wireguard-tools)[arguments]<#:phases>{wrap-wg-quick}:
  Set #:sh argument of ‘wrap-program’.
---
 gnu/packages/vpn.scm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gnu/packages/vpn.scm b/gnu/packages/vpn.scm
index 66c103e75f..34715a4cc8 100644
--- a/gnu/packages/vpn.scm
+++ b/gnu/packages/vpn.scm
@@ -726,6 +726,7 @@ WireGuard was added to Linux 5.6.")
                    (coreutils (string-append (assoc-ref inputs "coreutils")
                                              "/bin")))
                (wrap-program (string-append out "/bin/wg-quick")
+                 #:sh (search-input-file inputs "bin/bash")
                  `("PATH" ":" prefix ,(append inputs-sbin
                                               (list coreutils))))
                #t))))))
-- 
2.31.1