[PATCH 00/11] Update Racket to 8.4. Adjust Chez Scheme

DoneSubmitted by Philip McGrath.
Details
7 participants
  • Liliana Marie Prikler
  • Liliana Marie Prikler
  • Ludovic Courtès
  • Maxime Devos
  • Philip McGrath
  • Philip McGrath
  • zimoun
Owner
unassigned
Severity
normal
Merged with
P
P
Philip McGrath wrote on 8 Feb 16:13 +0100
[RFC PATCH 0/9] Update Racket to 8.4. Adjust Chez Scheme packages.
(address . guix-patches@gnu.org)
20220208151316.1897345-1-philip@philipmcgrath.com
Racket 8.4 hasn't been released yet (expect it in a matter of days), but I
wanted to solicit feedback on these changes early.

On the Racket side of things, discussions upstream and with other distribution
packagers have clarified what a ``minimal Racket'' package ought to consist
of, which in turn suggested a nice new boundary between the lowest-level
Racket VM packages, which are concerned with bootstrapping and platform
support, and a more uniform use of layered and tethered installations for both
the 'racket-minimal' and 'racket' packages. I've also started getting the
sources for the other main-distribution Racket packages directly from their
respective repositories, rather than extracting them from the bundled
tarballs. All in all, it's a few steps closer to the goal of a build system
for Racket packages.

For Chez Scheme, I set out to package Racket's variant of Chez Scheme---which
supports architectures not yet supported upstream, e.g. aarch64---and to share
more between the upstream and Racket packages. I also tweaked various things I
found along the way: hopefully some are clear improvements, though there are
some prime opportunities for bikeshedding about naming things.

Let me know what you think!

-Philip

Philip McGrath (9):
gnu: chez-scheme: Move to (gnu packages chez-and-racket-bootstrap).
gnu: chez-scheme: Use "lib/chez-scheme" for search path.
gnu: chez-scheme: Use shared zlib and lz4.
gnu: chez-and-racket-bootstrap: Add utilities for Chez machine types.
gnu: Add stex.
gnu: Add chez-nanopass.
gnu: chez-scheme: Explicitly package bootstrap bootfiles.
gnu: Add chez-scheme-racket-variant.
gnu: racket: Update to 8.3.900.

gnu/local.mk | 5 +-
gnu/packages/chez-and-racket-bootstrap.scm | 1108 ++++++++++++
gnu/packages/chez.scm | 628 +++----
gnu/packages/emacs-xyz.scm | 4 +-
gnu/packages/loko.scm | 4 +-
.../racket-enable-scheme-backport.patch | 465 +++++
...acket-gui-tethered-launcher-backport.patch | 26 +
gnu/packages/racket.scm | 1552 +++++++++++------
8 files changed, 2850 insertions(+), 942 deletions(-)
create mode 100644 gnu/packages/chez-and-racket-bootstrap.scm
create mode 100644 gnu/packages/patches/racket-enable-scheme-backport.patch
create mode 100644 gnu/packages/patches/racket-gui-tethered-launcher-backport.patch

--
2.32.0
P
P
Philip McGrath wrote on 8 Feb 16:18 +0100
[RFC PATCH 1/9] gnu: chez-scheme: Move to (gnu packages chez-and-racket-bootstrap).
(address . 53878@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
20220208151857.1900389-1-philip@philipmcgrath.com
* gnu/packages/chez.scm (nanopass, stex, chez-scheme): Move to ...
* gnu/packages/chez-and-racket-bootstrap.scm: ... this new file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add it.
* gnu/packages/emacs-xyz.scm: Adjust imports accordingly.
* gnu/packages/loko.scm: Likewise.
* gnu/packages/racket.scm: Likewise.
---
gnu/local.mk | 1 +
gnu/packages/chez-and-racket-bootstrap.scm | 278 +++++++++++++++++++++
gnu/packages/chez.scm | 225 +----------------
gnu/packages/emacs-xyz.scm | 2 +-
gnu/packages/loko.scm | 2 +-
gnu/packages/racket.scm | 2 +-
6 files changed, 283 insertions(+), 227 deletions(-)
create mode 100644 gnu/packages/chez-and-racket-bootstrap.scm

Toggle diff (585 lines)
diff --git a/gnu/local.mk b/gnu/local.mk
index f14daf2edd..e3104fc0b6 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -144,6 +144,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/certs.scm			\
   %D%/packages/check.scm			\
   %D%/packages/chemistry.scm			\
+  %D%/packages/chez-and-racket-bootstrap.scm	\
   %D%/packages/chez.scm				\
   %D%/packages/chicken.scm				\
   %D%/packages/chromium.scm			\
diff --git a/gnu/packages/chez-and-racket-bootstrap.scm b/gnu/packages/chez-and-racket-bootstrap.scm
new file mode 100644
index 0000000000..f102b099fb
--- /dev/null
+++ b/gnu/packages/chez-and-racket-bootstrap.scm
@@ -0,0 +1,278 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2016 Federico Beffa <beffa@fbengineering.ch>
+;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2017, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
+;;; Copyright © 2019 Brett Gilio <brettg@gnu.org>
+;;; Copyright © 2020 Brendan Tildesley <mail@brendan.scot>
+;;; Copyright © 2021, 2022 Philip McGrath <philip@philipmcgrath.com>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages chez-and-racket-bootstrap)
+  #:use-module (guix packages)
+  #:use-module (guix download)
+  #:use-module (guix git-download)
+  #:use-module (guix utils)
+  #:use-module (guix gexp)
+  #:use-module (ice-9 match)
+  #:use-module (srfi srfi-1)
+  #:use-module (guix build-system gnu)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages compression)
+  #:use-module (gnu packages ghostscript)
+  #:use-module (gnu packages linux)
+  #:use-module (gnu packages ncurses)
+  #:use-module (gnu packages netpbm)
+  #:use-module (gnu packages tex)
+  #:use-module (gnu packages xorg)
+  #:use-module ((guix licenses)
+                #:prefix license:))
+
+;; Commentary:
+;;
+;; Alphabetically and chronologically, Chez comes before Racket.
+;;
+;; The bootstrapping paths for Chez Scheme and Racket are closely
+;; entwined. Racket CS (the default Racket implementation) is based on (a fork
+;; of) Chez Scheme. Racket's variant of Chez Scheme shares sources for
+;; nanopass and stex with upstream Chez Scheme.
+;;
+;; Racket's variant of Chez Scheme can be bootstrapped by an older Racket
+;; implementation, Racket BC, which can be bootstrapped from C. Porting that
+;; code to work with upstream Chez Scheme (or finding an old version that
+;; does) is our best hope for some day bootstrapping upstream Chez Scheme from
+;; source.
+;;
+;; Putting the relevant definitions together in this module avoids having to
+;; work around dependency cycles.
+;;
+;; Code:
+
+(define nanopass
+  (let ((version "1.9.2"))
+    (origin
+      (method git-fetch)
+      (uri (git-reference
+            (url "https://github.com/nanopass/nanopass-framework-scheme")
+            (commit (string-append "v" version))))
+      (sha256 (base32 "16vjsik9rrzbabbhbxbaha51ppi3f9n8rk59pc6zdyffs0vziy4i"))
+      (file-name (git-file-name "nanopass" version)))))
+
+(define stex
+  ;; This commit includes a fix, which we would otherwise want to use as
+  ;; patch.  Let's revert to tagged releases as soon as one becomes available.
+  (let* ((commit "54051494434a197772bf6ca5b4e6cf6be55f39a5")
+         (version "1.2.2")
+         (version (git-version version "1" commit)))
+    (origin
+      (method git-fetch)
+      (uri (git-reference
+            (url "https://github.com/dybvig/stex")
+            (commit commit)))
+      (sha256 (base32 "01jnvw8qw33gnpzwrakwhsr05h6b609lm180jnspcrb7lds2p23d"))
+      (file-name (git-file-name "stex" version)))))
+
+(define-public chez-scheme
+  (package
+    (name "chez-scheme")
+    (version "9.5.6")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/cisco/ChezScheme")
+             (commit (string-append "v" version))))
+       (sha256
+        (base32 "07s433hn1z2slfc026sidrpzxv3a8narcd40qqr1xrpb9012xdky"))
+       (file-name (git-file-name name version))
+       (snippet
+        ;; Remove bundled libraries.
+        (with-imported-modules '((guix build utils))
+          #~(begin
+              (use-modules (guix build utils))
+              (for-each (lambda (dir)
+                          (when (directory-exists? dir)
+                            (delete-file-recursively dir)))
+                        '("stex"
+                          "nanopass"
+                          "lz4"
+                          "zlib")))))))
+    (build-system gnu-build-system)
+    (inputs
+     `(("libuuid" ,util-linux "lib")
+       ("zlib" ,zlib)
+       ("zlib:static" ,zlib "static")
+       ("lz4" ,lz4)
+       ("lz4:static" ,lz4 "static")
+       ;; for expeditor:
+       ("ncurses" ,ncurses)
+       ;; for X11 clipboard support in expeditor:
+       ;; https://github.com/cisco/ChezScheme/issues/9#issuecomment-222057232
+       ("libx11" ,libx11)))
+    (native-inputs
+     `(("nanopass" ,nanopass) ; source only
+       ;; for docs
+       ("stex" ,stex)
+       ("xorg-rgb" ,xorg-rgb)
+       ("texlive" ,(texlive-updmap.cfg (list texlive-dvips-l3backend
+                                             texlive-epsf
+                                             texlive-fonts-ec
+                                             texlive-oberdiek)))
+       ("ghostscript" ,ghostscript)
+       ("netpbm" ,netpbm)))
+    (native-search-paths
+     (list (search-path-specification
+            (variable "CHEZSCHEMELIBDIRS")
+            (files (list (string-append "lib/csv" version "-site"))))))
+    (outputs '("out" "doc"))
+    (arguments
+     `(#:modules
+       ((guix build gnu-build-system)
+        (guix build utils)
+        (ice-9 ftw)
+        (ice-9 match))
+       #:test-target "test"
+       #:configure-flags
+       '("--threads") ;; TODO when we fix armhf, it doesn't support --threads
+       #:phases
+       (modify-phases %standard-phases
+         ;; put these where configure expects them to be
+         (add-after 'unpack 'unpack-nanopass+stex
+           (lambda* (#:key native-inputs inputs #:allow-other-keys)
+             (for-each (lambda (dep)
+                         (define src
+                           (assoc-ref (or native-inputs inputs) dep))
+                         (copy-recursively src dep
+                                           #:keep-mtime? #t))
+                       '("nanopass" "stex"))))
+         ;; NOTE: the custom Chez 'configure' script doesn't allow
+         ;; unrecognized flags, such as those automatically added
+         ;; by `gnu-build-system`.
+         (replace 'configure
+           (lambda* (#:key inputs outputs
+                           (configure-flags '())
+                           #:allow-other-keys)
+             (let* ((zlib-static (assoc-ref inputs "zlib:static"))
+                    (lz4-static (assoc-ref inputs "lz4:static"))
+                    (out (assoc-ref outputs "out"))
+                    ;; add flags which are always required:
+                    (flags (cons*
+                            (string-append "--installprefix=" out)
+                            (string-append "ZLIB=" zlib-static "/lib/libz.a")
+                            (string-append "LZ4=" lz4-static "/lib/liblz4.a")
+                            ;; Guix will do compress man pages,
+                            ;; and letting Chez try causes an error
+                            "--nogzip-man-pages"
+                            configure-flags)))
+               (format #t "configure flags: ~s~%" flags)
+               ;; Some makefiles (for tests) don't seem to propagate CC
+               ;; properly, so we take it out of their hands:
+               (setenv "CC" ,(cc-for-target))
+               (setenv "HOME" "/tmp")
+               (apply invoke
+                      "./configure"
+                      flags))))
+         ;; The binary file name is called "scheme" as is the one from MIT/GNU
+         ;; Scheme.  We add a symlink to use in case both are installed.
+         (add-after 'install 'install-symlink
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (bin (string-append out "/bin"))
+                    (lib (string-append out "/lib"))
+                    (name "chez-scheme"))
+               (symlink (string-append bin "/scheme")
+                        (string-append bin "/" name))
+               (map (lambda (file)
+                      (symlink file (string-append (dirname file)
+                                                   "/" name ".boot")))
+                    (find-files lib "scheme.boot")))))
+         ;; Building explicitly lets us avoid using substitute*
+         ;; to re-write makefiles.
+         (add-after 'install-symlink 'prepare-stex
+           (lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
+             (let* ((stex+version
+                     (strip-store-file-name
+                      (assoc-ref (or native-inputs inputs) "stex")))
+                    ;; Eventually we want to install stex as a real
+                    ;; package so it's reusable. For now:
+                    (stex-output "/tmp")
+                    (doc-dir (string-append stex-output
+                                            "/share/doc/"
+                                            stex+version)))
+               (with-directory-excursion "stex"
+                 (invoke "make"
+                         "install"
+                         (string-append "LIB="
+                                        stex-output
+                                        "/lib/"
+                                        stex+version)
+                         (string-append "Scheme="
+                                        (assoc-ref outputs "out")
+                                        "/bin/scheme"))
+                 (for-each (lambda (pth)
+                             (install-file pth doc-dir))
+                           '("ReadMe" ; includes the license
+                             "doc/stex.html"
+                             "doc/stex.css"
+                             "doc/stex.pdf"))))))
+         ;; Building the documentation requires stex and a running scheme.
+         ;; FIXME: this is probably wrong for cross-compilation
+         (add-after 'prepare-stex 'install-doc
+           (lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
+             (let* ((chez+version (strip-store-file-name
+                                   (assoc-ref outputs "out")))
+                    (stex+version
+                     (strip-store-file-name
+                      (assoc-ref (or native-inputs inputs) "stex")))
+                    (scheme (string-append (assoc-ref outputs "out")
+                                           "/bin/scheme"))
+                    ;; see note on stex-output in phase build-stex, above:
+                    (stexlib (string-append "/tmp"
+                                            "/lib/"
+                                            stex+version))
+                    (doc-dir (string-append (assoc-ref outputs "doc")
+                                            "/share/doc/"
+                                            chez+version)))
+               (define* (stex-make #:optional (suffix ""))
+                 (invoke "make"
+                         "install"
+                         (string-append "Scheme=" scheme)
+                         (string-append "STEXLIB=" stexlib)
+                         (string-append "installdir=" doc-dir suffix)))
+               (with-directory-excursion "csug"
+                 (stex-make "/csug"))
+               (with-directory-excursion "release_notes"
+                 (stex-make "/release_notes"))
+               (with-directory-excursion doc-dir
+                 (symlink "release_notes/release_notes.pdf"
+                          "release_notes.pdf")
+                 (symlink "csug/csug9_5.pdf"
+                          "csug.pdf"))))))))
+    ;; Chez Scheme does not have a  MIPS backend.
+    ;; FIXME: Debian backports patches to get armhf working.
+    ;; We should too. It is the Chez machine type arm32le
+    ;; (no threaded version upstream yet, though there is in
+    ;; Racket's fork), more specifically (per the release notes) ARMv6.
+    (supported-systems (fold delete %supported-systems
+                             '("mips64el-linux" "armhf-linux")))
+    (home-page "https://cisco.github.io/ChezScheme/")
+    (synopsis "R6RS Scheme compiler and run-time")
+    (description
+     "Chez Scheme is a compiler and run-time system for the language of the
+Revised^6 Report on Scheme (R6RS), with numerous extensions.  The compiler
+generates native code for each target processor, with support for x86, x86_64,
+and 32-bit PowerPC architectures.")
+    (license license:asl2.0)))
diff --git a/gnu/packages/chez.scm b/gnu/packages/chez.scm
index 47904e7b4e..caf61a95f5 100644
--- a/gnu/packages/chez.scm
+++ b/gnu/packages/chez.scm
@@ -4,7 +4,6 @@
 ;;; Copyright © 2017, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2019 Brett Gilio <brettg@gnu.org>
 ;;; Copyright © 2020 Brendan Tildesley <mail@brendan.scot>
-;;; Copyright © 2021 Philip McGrath <philip@philipmcgrath.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -32,234 +31,12 @@ (define-module (gnu packages chez)
   #:use-module (guix utils)
   #:use-module (guix gexp)
   #:use-module (guix build-system gnu)
-  #:use-module (gnu packages compression)
-  #:use-module (gnu packages ncurses)
+  #:use-module (gnu packages chez-and-racket-bootstrap)
   #:use-module (gnu packages ghostscript)
-  #:use-module (gnu packages linux)
-  #:use-module (gnu packages netpbm)
   #:use-module (gnu packages tex)
-  #:use-module (gnu packages compression)
-  #:use-module (gnu packages image)
-  #:use-module (gnu packages xorg)
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-1))
 
-(define nanopass
-  (let ((version "1.9.2"))
-    (origin
-      (method git-fetch)
-      (uri (git-reference
-            (url "https://github.com/nanopass/nanopass-framework-scheme")
-            (commit (string-append "v" version))))
-      (sha256 (base32 "16vjsik9rrzbabbhbxbaha51ppi3f9n8rk59pc6zdyffs0vziy4i"))
-      (file-name (git-file-name "nanopass" version)))))
-
-(define stex
-  ;; This commit includes a fix, which we would otherwise want to use as
-  ;; patch.  Let's revert to tagged releases as soon as one becomes available.
-  (let* ((commit "54051494434a197772bf6ca5b4e6cf6be55f39a5")
-         (version "1.2.2")
-         (version (git-version version "1" commit)))
-    (origin
-      (method git-fetch)
-      (uri (git-reference
-            (url "https://github.com/dybvig/stex")
-            (commit commit)))
-      (sha256 (base32 "01jnvw8qw33gnpzwrakwhsr05h6b609lm180jnspcrb7lds2p23d"))
-      (file-name (git-file-name "stex" version)))))
-
-(define-public chez-scheme
-  (package
-    (name "chez-scheme")
-    (version "9.5.6")
-    (source
-     (origin
-       (method git-fetch)
-       (uri (git-reference
-             (url "https://github.com/cisco/ChezScheme")
-             (commit (string-append "v" version))))
-       (sha256
-        (base32 "07s433hn1z2slfc026sidrpzxv3a8narcd40qqr1xrpb9012xdky"))
-       (file-name (git-file-name name version))
-       (snippet
-        ;; Remove bundled libraries.
-        (with-imported-modules '((guix build utils))
-          #~(begin
-              (use-modules (guix build utils))
-              (for-each (lambda (dir)
-                          (when (directory-exists? dir)
-                            (delete-file-recursively dir)))
-                        '("stex"
-                          "nanopass"
-                          "lz4"
-                          "zlib")))))))
-    (build-system gnu-build-system)
-    (inputs
-     `(("libuuid" ,util-linux "lib")
-       ("zlib" ,zlib)
-       ("zlib:static" ,zlib "static")
-       ("lz4" ,lz4)
-       ("lz4:static" ,lz4 "static")
-       ;; for expeditor:
-       ("ncurses" ,ncurses)
-       ;; for X11 clipboard support in expeditor:
-       ;; https://github.com/cisco/ChezScheme/issues/9#issuecomment-222057232
-       ("libx11" ,libx11)))
-    (native-inputs
-     `(("nanopass" ,nanopass) ; source only
-       ;; for docs
-       ("stex" ,stex)
-       ("xorg-rgb" ,xorg-rgb)
-       ("texlive" ,(texlive-updmap.cfg (list texlive-dvips-l3backend
-                                             texlive-epsf
-                                             texlive-fonts-ec
-                                             texlive-oberdiek)))
-       ("ghostscript" ,ghostscript)
-       ("netpbm" ,netpbm)))
-    (native-search-paths
-     (list (search-path-specification
-            (variable "CHEZSCHEMELIBDIRS")
-            (files (list (string-append "lib/csv" version "-site"))))))
-    (outputs '("out" "doc"))
-    (arguments
-     `(#:modules
-       ((guix build gnu-build-system)
-        (guix build utils)
-        (ice-9 ftw)
-        (ice-9 match))
-       #:test-target "test"
-       #:configure-flags
-       '("--threads") ;; TODO when we fix armhf, it doesn't support --threads
-       #:phases
-       (modify-phases %standard-phases
-         ;; put these where configure expects them to be
-         (add-after 'unpack 'unpack-nanopass+stex
-           (lambda* (#:key native-inputs inputs #:allow-other-keys)
-             (for-each (lambda (dep)
-                         (define src
-                           (assoc-ref (or native-inputs inputs) dep))
-                         (copy-recursively src dep
-                                           #:keep-mtime? #t))
-                       '("nanopass" "stex"))))
-         ;; NOTE: the custom Chez 'configure' script doesn't allow
-         ;; unrecognized flags, such as those automatically added
-         ;; by `gnu-build-system`.
-         (replace 'configure
-           (lambda* (#:key inputs outputs
-                           (configure-flags '())
-                           #:allow-other-keys)
-             (let* ((zlib-static (assoc-ref inputs "zlib:static"))
-                    (lz4-static (assoc-ref inputs "lz4:static"))
-                    (out (assoc-ref outputs "out"))
-                    ;; add flags which are always required:
-                    (flags (cons*
-                            (string-append "--installprefix=" out)
-                            (string-append "ZLIB=" zlib-static "/lib/libz.a")
-                            (string-append "LZ4=" lz4-static "/lib/liblz4.a")
-                            ;; Guix will do compress man pages,
-                            ;; and letting Chez try causes an error
-                            "--nogzip-man-pages"
-                            configure-flags)))
-               (format #t "configure flags: ~s~%" flags)
-               ;; Some makefiles (for tests) don't seem to propagate CC
-               ;; properly, so we take it out of their hands:
-               (setenv "CC" ,(cc-for-target))
-               (setenv "HOME" "/tmp")
-               (apply invoke
-                      "./configure"
-                      flags))))
-         ;; The binary file name is called "scheme" as is the one from MIT/GNU
-         ;; Scheme.  We add a symlink to use in case both are installed.
-         (add-after 'install 'install-symlink
-           (lambda* (#:key outputs #:allow-other-keys)
-             (let* ((out (assoc-ref outputs "out"))
-                    (bin (string-append out "/bin"))
-                    (lib (string-append out "/lib"))
-                    (name "chez-scheme"))
-               (symlink (string-append bin "/scheme")
-                        (string-append bin "/" name))
-               (map (lambda (file)
-                      (symlink file (string-append (dirname file)
-                                                   "/" name ".boot")))
-                    (find-files lib "scheme.boot")))))
-         ;; Building explicitly lets us avoid using substitute*
-         ;; to re-write makefiles.
-         (add-after 'install-symlink 'prepare-stex
-           (lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
-             (let* ((stex+version
-                     (strip-store-file-name
-                      (assoc-ref (or native-inputs inputs) "stex")))
-                    ;; Eventually we want to install stex as a real
-                    ;; package so it's reusable. For now:
-                    (stex-output "/tmp")
-                    (doc-dir (string-append stex-output
-                                            "/share/doc/"
-                                            stex+version)))
-               (with-directory-excursion "stex"
-                 (invoke "make"
-                         "install"
-                         (string-append "LIB="
-                                        stex-output
-                                        "/lib/"
-                                        stex+version)
-                         (string-append "Scheme="
-                                        (assoc-ref outputs "out")
-                                        "/bin/scheme"))
-                 (for-each (lambda (pth)
-                             (install-file pth doc-dir))
-                           '("ReadMe" ; includes the license
-                             "doc/stex.html"
-                             "doc/stex.css"
-                             "doc/stex.pdf"))))))
-         ;; Building the documentation requires stex and a running scheme.
-         ;; FIXME: this is probably wrong for cross-compilation
-         (add-after 'prepare-stex 'install-doc
-           (lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
-             (let* ((chez+version (strip-store-file-name
-                                   (assoc-ref outputs "out")))
-                    (stex+version
-                     (strip-store-file-name
-                      (assoc-ref (or native-inputs inputs) "stex")))
-                    (scheme (string-append (assoc-ref outputs "out")
-                                           "/bin/scheme"))
-                    ;; see note on stex-output in phase build-stex, above:
-                    (stexlib (string-append "/tmp"
-                                            "/lib/"
-                                            stex+version))
-                    (doc-dir (string-append (assoc-ref outputs "doc")
-                                            "/share/doc/"
-                                            chez+version)))
-               (define* (stex-make #:optional (suffix ""))
-                 (invoke "make"
-                         "install"
-                         (string-append "Scheme=" scheme)
-                         (string-append "STEXLIB=" stexlib)
-                         (string-append "installdir=" doc-dir suffix)))
-               (with-directory-excursion "csug"
-                 (stex-make "/csug"))
-               (with-directory-excursion "release_notes"
-                 (stex-make "/release_notes"))
-               (with-directory-excursion doc-dir
-                 (symlink "release_notes/release_notes.pdf"
-                          "release_notes.pdf")
-                 (symlink "csug/csug9_5.pdf"
-                          "csug.pdf"))))))))
-    ;; Chez Scheme does not have a  MIPS backend.
-    ;; FIXME: Debian backports patches to get armhf working.
-    ;; We should too. It is the Chez machine type arm32le
-    ;; (no threaded version upstream yet, though there is in
-    ;; Racket's fork), more specifically (per the release notes) ARMv6.
-    (supported-systems (fold delete %supported-systems
-                             '("mips64el-linux" "armhf-linux")))
-    (home-page "https://cisco.github.io/ChezScheme/")
-    (synopsis "R6RS Scheme compiler and run-time")
-    (description
-     "Chez Scheme is a compiler and run-time system for the language of the
-Revised^6 Report on Scheme (R6RS), with numerous extensions.  The compiler
-generates native code for each target processor, with support for x86, x86_64,
-and 32-bit PowerPC architectures.")
-    (license asl2.0)))
-
 (define-public chez-srfi
   (package
     (name "chez-srfi")
diff --git a/gnu/packages/emacs-xyz.scm b/gnu/packages/emacs-xyz.scm
index 9b57b36623..c6a62e8767 100644
--- a/gnu/packages/emacs-xyz.scm
+++ b/gnu/packages/emacs-xyz.scm
@@ -145,7 +145,7 @@ (define-module (gnu packages emacs-xyz)
   #:use-module (gnu packages aspell)
   #:use-module (gnu packages audio)
   #:use-module (gnu packages bash)
-  #:use-module (gnu packages chez)
+  #:use-module (gnu packages chez-and-racket-bootstrap)
   #:use-module (gnu packages cmake)
   #:use-module (gnu packages code)
   #:use-module (gnu packages cpp)
diff --git a/gnu/packages/loko.scm b/gnu/packages/loko.scm
index ef9312afe3..74a649b8a1 100644
--- a/gnu/packages/loko.scm
+++ b/gnu/packages/loko.scm
@@ -24,7 +24,7 @@ (define-module (gnu packages loko)
   #:use-module (gnu packages package-management)
   #:use-module (gnu packages guile)
   #:use-module (gnu packages guile-xyz)
-  #:use-module (gnu packages chez))
+  #:use-module (gnu packages chez-and-racket-bootstrap))
 
 (define-public loko-scheme
   (package
diff --git a/gnu/packages/racket.scm b/gnu/packages/racket.scm
index d0a5ca494b..865fdff70f 100644
--- a/gnu/packages/racket.scm
+++ b/gnu/packages/racket.scm
@@ -34,7 +34,7 @@ (define-module (gnu packages racket)
   #:use-module (gnu packages)
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages bash)
-  #:use-module (gnu packages chez)
+  #:use-module (gnu packages chez-and-racket-bootstrap)
   #:use-module (gnu packages compression)
   #:use-module (gnu packages databases)
   #:use-module (gnu packages fontutils)
-- 
2.32.0
P
P
Philip McGrath wrote on 8 Feb 16:18 +0100
[RFC PATCH 2/9] gnu: chez-scheme: Use "lib/chez-scheme" for search path.
(address . 53878@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
20220208151857.1900389-2-philip@philipmcgrath.com
There does not seem to be any widely accepted standard path to use for
"CHEZSCHEMELIBDIRS". Using a path without a version number in it avoids
having to compute the actual path everywhere, which would be especially
unpleasant when support is added for the Racket variant of Chez Scheme,
which always has a different version number than upstream.

* gnu/packages/chez-and-racket-bootstrap.scm
(chez-scheme)[native-search-paths]: Change to use "lib/chez-scheme"
instead of "lib/csvX.Y.Z-site" for "CHEZSCHEMELIBDIRS".
* gnu/packages/chez.scm (chez-srfi, chez-web, chez-sockets,
chez-matchable, chez-irregex, chez-fmt, chez-mit, chez-scmutils): Update
accordingly. Also, remove input labels and use G-expressions.
---
gnu/packages/chez-and-racket-bootstrap.scm | 2 +-
gnu/packages/chez.scm | 373 +++++++++++----------
2 files changed, 191 insertions(+), 184 deletions(-)

Toggle diff (467 lines)
diff --git a/gnu/packages/chez-and-racket-bootstrap.scm b/gnu/packages/chez-and-racket-bootstrap.scm
index f102b099fb..1ed4631ced 100644
--- a/gnu/packages/chez-and-racket-bootstrap.scm
+++ b/gnu/packages/chez-and-racket-bootstrap.scm
@@ -136,7 +136,7 @@ (define-public chez-scheme
     (native-search-paths
      (list (search-path-specification
             (variable "CHEZSCHEMELIBDIRS")
-            (files (list (string-append "lib/csv" version "-site"))))))
+            (files (list (string-append "lib/chez-scheme"))))))
     (outputs '("out" "doc"))
     (arguments
      `(#:modules
diff --git a/gnu/packages/chez.scm b/gnu/packages/chez.scm
index caf61a95f5..54bbee7923 100644
--- a/gnu/packages/chez.scm
+++ b/gnu/packages/chez.scm
@@ -37,6 +37,28 @@ (define-module (gnu packages chez)
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-1))
 
+
+;; Help function for Chez Scheme to add the current path to
+;; CHEZSCHEMELIBDIRS.
+(define chez-configure
+  #~(lambda _
+      (let ((chez-env (getenv "CHEZSCHEMELIBDIRS")))
+        (setenv "CHEZSCHEMELIBDIRS"
+                (if chez-env
+                    (string-append ".:" chez-env)
+                    ".")))))
+
+;; Help function to define make flags for some Chez Scheme custom make
+;; files.
+(define (chez-make-flags name version)
+  #~(let ((out #$output))
+      (list
+       ;; Set 'schemedir' so that libraries are installed in
+       ;; 'lib/chez-scheme' like Chez's 'native-search-paths' expects.
+       (string-append "schemedir=" out "/lib/chez-scheme")
+       (string-append "PREFIX=" out)
+       (string-append "DOCDIR=" out "/share/doc/" #$name "-" #$version))))
+
 (define-public chez-srfi
   (package
     (name "chez-srfi")
@@ -54,13 +76,11 @@ (define-public chez-srfi
     (native-inputs
      (list chez-scheme))
     (arguments
-     `(#:make-flags (let ((out (assoc-ref %outputs "out")))
-                      (list (string-append "PREFIX=" out)
-                            "CHEZ=chez-scheme --libdirs ./"
-                            (string-append "chezversion=" ,(package-version chez-scheme))))
-       #:test-target "test"
-       #:phases (modify-phases %standard-phases
-                  (delete 'configure))))
+     (list #:make-flags (chez-make-flags name version)
+           #:test-target "test"
+           #:phases #~(modify-phases %standard-phases
+                        (replace 'configure
+                          #$chez-configure))))
     (home-page "https://github.com/fedeinthemix/chez-srfi")
     (synopsis "SRFI libraries for Chez Scheme")
     (description
@@ -85,42 +105,48 @@ (define-public chez-web
           (base32 "1dq25qygyncbfq4kwwqqgyyakfqjwhp5q23vrf3bff1p66nyfl3b"))))
       (build-system gnu-build-system)
       (native-inputs
-       `(("chez-scheme" ,chez-scheme)
-         ("ghostscript" ,ghostscript)
-         ("texlive" ,(texlive-updmap.cfg (list texlive-oberdiek
-                                          texlive-epsf
-                                          texlive-metapost
-                                          texlive-charter
-                                          texlive-pdftex
-                                          texlive-context
-                                          texlive-cm
-                                          texlive-tex-plain)))))
+       (list chez-scheme
+             ghostscript
+             ;; FIXME: This package fails to build with the error:
+             ;;     mktexpk: don't know how to create bitmap font for bchr8r
+             ;; Replacing the following with `texlive` fixes it.
+             ;; What is missing?
+             (texlive-updmap.cfg (list texlive-oberdiek
+                                       texlive-epsf
+                                       texlive-metapost
+                                       texlive-charter
+                                       texlive-pdftex
+                                       texlive-context
+                                       texlive-cm
+                                       texlive-tex-plain))))
       (arguments
-       `(#:make-flags (list (string-append "PREFIX=" %output)
-                            (string-append "DOCDIR=" %output "/share/doc/"
-                                           ,name "-" ,version)
-                            (string-append "LIBDIR=" %output "/lib/chezweb")
-                            (string-append "TEXDIR=" %output "/share/texmf-local"))
-                      #:tests? #f        ; no tests
-                      #:phases
-                      (modify-phases %standard-phases
-                        ;; This package has a custom "bootstrap" script that
-                        ;; is meant to be run from the Makefile.
-                        (delete 'bootstrap)
-                        (replace 'configure
-                          (lambda* _
-                            (copy-file "config.mk.template" "config.mk")
-                            (substitute* "tangleit"
-                              (("\\./cheztangle\\.ss" all)
-                               (string-append "chez-scheme --program " all)))
-                            (substitute* "weaveit"
-                              (("mpost chezweb\\.mp")
-                               "mpost --tex=tex chezweb.mp")
-                              (("\\./chezweave" all)
-                               (string-append "chez-scheme --program " all)))
-                            (substitute* "installit"
-                              (("-g \\$GROUP -o \\$OWNER") ""))
-                            #t)))))
+       (list
+        #:make-flags
+        #~(list (string-append "PREFIX=" #$output)
+                (string-append "DOCDIR=" #$output "/share/doc/"
+                               #$name "-" #$version)
+                ;; lib/chez-scheme/chezweb ???
+                (string-append "LIBDIR=" #$output "/lib/chezweb")
+                (string-append "TEXDIR=" #$output "/share/texmf-local"))
+        #:tests? #f ; no tests
+        #:phases
+        #~(modify-phases %standard-phases
+            ;; This package has a custom "bootstrap" script that
+            ;; is meant to be run from the Makefile.
+            (delete 'bootstrap)
+            (replace 'configure
+              (lambda* _
+                (copy-file "config.mk.template" "config.mk")
+                (substitute* "tangleit"
+                  (("\\./cheztangle\\.ss" all)
+                   (string-append "scheme --program " all)))
+                (substitute* "weaveit"
+                  (("mpost chezweb\\.mp")
+                   "mpost --tex=tex chezweb.mp")
+                  (("\\./chezweave" all)
+                   (string-append "scheme --program " all)))
+                (substitute* "installit"
+                  (("-g \\$GROUP -o \\$OWNER") "")))))))
       (home-page "https://github.com/arcfide/ChezWEB")
       (synopsis "Hygienic Literate Programming for Chez Scheme")
       (description "ChezWEB is a system for doing Knuthian style WEB
@@ -144,95 +170,74 @@ (define-public chez-sockets
           (base32 "1n5fbwwz51fdzvjackgmnsgh363g9inyxv7kmzi0469cwavwcx5m"))))
       (build-system gnu-build-system)
       (native-inputs
-       `(("chez-scheme" ,chez-scheme)
-         ("chez-web" ,chez-web)
-         ("texlive" ,(texlive-updmap.cfg (list texlive-pdftex)))))
+       (list chez-scheme
+             chez-web
+             (texlive-updmap.cfg (list texlive-pdftex))))
       (arguments
-       `(#:tests? #f              ; no tests
-         #:phases
-         (modify-phases %standard-phases
-           (replace 'configure
-             (lambda* (#:key outputs inputs #:allow-other-keys)
-               (let* ((out (assoc-ref outputs "out"))
-                      (chez-web (assoc-ref inputs "chez-web"))
-                      (chez (assoc-ref inputs "chez-scheme"))
-                      (chez-h (dirname (car (find-files chez "scheme\\.h")))))
-                 (substitute* "Makefile"
-                   (("(SCHEMEH=).*$" all var)
-                    (string-append var chez-h)))
-                 #t)))
-           (add-before 'build 'tangle
-             (lambda* (#:key inputs #:allow-other-keys)
-               (setenv "TEXINPUTS"
-                       (string-append
-                        (getcwd) ":"
-                        (assoc-ref inputs "chez-web") "/share/texmf-local/tex/generic:"
-                        ":"))
-               ;; just using "make" tries to build the .c files before
-               ;; they are created.
-               (and (invoke "make" "sockets")
-                    (invoke "make"))))
-           (replace 'build
-             (lambda* (#:key outputs inputs #:allow-other-keys)
-               (let* ((out (assoc-ref outputs "out"))
-                      (chez-site (string-append out "/lib/csv"
-                                                ,(package-version chez-scheme)
-                                                "-site/arcfide")))
-                 ;; make sure Chez Scheme can find the shared libraries.
-                 (substitute* "sockets.ss"
-                   (("(load-shared-object) \"(socket-ffi-values\\.[sd][oy].*)\""
-                     all cmd so)
-                    (string-append cmd " \"" chez-site "/" so "\""))
-                   (("sockets-stub\\.[sd][oy].*" all)
-                    (string-append chez-site "/" all)))
-                 ;; to compile chez-sockets, the .so files must be
-                 ;; installed (because of the absolute path we
-                 ;; inserted above).
-                 (for-each (lambda (f d) (install-file f d))
-                           '("socket-ffi-values.so" "sockets-stub.so")
-                           (list chez-site chez-site))
-                 (zero? (system "echo '(compile-file \"sockets.sls\")' | scheme -q")))))
-           (replace 'install
-             (lambda* (#:key outputs inputs #:allow-other-keys)
-               (let* ((out (assoc-ref outputs "out"))
-                      (lib (string-append out "/lib/chez-sockets"))
-                      (doc (string-append out "/share/doc/" ,name "-" ,version))
-                      (chez-site (string-append out "/lib/csv"
-                                                ,(package-version chez-scheme)
-                                                "-site/arcfide")))
-                 (for-each (lambda (f d) (install-file f d))
-                           '("sockets.pdf" "sockets.so")
-                           (list doc chez-site))
-                 #t))))))
+       (list
+        #:tests? #f ; no tests
+        #:phases
+        #~(modify-phases %standard-phases
+            (replace 'configure
+              (lambda* (#:key native-inputs inputs #:allow-other-keys)
+                (let* ((scheme (search-input-file (or native-inputs inputs)
+                                                  "/bin/scheme"))
+                       (lib (string-append (dirname scheme) "/../lib"))
+                       (header-file (car (find-files lib "scheme\\.h")))
+                       (include-dir (dirname header-file)))
+                  (substitute* "Makefile"
+                    (("(SCHEMEH=).*$" _ var)
+                     (string-append var include-dir))))))
+            (add-before 'build 'tangle
+              (lambda* (#:key inputs #:allow-other-keys)
+                (setenv "TEXINPUTS"
+                        (string-append
+                         (getcwd) ":"
+                         (assoc-ref inputs "chez-web")
+                         "/share/texmf-local/tex/generic:"
+                         ":"))
+                ;; just using "make" tries to build the .c files before
+                ;; they are created.
+                (and (invoke "make" "sockets")
+                     (invoke "make"))))
+            (replace 'build
+              (lambda args
+                (let ((chez-site (string-append #$output
+                                                "/lib/chez-scheme/arcfide")))
+                  ;; make sure Chez Scheme can find the shared libraries.
+                  (substitute* "sockets.ss"
+                    (("(object \")(socket-ffi-values\\.[sd][oy][^\"]*)(\")"
+                      _ pre file post)
+                     (string-append pre chez-site "/" file post))
+                    (("(\")(sockets-stub\\.[sd][oy][^\"]*)(\")"
+                      _ pre file post)
+                     (string-append pre chez-site "/" file post)))
+                  ;; to compile chez-sockets, the .so files must be
+                  ;; installed (because of the absolute path we
+                  ;; inserted above).
+                  (for-each (lambda (f)
+                              (install-file f chez-site))
+                            '("socket-ffi-values.so"
+                              "sockets-stub.so"))
+                  (invoke "bash"
+                          "-c"
+                          (format #f "echo '~s' | scheme -q"
+                                  '(compile-file "sockets.sls"))))))
+            (replace 'install
+              (lambda args
+                (install-file "sockets.so"
+                              (string-append #$output
+                                             "/lib/chez-scheme/arcfide"))
+                (install-file "sockets.pdf"
+                              (string-append #$output
+                                             "/share/doc/"
+                                             #$name "-" #$version)))))))
       (home-page "https://github.com/arcfide/chez-sockets")
       (synopsis "Extensible sockets library for Chez Scheme")
       (description "Chez-sockets is an extensible sockets library for
 Chez Scheme.")
       (license expat))))
 
-;; Help function for Chez Scheme to add the current path to
-;; CHEZSCHEMELIBDIRS.
-(define chez-configure
-  '(lambda _
-     (let ((chez-env (getenv "CHEZSCHEMELIBDIRS")))
-       (setenv "CHEZSCHEMELIBDIRS"
-               (if chez-env
-                   (string-append ".:" chez-env)
-                   "."))
-       #t)))
-
-;; Help function to define make flags for some Chez Scheme custom make
-;; files.
-(define (chez-make-flags name version)
-  `(let ((out (assoc-ref %outputs "out")))
-     (list
-      ;; Set 'chezversion' so that libraries are installed in
-      ;; 'lib/csvX.Y.Z-site' like Chez's 'native-search-paths' expects.
-      (string-append "chezversion=" ,(package-version chez-scheme))
-      (string-append "PREFIX=" out)
-      (string-append "DOCDIR=" out "/share/doc/"
-                     ,name "-" ,version))))
-
 (define-public chez-matchable
   (package
     (name "chez-matchable")
@@ -253,10 +258,11 @@ (define-public chez-matchable
     (native-inputs
      (list chez-scheme))
     (arguments
-     `(#:make-flags ,(chez-make-flags name version)
-       #:test-target "test"
-       #:phases (modify-phases %standard-phases
-                  (replace 'configure ,chez-configure))))
+     (list #:make-flags (chez-make-flags name version)
+           #:test-target "test"
+           #:phases #~(modify-phases %standard-phases
+                        (replace 'configure
+                          #$chez-configure))))
     (synopsis "Portable hygienic pattern matcher for Scheme")
     (description "This package provides a superset of the popular Scheme
 @code{match} package by Andrew Wright, written in fully portable
@@ -284,10 +290,11 @@ (define-public chez-irregex
     (native-inputs
      (list chez-scheme))
     (arguments
-     `(#:make-flags ,(chez-make-flags name version)
-       #:test-target "test"
-       #:phases (modify-phases %standard-phases
-                  (replace 'configure ,chez-configure))))
+     (list #:make-flags (chez-make-flags name version)
+           #:test-target "test"
+           #:phases #~(modify-phases %standard-phases
+                        (replace 'configure
+                          #$chez-configure))))
     (home-page "https://github.com/fedeinthemix/chez-irregex")
     (synopsis "Portable regular expression library for Scheme")
     (description "This package provides a portable and efficient
@@ -314,17 +321,18 @@ (define-public chez-fmt
     (native-inputs
      (list chez-scheme))
     (arguments
-     `(#:make-flags ,(chez-make-flags name version)
-       #:test-target "chez-check"
-       #:phases
-       (modify-phases %standard-phases
-         (replace 'configure ,chez-configure)
-         (replace 'build
-           (lambda* (#:key (make-flags '()) #:allow-other-keys)
-             (apply invoke "make" "chez-build" make-flags)))
-         (replace 'install
-           (lambda* (#:key (make-flags '()) #:allow-other-keys)
-             (apply invoke "make" "chez-install" make-flags))))))
+     (list #:make-flags (chez-make-flags name version)
+           #:test-target "chez-check"
+           #:phases
+           #~(modify-phases %standard-phases
+               (replace 'configure
+                 #$chez-configure)
+               (replace 'build
+                 (lambda* (#:key (make-flags '()) #:allow-other-keys)
+                   (apply invoke "make" "chez-build" make-flags)))
+               (replace 'install
+                 (lambda* (#:key (make-flags '()) #:allow-other-keys)
+                   (apply invoke "make" "chez-install" make-flags))))))
     (home-page "http://synthcode.com/scheme/fmt")
     (synopsis "Combinator formatting library for Chez Scheme")
     (description "This package provides a library of procedures for
@@ -354,10 +362,11 @@ (define-public chez-mit
     (native-inputs
      (list chez-scheme))
     (arguments
-     `(#:make-flags ,(chez-make-flags name version)
-       #:test-target "test"
-       #:phases (modify-phases %standard-phases
-                  (replace 'configure ,chez-configure))))
+     (list #:make-flags (chez-make-flags name version)
+           #:test-target "test"
+           #:phases #~(modify-phases %standard-phases
+                        (replace 'configure
+                          #$chez-configure))))
     (synopsis "MIT/GNU Scheme compatibility library for Chez Scheme")
     (description "This package provides a set of MIT/GNU Scheme compatibility
 libraries for Chez Scheme.  The main goal was to provide the functionality
@@ -386,46 +395,44 @@ (define-public chez-scmutils
     (propagated-inputs
      (list chez-mit chez-srfi))
     (arguments
-     `(#:make-flags ,(chez-make-flags name version)
-       #:tests? #f                      ; no test suite
-       #:phases
-       (modify-phases %standard-phases
-         (replace 'configure ,chez-configure)
-         ;; Since the documentation is lacking, we install the source
-         ;; code.  For things to work correctly we have to replace
-         ;; relative paths by absolute ones in 'include' forms.  This
-         ;; in turn requires us to compile the files in the final
-         ;; destination.
-         (delete 'build)
-         (add-after 'install 'install-src
-           (lambda* (#:key (make-flags '()) #:allow-other-keys)
-             (apply invoke "make" "install-src" make-flags)))
-         (add-after 'install-src 'absolute-path-in-scm-files
-           (lambda* (#:key outputs #:allow-other-keys)
-             (let ((out (assoc-ref outputs "out")))
-               (for-each (lambda (file)
-                           (substitute* file
-                             (("include +\"\\./scmutils")
-                              (string-append "include \"" (dirname file)))))
-                         (find-files out "\\.sls"))
-               (for-each (lambda (file)
-                           (substitute* file
-                             (("include +\"\\./scmutils/simplify")
-                              (string-append "include \"" (dirname file)))))
-                         (find-files out "fbe-syntax\\.scm"))
-               #t)))
+     (list
+      #:make-flags (chez-make-flags name version)
+      #:tests? #f  ; no test suite
+      #:phases
+      #~(modify-phases %standard-phases
+          (replace 'configure
+            #$chez-configure)
+          ;; Since the documentation is lacking, we install the source
+          ;; code.  For things to work correctly we have to replace
+          ;; relative paths by absolute ones in 'include' forms.  This
+          ;; in turn requires us to compile the files in the final
+          ;; destination.
+          (delete 'build)
+          (add-after 'install 'install-src
+            (lambda* (#:key (make-flags '()) #:allow-other-keys)
+              (apply invoke "make" "install-src" make-flags)))
+          (add-after 'install-src 'absolute-path-in-scm-files
+            (lambda* (#:key #:allow-other-keys)
+              (for-each (lambda (file)
+                          (substitute* file
+                            (("include +\"\\./scmutils")
+                             (string-append "include \"" (dirname file)))))
+                        (find-files #$output "\\.sls"))
+              (for-each (lambda (file)
+                          (substitute* file
+                            (("include +\"\\./scmutils/simplify")
+                             (string-append "include \"" (dirname file)))))
+                        (find-files #$output "fbe-syntax\\.scm"))))
          (add-after 'absolute-path-in-scm-files 'build
-           (lambda* (#:key outputs (make-flags '()) #:allow-other-keys)
-             (let* ((out (assoc-ref outputs "out"))
-                    (mk-file (car (find-files out "Makefile"))))
+           (lambda* (#:key (make-flags '()) #:allow-other-keys)
+             (let ((mk-file (car (find-files #$output "Makefile"))))
                (with-directory-excursion (dirname mk-file)
                  (apply invoke "make" "build" make-flags)))))
          (add-after 'build 'clean-up
-           (lambda* (#:key outputs #:allow-other-keys)
-             (let* ((out (assoc-ref outputs "out")))
-               (for-each delete-file
-                         (find-files out "Makefile|compile-all\\.ss"))
-               #t))))))
+           (lambda args
+             (for-each delete-file
+                       (find-files #$output
+                                   "Makefile|compile-all\\.ss")))))))
     (synopsis "Port of MIT/GNU Scheme Scmutils to Chez Scheme")
     (description "This package provides a port of the MIT/GNU Scheme
 Scmutils program to Chez Scheme.  The port consists of a set of
-- 
2.32.0
P
P
Philip McGrath wrote on 8 Feb 16:18 +0100
[RFC PATCH 3/9] gnu: chez-scheme: Use shared zlib and lz4.
(address . 53878@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
20220208151857.1900389-3-philip@philipmcgrath.com
This change also involves building 'libkernel.a' instead of 'kernel.o'.

Support for these build options was merged upstream in 2019: see

* gnu/packages/chez-and-racket-bootstrap (chez-scheme)[inputs]: Remove
'zlib:static' and 'lz4:static'.
[arguments]: Adjust configure phase accordingly.
---
gnu/packages/chez-and-racket-bootstrap.scm | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)

Toggle diff (39 lines)
diff --git a/gnu/packages/chez-and-racket-bootstrap.scm b/gnu/packages/chez-and-racket-bootstrap.scm
index 1ed4631ced..11d570059b 100644
--- a/gnu/packages/chez-and-racket-bootstrap.scm
+++ b/gnu/packages/chez-and-racket-bootstrap.scm
@@ -114,9 +114,7 @@ (define-public chez-scheme
     (inputs
      `(("libuuid" ,util-linux "lib")
        ("zlib" ,zlib)
-       ("zlib:static" ,zlib "static")
        ("lz4" ,lz4)
-       ("lz4:static" ,lz4 "static")
        ;; for expeditor:
        ("ncurses" ,ncurses)
        ;; for X11 clipboard support in expeditor:
@@ -169,14 +167,14 @@ (define src
                     (lz4-static (assoc-ref inputs "lz4:static"))
                     (out (assoc-ref outputs "out"))
                     ;; add flags which are always required:
-                    (flags (cons*
-                            (string-append "--installprefix=" out)
-                            (string-append "ZLIB=" zlib-static "/lib/libz.a")
-                            (string-append "LZ4=" lz4-static "/lib/liblz4.a")
-                            ;; Guix will do compress man pages,
-                            ;; and letting Chez try causes an error
-                            "--nogzip-man-pages"
-                            configure-flags)))
+                    (flags (cons* (string-append "--installprefix=" out)
+                                  "ZLIB=-lz"
+                                  "LZ4=-llz4"
+                                  "--libkernel"
+                                  ;; Guix will do compress-man-pages,
+                                  ;; and letting Chez try causes an error
+                                  "--nogzip-man-pages"
+                                  configure-flags)))
                (format #t "configure flags: ~s~%" flags)
                ;; Some makefiles (for tests) don't seem to propagate CC
                ;; properly, so we take it out of their hands:
-- 
2.32.0
P
P
Philip McGrath wrote on 8 Feb 16:18 +0100
[RFC PATCH 4/9] gnu: chez-and-racket-bootstrap: Add utilities for Chez machine types.
(address . 53878@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
20220208151857.1900389-4-philip@philipmcgrath.com
* gnu/packages/chez-and-racket-bootstrap.scm (chez-machine->unthreaded,
chez-machine->upstream-restriction, chez-machine->nix-system,
nix-system->chez-machine): New private functions.
(%nix-arch-to-chez-alist, %nix-os-to-chez-alist): New private constants.
(chez-scheme)[supported-systems]: Compute based on
'nix-system->chez-machine' and 'chez-machine->upstream-restriction'.
---
gnu/packages/chez-and-racket-bootstrap.scm | 142 ++++++++++++++++++++-
1 file changed, 140 insertions(+), 2 deletions(-)

Toggle diff (170 lines)
diff --git a/gnu/packages/chez-and-racket-bootstrap.scm b/gnu/packages/chez-and-racket-bootstrap.scm
index 11d570059b..fc1da53178 100644
--- a/gnu/packages/chez-and-racket-bootstrap.scm
+++ b/gnu/packages/chez-and-racket-bootstrap.scm
@@ -28,7 +28,9 @@ (define-module (gnu packages chez-and-racket-bootstrap)
   #:use-module (guix utils)
   #:use-module (guix gexp)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 regex)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-26)
   #:use-module (guix build-system gnu)
   #:use-module (gnu packages)
   #:use-module (gnu packages compression)
@@ -61,6 +63,134 @@ (define-module (gnu packages chez-and-racket-bootstrap)
 ;;
 ;; Code:
 
+(define (chez-machine->unthreaded mach)
+  "Given a string MACH naming a Chez Scheme machine type, returns a string
+naming the unthreaded machine type for the same architecture and OS as MACH.
+The returned string may share storage with MACH."
+  (if (eqv? #\t (string-ref mach 0))
+      (substring mach 1)
+      mach))
+(define (chez-machine->threaded mach)
+  "Like @code{chez-machine->unthreaded}, but returns the threaded machine
+type."
+  (if (eqv? #\t (string-ref mach 0))
+      mach
+      (string-append "t" mach)))
+
+;; Based on the implementation from raco-cross-lib/private/cross/platform.rkt
+;; in https://github.com/racket/raco-cross.
+;; For supported platforms, refer to release_notes/release_notes.stex in the
+;; upstream Chez Scheme repository or to racket/src/ChezScheme/README.md
+;; in https://github.com/racket/racket.
+(define %nix-arch-to-chez-alist
+  `(("x86_64" . "a6")
+    ("i386" . "i3")
+    ("aarch64" . "arm64")
+    ("armhf" . "arm32") ;; Chez supports ARM v6+
+    ("ppc" . "ppc32")))
+(define %nix-os-to-chez-alist
+  `(("w64-mingw32" . "nt")
+    ("darwin" . "osx")
+    ("linux" . "le")
+    ("freebsd" . "fb")
+    ("openbsd" . "ob")
+    ("netbsd" . "nb")
+    ("solaris" . "s2")))
+
+(define (chez-machine->upstream-restriction mach)
+  "Given a string MACH naming a Chez Scheme machine type, returns a symbol
+naming a restriction on the upstream Chez Scheme implementation compared to
+the Racket variant, or @code{#f} if no such restriction exists.  The
+restriction is reported for the architecture--OS pair, regardless of whether
+MACH specifies a threaded or an unthreaded variant.
+
+Possible restrictions currently include:
+@itemize @bullet
+@item
+@code{'no-threads}: Support for native threads is not available upstream.
+@item
+@code{'no-support}: The upstream release doesn't claim to support this
+architecture--OS combination at all.
+@end itemize
+
+See @code{chez-machine->nix-system} for more details about acceptable values
+for MACH."
+  (let ((mach (chez-machine->unthreaded mach)))
+    (cond
+     ((string-prefix? "arm64" mach)
+      'no-support)
+     ((string-prefix? "arm32" mach)
+      (if (string-suffix? "le" mach)
+          'no-threads
+          'no-support))
+     ((string-prefix? "ppc32" mach)
+      (if (string-suffix? "le" mach)
+          #f
+          'no-support))
+     (else
+      #f))))
+
+(define (chez-machine->nix-system mach)
+  "Return the Nix system type corresponding to the Chez Scheme machine type
+MACH.  If MACH is not a string representing a known machine type, an exception
+is raised.  This function does not distinguish between threaded and unthreaded
+variants of MACH.
+
+Note that this function only handles Chez Scheme machine types in the
+strictest sense, not other kinds of descriptors sometimes used in place of a
+Chez Scheme machine type by the Racket, such as @code{\"pb\"}, @code{#f}, or
+@code{\"racket\"}.  (When using such extensions, the Chez Scheme machine type
+for the host system is often still relevant.)"
+  (let ((mach (chez-machine->unthreaded mach)))
+    (let find-arch ((alist %nix-arch-to-chez-alist))
+      (match alist
+        (((nix . chez) . alist)
+         (if (string-prefix? chez mach)
+             (string-append
+              nix "-" (let ((mach-os (substring mach (string-length chez))))
+                        (let find-os ((alist %nix-os-to-chez-alist))
+                          (match alist
+                            (((nix . chez) . alist)
+                             (if (equal? chez mach-os)
+                                 nix
+                                 (find-os alist)))))))
+             (find-arch alist)))))))
+
+(define* (nix-system->chez-machine #:optional (system (%current-system))
+                                   #:key (threads? 'always))
+  "Return the Chez Scheme machine type corresponding to the Nix system
+identifier SYSTEM, or @code{#f} if the translation of SYSTEM to a Chez Scheme
+machine type is undefined.
+
+When THREADS? is @code{'always} (the default), the threaded variant of the
+machine type will be returned: note that the package returned by
+@code{chez-scheme-for-system} will always support native threads.  When
+THREADS? is @code{#f}, the unthreaded machine type will be returned.  If
+THREADS? is @code{'upstream} (the default), the threaded variant of the
+machine type will be returned if and only if it is supported by upstream Chez
+Scheme (see @code{chez-machine->upstream-restriction}).  If THREADS? is any
+other value, an exception is raised."
+  (let* ((hyphen (string-index system #\-))
+         (nix-arch (substring system 0 hyphen))
+         (nix-os (substring system (+ 1 hyphen)))
+         (chez-arch (assoc-ref %nix-arch-to-chez-alist nix-arch))
+         (chez-os (assoc-ref %nix-os-to-chez-alist nix-os))
+         (mach (and chez-arch chez-os (string-append chez-arch chez-os))))
+    (and mach
+         (match threads?
+           ('always
+            (chez-machine->threaded mach))
+           (#f
+            mach)
+           ('upstream
+            (if (chez-machine->upstream-restriction mach)
+                mach
+                (chez-machine->threaded mach)))))))
+
+;;
+;; Chez Scheme:
+;;
+
 (define nanopass
   (let ((version "1.9.2"))
     (origin
@@ -264,8 +394,16 @@ (define* (stex-make #:optional (suffix ""))
     ;; We should too. It is the Chez machine type arm32le
     ;; (no threaded version upstream yet, though there is in
     ;; Racket's fork), more specifically (per the release notes) ARMv6.
-    (supported-systems (fold delete %supported-systems
-                             '("mips64el-linux" "armhf-linux")))
+    (supported-systems
+     (delete
+      "armhf-linux" ;; <-- should work, but reportedly broken
+      (filter
+       (lambda (system)
+         (and=> (nix-system->chez-machine system)
+                (lambda (mach)
+                  (not (eq? 'no-support
+                            (chez-machine->upstream-restriction mach))))))
+       %supported-systems)))
     (home-page "https://cisco.github.io/ChezScheme/")
     (synopsis "R6RS Scheme compiler and run-time")
     (description
-- 
2.32.0
P
P
Philip McGrath wrote on 8 Feb 16:18 +0100
[RFC PATCH 5/9] gnu: Add stex.
(address . 53878@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
20220208151857.1900389-5-philip@philipmcgrath.com
* gnu/packages/chez-and-racket-bootstrap.scm (stex-bootstrap): New
variable.
(stex): Change from origin to package inheriting from 'stex-bootstrap'.
(chez-scheme)[native-inputs]: Add 'stex-bootstrap'. Remove
labels. Remove dependencies of stex-bootstrap.
[inputs]: Remove labels.
[arguments]: Adapt to use 'stex-bootstrap', 'search-input-file', and
G-expressions.
(nanopass): Make it public as a temporary workaround for Racket.
* gnu/packages/racket.scm
(racket-bootstrap-chez-bootfiles)[native-inputs]: Update accordingly.
---
gnu/packages/chez-and-racket-bootstrap.scm | 435 ++++++++++++---------
gnu/packages/racket.scm | 5 +-
2 files changed, 263 insertions(+), 177 deletions(-)

Toggle diff (499 lines)
diff --git a/gnu/packages/chez-and-racket-bootstrap.scm b/gnu/packages/chez-and-racket-bootstrap.scm
index fc1da53178..c0d5e2897d 100644
--- a/gnu/packages/chez-and-racket-bootstrap.scm
+++ b/gnu/packages/chez-and-racket-bootstrap.scm
@@ -31,6 +31,7 @@ (define-module (gnu packages chez-and-racket-bootstrap)
   #:use-module (ice-9 regex)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-26)
+  #:use-module (guix build-system copy)
   #:use-module (guix build-system gnu)
   #:use-module (gnu packages)
   #:use-module (gnu packages compression)
@@ -191,113 +192,83 @@ (define* (nix-system->chez-machine #:optional (system (%current-system))
 ;; Chez Scheme:
 ;;
 
-(define nanopass
-  (let ((version "1.9.2"))
-    (origin
-      (method git-fetch)
-      (uri (git-reference
-            (url "https://github.com/nanopass/nanopass-framework-scheme")
-            (commit (string-append "v" version))))
-      (sha256 (base32 "16vjsik9rrzbabbhbxbaha51ppi3f9n8rk59pc6zdyffs0vziy4i"))
-      (file-name (git-file-name "nanopass" version)))))
+(define unbundle-chez-submodules
+  #~(begin
+      (use-modules (guix build utils))
+      (for-each (lambda (dir)
+                (when (directory-exists? dir)
+                  (delete-file-recursively dir)))
+              '("stex"
+                "nanopass"
+                "lz4"
+                "zlib"))))
 
-(define stex
-  ;; This commit includes a fix, which we would otherwise want to use as
-  ;; patch.  Let's revert to tagged releases as soon as one becomes available.
-  (let* ((commit "54051494434a197772bf6ca5b4e6cf6be55f39a5")
-         (version "1.2.2")
-         (version (git-version version "1" commit)))
-    (origin
-      (method git-fetch)
-      (uri (git-reference
-            (url "https://github.com/dybvig/stex")
-            (commit commit)))
-      (sha256 (base32 "01jnvw8qw33gnpzwrakwhsr05h6b609lm180jnspcrb7lds2p23d"))
-      (file-name (git-file-name "stex" version)))))
+(define (unpack-nanopass+stex)
+  ;; delayed resolution of `nanopass`
+  #~(begin
+      (copy-recursively #$nanopass
+                        "nanopass"
+                        #:keep-mtime? #t)
+      (mkdir-p "stex")
+      (with-output-to-file "stex/Mf-stex"
+        (lambda ()
+          ;; otherwise, it will try to download submodules
+          (display "# to placate ../configure")))))
 
 (define-public chez-scheme
   (package
     (name "chez-scheme")
+    ;; The version should match `(scheme-version-number)`.
+    ;; See s/cmacros.ss c. line 360.
     (version "9.5.6")
-    (source
-     (origin
-       (method git-fetch)
-       (uri (git-reference
-             (url "https://github.com/cisco/ChezScheme")
-             (commit (string-append "v" version))))
-       (sha256
-        (base32 "07s433hn1z2slfc026sidrpzxv3a8narcd40qqr1xrpb9012xdky"))
-       (file-name (git-file-name name version))
-       (snippet
-        ;; Remove bundled libraries.
-        (with-imported-modules '((guix build utils))
-          #~(begin
-              (use-modules (guix build utils))
-              (for-each (lambda (dir)
-                          (when (directory-exists? dir)
-                            (delete-file-recursively dir)))
-                        '("stex"
-                          "nanopass"
-                          "lz4"
-                          "zlib")))))))
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/cisco/ChezScheme")
+                    (commit (string-append "v" version))))
+              (sha256
+               (base32
+                "07s433hn1z2slfc026sidrpzxv3a8narcd40qqr1xrpb9012xdky"))
+              (file-name (git-file-name name version))
+              (snippet unbundle-chez-submodules)))
     (build-system gnu-build-system)
     (inputs
-     `(("libuuid" ,util-linux "lib")
-       ("zlib" ,zlib)
-       ("lz4" ,lz4)
-       ;; for expeditor:
-       ("ncurses" ,ncurses)
-       ;; for X11 clipboard support in expeditor:
-       ;; https://github.com/cisco/ChezScheme/issues/9#issuecomment-222057232
-       ("libx11" ,libx11)))
-    (native-inputs
-     `(("nanopass" ,nanopass) ; source only
-       ;; for docs
-       ("stex" ,stex)
-       ("xorg-rgb" ,xorg-rgb)
-       ("texlive" ,(texlive-updmap.cfg (list texlive-dvips-l3backend
-                                             texlive-epsf
-                                             texlive-fonts-ec
-                                             texlive-oberdiek)))
-       ("ghostscript" ,ghostscript)
-       ("netpbm" ,netpbm)))
+     (list
+      `(,util-linux "lib") ;<-- libuuid
+      zlib
+      lz4
+      ncurses ;<-- for expeditor
+      ;; for X11 clipboard support in expeditor:
+      ;; https://github.com/cisco/ChezScheme/issues/9#issuecomment-222057232
+      libx11))
+    (native-inputs (list stex-bootstrap))
     (native-search-paths
      (list (search-path-specification
             (variable "CHEZSCHEMELIBDIRS")
             (files (list (string-append "lib/chez-scheme"))))))
     (outputs '("out" "doc"))
     (arguments
-     `(#:modules
-       ((guix build gnu-build-system)
+     (list
+      #:modules
+      '((guix build gnu-build-system)
         (guix build utils)
         (ice-9 ftw)
         (ice-9 match))
-       #:test-target "test"
-       #:configure-flags
-       '("--threads") ;; TODO when we fix armhf, it doesn't support --threads
-       #:phases
-       (modify-phases %standard-phases
-         ;; put these where configure expects them to be
-         (add-after 'unpack 'unpack-nanopass+stex
-           (lambda* (#:key native-inputs inputs #:allow-other-keys)
-             (for-each (lambda (dep)
-                         (define src
-                           (assoc-ref (or native-inputs inputs) dep))
-                         (copy-recursively src dep
-                                           #:keep-mtime? #t))
-                       '("nanopass" "stex"))))
-         ;; NOTE: the custom Chez 'configure' script doesn't allow
-         ;; unrecognized flags, such as those automatically added
-         ;; by `gnu-build-system`.
-         (replace 'configure
-           (lambda* (#:key inputs outputs
-                           (configure-flags '())
-                           #:allow-other-keys)
-             (let* ((zlib-static (assoc-ref inputs "zlib:static"))
-                    (lz4-static (assoc-ref inputs "lz4:static"))
-                    (out (assoc-ref outputs "out"))
-                    ;; add flags which are always required:
-                    (flags (cons* (string-append "--installprefix=" out)
+      #:test-target "test"
+      ;; TODO when we fix armhf, it may not support --threads
+      #:configure-flags #~'("--threads")
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'unpack-nanopass+stex
+            (lambda args
+              #$(unpack-nanopass+stex)))
+          ;; NOTE: the custom Chez 'configure' script doesn't allow
+          ;; unrecognized flags, such as those automatically added
+          ;; by `gnu-build-system`.
+          (replace 'configure
+            (lambda* (#:key inputs (configure-flags '()) #:allow-other-keys)
+              ;; add flags which are always required:
+              (let ((flags (cons* (string-append "--installprefix=" #$output)
                                   "ZLIB=-lz"
                                   "LZ4=-llz4"
                                   "--libkernel"
@@ -305,90 +276,59 @@ (define src
                                   ;; and letting Chez try causes an error
                                   "--nogzip-man-pages"
                                   configure-flags)))
-               (format #t "configure flags: ~s~%" flags)
-               ;; Some makefiles (for tests) don't seem to propagate CC
-               ;; properly, so we take it out of their hands:
-               (setenv "CC" ,(cc-for-target))
-               (setenv "HOME" "/tmp")
-               (apply invoke
-                      "./configure"
-                      flags))))
-         ;; The binary file name is called "scheme" as is the one from MIT/GNU
-         ;; Scheme.  We add a symlink to use in case both are installed.
-         (add-after 'install 'install-symlink
-           (lambda* (#:key outputs #:allow-other-keys)
-             (let* ((out (assoc-ref outputs "out"))
-                    (bin (string-append out "/bin"))
-                    (lib (string-append out "/lib"))
-                    (name "chez-scheme"))
-               (symlink (string-append bin "/scheme")
-                        (string-append bin "/" name))
-               (map (lambda (file)
-                      (symlink file (string-append (dirname file)
-                                                   "/" name ".boot")))
-                    (find-files lib "scheme.boot")))))
-         ;; Building explicitly lets us avoid using substitute*
-         ;; to re-write makefiles.
-         (add-after 'install-symlink 'prepare-stex
-           (lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
-             (let* ((stex+version
-                     (strip-store-file-name
-                      (assoc-ref (or native-inputs inputs) "stex")))
-                    ;; Eventually we want to install stex as a real
-                    ;; package so it's reusable. For now:
-                    (stex-output "/tmp")
-                    (doc-dir (string-append stex-output
-                                            "/share/doc/"
-                                            stex+version)))
-               (with-directory-excursion "stex"
-                 (invoke "make"
-                         "install"
-                         (string-append "LIB="
-                                        stex-output
-                                        "/lib/"
-                                        stex+version)
-                         (string-append "Scheme="
-                                        (assoc-ref outputs "out")
-                                        "/bin/scheme"))
-                 (for-each (lambda (pth)
-                             (install-file pth doc-dir))
-                           '("ReadMe" ; includes the license
-                             "doc/stex.html"
-                             "doc/stex.css"
-                             "doc/stex.pdf"))))))
-         ;; Building the documentation requires stex and a running scheme.
-         ;; FIXME: this is probably wrong for cross-compilation
-         (add-after 'prepare-stex 'install-doc
-           (lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
-             (let* ((chez+version (strip-store-file-name
-                                   (assoc-ref outputs "out")))
-                    (stex+version
-                     (strip-store-file-name
-                      (assoc-ref (or native-inputs inputs) "stex")))
-                    (scheme (string-append (assoc-ref outputs "out")
-                                           "/bin/scheme"))
-                    ;; see note on stex-output in phase build-stex, above:
-                    (stexlib (string-append "/tmp"
-                                            "/lib/"
-                                            stex+version))
-                    (doc-dir (string-append (assoc-ref outputs "doc")
-                                            "/share/doc/"
-                                            chez+version)))
-               (define* (stex-make #:optional (suffix ""))
-                 (invoke "make"
-                         "install"
-                         (string-append "Scheme=" scheme)
-                         (string-append "STEXLIB=" stexlib)
-                         (string-append "installdir=" doc-dir suffix)))
-               (with-directory-excursion "csug"
-                 (stex-make "/csug"))
-               (with-directory-excursion "release_notes"
-                 (stex-make "/release_notes"))
-               (with-directory-excursion doc-dir
-                 (symlink "release_notes/release_notes.pdf"
-                          "release_notes.pdf")
-                 (symlink "csug/csug9_5.pdf"
-                          "csug.pdf"))))))))
+                (format #t "configure flags: ~s~%" flags)
+                ;; Some makefiles (for tests) don't seem to propagate CC
+                ;; properly, so we take it out of their hands:
+                (setenv "CC" #$(cc-for-target))
+                (setenv "HOME" "/tmp")
+                (apply invoke "./configure" flags))))
+          ;; The binary file name is called "scheme" as is the one from
+          ;; MIT/GNU Scheme.  We add a symlink to use in case both are
+          ;; installed.
+          (add-after 'install 'install-symlink
+            (lambda* (#:key outputs #:allow-other-keys)
+              (let* ((scheme (search-input-file outputs "/bin/scheme"))
+                     (bin-dir (dirname scheme)))
+                (symlink scheme
+                         (string-append bin-dir "/chez-scheme"))
+                (match (find-files (string-append bin-dir "/../lib")
+                                   "scheme.boot")
+                  ((scheme.boot)
+                   (symlink scheme.boot
+                            (string-append (dirname scheme.boot)
+                                           "/chez-scheme.boot")))))))
+          ;; Building the documentation requires stex and a running scheme.
+          ;; FIXME: this is probably wrong for cross-compilation
+          (add-after 'install-symlink 'install-doc
+            (lambda* (#:key native-inputs inputs outputs
+                            #:allow-other-keys)
+              (match (assoc-ref outputs "doc")
+                (#f
+                 (format #t "not installing docs~%"))
+                (doc-prefix
+                 (let* ((chez+version (strip-store-file-name #$output))
+                        (scheme (search-input-file outputs "/bin/scheme"))
+                        (stexlib (search-input-directory
+                                  (or native-inputs inputs)
+                                  "/lib/stex"))
+                        (doc-dir (string-append doc-prefix
+                                                "/share/doc/"
+                                                chez+version)))
+                   (define* (stex-make #:optional (suffix ""))
+                     (invoke "make" "install"
+                             (string-append "Scheme=" scheme)
+                             (string-append "STEXLIB=" stexlib)
+                             (string-append "installdir="
+                                            doc-dir suffix)))
+                   (with-directory-excursion "csug"
+                     (stex-make "/csug"))
+                   (with-directory-excursion "release_notes"
+                     (stex-make "/release_notes"))
+                   (with-directory-excursion doc-dir
+                     (symlink "release_notes/release_notes.pdf"
+                              "release_notes.pdf")
+                     (symlink "csug/csug9_5.pdf"
+                              "csug.pdf"))))))))))
     ;; Chez Scheme does not have a  MIPS backend.
     ;; FIXME: Debian backports patches to get armhf working.
     ;; We should too. It is the Chez machine type arm32le
@@ -412,3 +352,150 @@ (define* (stex-make #:optional (suffix ""))
 generates native code for each target processor, with support for x86, x86_64,
 and 32-bit PowerPC architectures.")
     (license license:asl2.0)))
+
+;;
+;; Chez's bootstrap dependencies:
+;;
+
+(define-public stex-bootstrap
+  ;; This commit includes a fix which we would otherwise want to use as
+  ;; patch.  Let's revert to tagged releases as soon as one becomes available.
+  (let ((commit "54051494434a197772bf6ca5b4e6cf6be55f39a5")
+        (revision "1"))
+    (hidden-package
+     (package
+       (name "stex")
+       ;; ^ Debian calls this "stex", not "chez-stex". It is a set of
+       ;; command-line tools, and there isn't a Scheme API, let alone a
+       ;; Chez-specific one, except perhaps that the Scheme examples are
+       ;; assumed to be Chez-compatible.
+       (version (git-version "1.2.2" revision commit))
+       (source
+        (origin
+          (method git-fetch)
+          (uri (git-reference
+                (url "https://github.com/dybvig/stex")
+                (commit commit)))
+          (sha256
+           (base32 "01jnvw8qw33gnpzwrakwhsr05h6b609lm180jnspcrb7lds2p23d"))
+          (file-name (git-file-name name version))
+          (snippet
+           #~(for-each delete-file
+                       '("sbin/install" "doc/stex.pdf" "doc/stex.html")))))
+       (outputs '("out"))
+       (build-system copy-build-system)
+       ;; N.B. Upstream does not seem to support cross-compilation,
+       ;; though it would probably be easy to add.
+       (propagated-inputs
+        (list xorg-rgb
+              (texlive-updmap.cfg
+               (list texlive-dvips-l3backend
+                     texlive-hyperref
+                     texlive-bibtex
+                     texlive-epsf
+                     texlive-fonts-ec
+                     texlive-oberdiek))
+              ghostscript
+              netpbm))
+       ;; Debian uses a versionless path for STEXLIB,
+       ;; which is much more convienient.
+       (arguments
+        (list
+         #:install-plan #~`(("inputs" "lib/stex/")
+                            ("gifs" "lib/stex/")
+                            ("math" "lib/stex/")
+                            ("src" "lib/stex/") ;; can run without compiling
+                            ("Mf-stex" "lib/stex/")
+                            ("Makefile.template" "lib/stex/"))
+         #:phases
+         #~(modify-phases %standard-phases
+             (add-before 'install 'patch-sources
+               (lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
+                 (define scheme
+                   (false-if-exception
+                    (search-input-file inputs "/bin/scheme")))
+                 (when scheme
+                   (setenv "Scheme" scheme))
+                 (substitute* '("Makefile.template"
+                                "doc/Makefile")
+                   (("STEXLIB=[^\n]*")
+                    (string-append "STEXLIB=" #$output "/lib/stex"))
+                   (("Scheme=[^\n]*")
+                    (string-append "Scheme=" (or scheme "scheme"))))
+                 (substitute* '("Mf-stex"
+                                "math/Makefile")
+                   (("/bin/rm")
+                    "rm"))
+                 (substitute* "Mf-stex"
+                   (("SHELL=bash")
+                    ;; avoid Solaris workaround
+                    "#SHELL=bash"))))
+             (add-after 'install 'maybe-compile
+               (lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
+                 (cond
+                  ((getenv "Scheme")
+                   => (lambda (scheme)
+                        (define makefile
+                          (string-append (getcwd) "/Makefile"))
+                        (define machine
+                          (let ((machine #$(nix-system->chez-machine
+                                            (or (%current-target-system)
+                                                (%current-system)))))
+                            (if (and (not (eqv? #\t (string-ref machine 0)))
+                                     (string-contains scheme "racket"))
+                                (string-append "t" machine)
+                                machine)))
+                        (with-directory-excursion
+                            (search-input-directory outputs "/lib/stex")
+                          (invoke "make"
+                                  "-f" makefile
+                                  (string-append "Scheme=" scheme))
+                          (for-each delete-file
+                                    (find-files machine
+                                                "\\.")))))
+                  (else
+                   (format #t "not compiling~%")))))
+             (add-after 'maybe-compile 'maybe-make-docs
+               (lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
+                 (cond
+                  ((assoc-ref outputs "doc")
+                   => (lambda (doc-prefix)
+                        (define doc-dir
+                          (string-append doc-prefix "/share/doc/stex"))
+                        ;; the Makefile is considered part of the documentation
+                        (copy-recursively "doc" doc-dir)
+                        (install-file "ReadMe" doc-dir)
+                        (with-directory-excursion "doc"
+                          (invoke "make")
+                          (install-file "stex.html" doc-dir)
+                          (install-file "stex.pdf" doc-dir))))
+                  (else
+                   (format #t "not making docs~%"))))))))
+       (home-page "https://github.com/dybvig/stex")
+       (synopsis "LaTeX with embeded Scheme code and HTML generation")
+       (description "The @code{stex} package extends LaTeX with a handful of
+commands for including Scheme code (or pretty much any other kind of code, as
+long as you don't plan to use the Scheme-specific transcript support) in a
+document.  It provides the programs @code{scheme-prep} and @code{html-prep} to
+convert @code{stex} documents to LaTeX and HTML, respectively, plus makefile
+templates, style files, and other resources.  The @code{stex} system is used
+to typeset @cite{The Scheme Programming Language} and the @cite{Chez Scheme
+User's Guix}, among other documents.")
+       (license license:expat)))))
+
+(define-public stex
+  (package/inherit stex-bootstrap
+    (inputs (modify-inputs (package-inputs stex-bootstrap)
+              (prepend chez-scheme)))
+    (outputs '("out" "doc"))
+    (properties '())))
+
+(define-public nanopass
+  (let ((version "1.9.2"))
+    (origin
+      (method git-fetch)
+      (uri (git-reference
+            (url "https://github.com/nanopass/nanopass-framework-scheme")
+            (commit (string-append "v" version))))
+      (sha256 (base32 "16vjsik9rrzbabbhbxbaha51ppi3f9n8rk59pc6zdyffs0vziy4i"))
+      (file-name (git-file-name "nanopass" version)))))
diff --git a/gnu/packages/racket.scm b/gnu/packages/racket.scm
index 865fdff70f..d8338bcd6f 100644
--- a/gnu/packages/racket.scm
+++ b/gnu/packages/racket.scm
@@ -333,9 +333,8 @@ (define-public racket-bootstrap-chez-bootfiles
       `(("racket" ,(if (%current-target-system)
                        racket-minimal
                        racket-minimal-bc-3m))
-        ("stex" ,@(assoc-ref (package-native-inputs chez-scheme) "stex"))
-        ("nanopass" ,@(assoc-ref (package-native-inputs chez-scheme)
-                                 "nanopass"))))
+        ("stex" ,(package-source stex))
+        ("nanopass" ,nanopass)))
      (arguments
       `(#:phases
         (modify-phases %standard-phases
-- 
2.32.0
P
P
Philip McGrath wrote on 8 Feb 16:18 +0100
[RFC PATCH 6/9] gnu: Add chez-nanopass.
(address . 53878@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
20220208151857.1900389-6-philip@philipmcgrath.com
* gnu/packages/chez-and-racket-bootstrap.scm (nanopass): Rename to ...
(chez-nanopass-bootstrap): ... this new variable, and promote it from an
origin to a package.
(chez-scheme)[native-inputs]: Add it.
(chez-nanopass): New variable.
(unpack-nanopass+stex): Adapt accordingly.
* gnu/packages/racket.scm
(racket-bootstrap-chez-bootfiles)[native-inputs]: Likewise.
---
gnu/packages/chez-and-racket-bootstrap.scm | 96 ++++++++++++++++++----
gnu/packages/racket.scm | 2 +-
2 files changed, 81 insertions(+), 17 deletions(-)

Toggle diff (141 lines)
diff --git a/gnu/packages/chez-and-racket-bootstrap.scm b/gnu/packages/chez-and-racket-bootstrap.scm
index c0d5e2897d..9125d34ab7 100644
--- a/gnu/packages/chez-and-racket-bootstrap.scm
+++ b/gnu/packages/chez-and-racket-bootstrap.scm
@@ -203,12 +203,13 @@ (define unbundle-chez-submodules
                 "lz4"
                 "zlib"))))
 
-(define (unpack-nanopass+stex)
-  ;; delayed resolution of `nanopass`
+(define unpack-nanopass+stex
   #~(begin
-      (copy-recursively #$nanopass
-                        "nanopass"
-                        #:keep-mtime? #t)
+      (copy-recursively
+       (dirname (search-input-file %build-inputs
+                                   "lib/chez-scheme/nanopass.ss"))
+       "nanopass"
+       #:keep-mtime? #t)
       (mkdir-p "stex")
       (with-output-to-file "stex/Mf-stex"
         (lambda ()
@@ -241,7 +242,7 @@ (define-public chez-scheme
       ;; for X11 clipboard support in expeditor:
       ;; https://github.com/cisco/ChezScheme/issues/9#issuecomment-222057232
       libx11))
-    (native-inputs (list stex-bootstrap))
+    (native-inputs (list chez-nanopass-bootstrap stex-bootstrap))
     (native-search-paths
      (list (search-path-specification
             (variable "CHEZSCHEMELIBDIRS")
@@ -261,7 +262,7 @@ (define-public chez-scheme
       #~(modify-phases %standard-phases
           (add-after 'unpack 'unpack-nanopass+stex
             (lambda args
-              #$(unpack-nanopass+stex)))
+              #$unpack-nanopass+stex))
           ;; NOTE: the custom Chez 'configure' script doesn't allow
           ;; unrecognized flags, such as those automatically added
           ;; by `gnu-build-system`.
@@ -490,12 +491,75 @@ (define-public stex
     (outputs '("out" "doc"))
     (properties '())))
 
-(define-public nanopass
-  (let ((version "1.9.2"))
-    (origin
-      (method git-fetch)
-      (uri (git-reference
-            (url "https://github.com/nanopass/nanopass-framework-scheme")
-            (commit (string-append "v" version))))
-      (sha256 (base32 "16vjsik9rrzbabbhbxbaha51ppi3f9n8rk59pc6zdyffs0vziy4i"))
-      (file-name (git-file-name "nanopass" version)))))
+(define-public chez-nanopass-bootstrap
+  (hidden-package
+   (package
+     (name "chez-nanopass")
+     (version "1.9.2")
+     (source
+      (origin
+        (method git-fetch)
+        (uri (git-reference
+              (url "https://github.com/nanopass/nanopass-framework-scheme")
+              (commit (string-append "v" version))))
+        (sha256 (base32 "16vjsik9rrzbabbhbxbaha51ppi3f9n8rk59pc6zdyffs0vziy4i"))
+        (file-name (git-file-name "nanopass-framework-scheme" version))
+        (snippet
+         #~(begin
+             (use-modules (guix build utils))
+             (when (file-exists? "doc/user-guide.pdf")
+               (delete-file "doc/user-guide.pdf"))
+             (substitute* "doc/Makefile"
+               (("include ~/stex/Mf-stex")
+                "include $(STEXLIB)/Mf-stex"))))))
+     (build-system copy-build-system)
+     (arguments
+      (list #:install-plan
+            #~`(("nanopass.ss" "lib/chez-scheme/")
+                ("nanopass" "lib/chez-scheme/"))))
+     (home-page "https://nanopass.org")
+     (synopsis "DSL for compiler development")
+     (description "The Nanopass framework is an embedded domain-specific
+language for writing compilers composed of several simple passes that
+operate over well-defined intermediate languages.  The goal of this
+organization is both to simplify the understanding of each pass, because it
+is responsible for a single task, and to simplify the addition of new passes
+anywhere in the compiler.  Nanopass reduces the boilerplate required to
+create compilers, making them easier to understand and maintain.")
+     (license license:expat))))
+
+(define-public chez-nanopass
+  (package/inherit chez-nanopass-bootstrap
+    (properties '())
+    ;; TODO: cross-compilation
+    (native-inputs (list chez-scheme stex))
+    (arguments
+     (substitute-keyword-arguments (package-arguments chez-nanopass-bootstrap)
+       ((#:install-plan base-plan)
+        #~`(("nanopass.so" "lib/chez-scheme/")
+            ("doc/user-guide.pdf" #$(string-append
+                                     "share/doc/"
+                                     (package-name this-package)
+                                     "-"
+                                     (package-version this-package)
+                                     "/"))
+            ,@#$base-plan))
+       ((#:phases base-phases #~%standard-phases)
+        #~(modify-phases #$base-phases
+            (add-before 'install 'compile-and-test
+              (lambda args
+                (invoke "scheme"
+                        "--compile-imported-libraries"
+                        "--program" "test-all.ss")))
+            (add-after 'compile-and-test 'build-doc
+              (lambda* (#:key native-inputs inputs #:allow-other-keys)
+                (with-directory-excursion "doc"
+                  (invoke "make"
+                          (string-append "Scheme="
+                                         (search-input-file
+                                          (or native-inputs inputs)
+                                          "/bin/scheme"))
+                          (string-append "STEXLIB="
+                                         (search-input-directory
+                                          (or native-inputs inputs)
+                                          "/lib/stex"))))))))))))
diff --git a/gnu/packages/racket.scm b/gnu/packages/racket.scm
index d8338bcd6f..e8d016c07b 100644
--- a/gnu/packages/racket.scm
+++ b/gnu/packages/racket.scm
@@ -334,7 +334,7 @@ (define-public racket-bootstrap-chez-bootfiles
                        racket-minimal
                        racket-minimal-bc-3m))
         ("stex" ,(package-source stex))
-        ("nanopass" ,nanopass)))
+        ("nanopass" ,(package-source chez-nanopass))))
      (arguments
       `(#:phases
         (modify-phases %standard-phases
-- 
2.32.0
P
P
Philip McGrath wrote on 8 Feb 16:18 +0100
[RFC PATCH 7/9] gnu: chez-scheme: Explicitly package bootstrap bootfiles.
(address . 53878@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
20220208151857.1900389-7-philip@philipmcgrath.com
This might seem a bit silly in isolation, but it makes the structure of
the upstream Chez Scheme package the same as for the Racket variant, it
sets things up for (one day, hopefully) actually being able to bootstrap
the upstream Chez Scheme bootfiles, and it may be useful for
cross-compilation and adding support for architectures without pre-built
bootfiles from upstream.

* gnu/packages/chez-and-racket-bootstrap.scm
(chez-scheme-bootstrap-bootfiles): New variable.
(chez-scheme)[native-inputs]: Add it.
[arguments]: Add new phase 'unpack-bootfiles'.
[version, source, home-page]: Derive from 'chez-scheme-bootstrap-bootfiles'.
---
gnu/packages/chez-and-racket-bootstrap.scm | 57 ++++++++++++++++++++--
1 file changed, 52 insertions(+), 5 deletions(-)

Toggle diff (100 lines)
diff --git a/gnu/packages/chez-and-racket-bootstrap.scm b/gnu/packages/chez-and-racket-bootstrap.scm
index 9125d34ab7..c6e4e07085 100644
--- a/gnu/packages/chez-and-racket-bootstrap.scm
+++ b/gnu/packages/chez-and-racket-bootstrap.scm
@@ -216,9 +216,9 @@ (define unpack-nanopass+stex
           ;; otherwise, it will try to download submodules
           (display "# to placate ../configure")))))
 
-(define-public chez-scheme
+(define-public chez-scheme-bootstrap-bootfiles
   (package
-    (name "chez-scheme")
+    (name "chez-scheme-bootstrap-bootfiles")
     ;; The version should match `(scheme-version-number)`.
     ;; See s/cmacros.ss c. line 360.
     (version "9.5.6")
@@ -230,8 +230,45 @@ (define-public chez-scheme
               (sha256
                (base32
                 "07s433hn1z2slfc026sidrpzxv3a8narcd40qqr1xrpb9012xdky"))
-              (file-name (git-file-name name version))
+              (file-name (git-file-name "chez-scheme" version))
               (snippet unbundle-chez-submodules)))
+    (build-system copy-build-system)
+    ;; TODO: cross compilation
+    (arguments
+     (list #:install-plan
+           #~`(("boot/" "lib/chez-scheme-bootfiles"))))
+    (supported-systems
+     ;; Upstream only distributes pre-built bootfiles for
+     ;; arm32le and t?(i3|a6)(le|nt|osx)
+     (filter (lambda (system)
+               (let ((mach (nix-system->chez-machine system #:threads? #f)))
+                 (or (equal? "arm32le" mach)
+                     (and mach
+                          (member (substring mach 0 2) '("i3" "a6"))
+                          (or-map (cut string-suffix? <> mach)
+                                  '("le" "nt" "osx"))))))
+             %supported-systems))
+    (home-page "https://cisco.github.io/ChezScheme/")
+    (synopsis "Chez Scheme bootfiles (binary seed)")
+    (description
+     "Chez Scheme is a self-hosting compiler: building it requires
+``bootfiles'' containing the Scheme-implemented portions compiled for the
+current platform.  (Chez can then cross-compile bootfiles for all other
+supported platforms.)
+
+This package provides bootstrap bootfiles for upstream Chez Scheme.
+Currently, it simply packages the binaries checked in to the upsream
+repository.  Hopefully we can eventually adapt Racket's @code{cs-bootstrap} to
+work with upstream Chez Scheme so that we can bootstrap these files from
+source.")
+    (properties `((hidden? . #t)))
+    (license license:asl2.0)))
+
+(define-public chez-scheme
+  (package
+    (name "chez-scheme")
+    (version (package-version chez-scheme-bootstrap-bootfiles))
+    (source (package-source chez-scheme-bootstrap-bootfiles))
     (build-system gnu-build-system)
     (inputs
      (list
@@ -242,7 +279,9 @@ (define-public chez-scheme
       ;; for X11 clipboard support in expeditor:
       ;; https://github.com/cisco/ChezScheme/issues/9#issuecomment-222057232
       libx11))
-    (native-inputs (list chez-nanopass-bootstrap stex-bootstrap))
+    (native-inputs (list chez-scheme-bootstrap-bootfiles
+                         chez-nanopass-bootstrap
+                         stex-bootstrap))
     (native-search-paths
      (list (search-path-specification
             (variable "CHEZSCHEMELIBDIRS")
@@ -263,6 +302,14 @@ (define-public chez-scheme
           (add-after 'unpack 'unpack-nanopass+stex
             (lambda args
               #$unpack-nanopass+stex))
+          (add-after 'unpack-nanopass+stex 'unpack-bootfiles
+            (lambda* (#:key native-inputs inputs #:allow-other-keys)
+              (when (directory-exists? "boot")
+                (delete-file-recursively "boot"))
+              (copy-recursively
+               (search-input-directory (or native-inputs inputs)
+                                       "lib/chez-scheme-bootfiles")
+               "boot")))
           ;; NOTE: the custom Chez 'configure' script doesn't allow
           ;; unrecognized flags, such as those automatically added
           ;; by `gnu-build-system`.
@@ -345,7 +392,7 @@ (define* (stex-make #:optional (suffix ""))
                   (not (eq? 'no-support
                             (chez-machine->upstream-restriction mach))))))
        %supported-systems)))
-    (home-page "https://cisco.github.io/ChezScheme/")
+    (home-page (package-home-page chez-scheme-bootstrap-bootfiles))
     (synopsis "R6RS Scheme compiler and run-time")
     (description
      "Chez Scheme is a compiler and run-time system for the language of the
-- 
2.32.0
P
P
Philip McGrath wrote on 8 Feb 16:18 +0100
[RFC PATCH 8/9] gnu: Add chez-scheme-racket-variant.
(address . 53878@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
20220208151857.1900389-8-philip@philipmcgrath.com
The Racket variant of Chez Scheme can be used to support platforms that
are not yet supported by upstream Chez Scheme. The new function
'chez-scheme-for-system' selects the Chez Scheme package that best
supports the target system.

In the process, we also add packages for 'racket-vm-cgc',
'racket-vm-bc', and 'racket-vm-cs'. A future commit will change
'racket-minimal' to use the Racket VM implementation that best supports
the target system, as reported by 'racket-vm-for-system'.

* gnu/packages/patches/racket-enable-scheme-backport.patch: New patch.
* gnu/local.mk (dist_patch_DATA): Add it.
* gnu/packages/chez-and-racket-bootstrap.scm (racket-vm-cgc):
(racket-vm-bc):
(racket-vm-cs):
(chez-scheme-racket-variant-bootstrap-bootfiles):
(chez-scheme-racket-variant): New variables.
(chez-scheme-for-system, racket-vm-for-system): New exported functions.
* gnu/packages/loko.scm (loko-scheme): Use 'chez-scheme-for-system'.
* gnu/packages/emacs-xyz.scm (emacs-geiser-chez): Likewise
* gnu/packages/chez.scm (chez-srfi):
(chez-web):
(chez-sockets):
(chez-matchable):
(chez-irregex):
(chez-fmt):
(chez-mit):
(chez-scmutils): Likewise.
(chez-mit)[origin]<snippet>: Add workaround for Racket variant.
---
gnu/local.mk | 1 +
gnu/packages/chez-and-racket-bootstrap.scm | 512 +++++++++++++++++-
gnu/packages/chez.scm | 40 +-
gnu/packages/emacs-xyz.scm | 2 +-
gnu/packages/loko.scm | 2 +-
.../racket-enable-scheme-backport.patch | 465 ++++++++++++++++
6 files changed, 1003 insertions(+), 19 deletions(-)
create mode 100644 gnu/packages/patches/racket-enable-scheme-backport.patch

Toggle diff (1182 lines)
diff --git a/gnu/local.mk b/gnu/local.mk
index e3104fc0b6..94de782ca9 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1785,6 +1785,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/ripperx-missing-file.patch		\
   %D%/packages/patches/rpcbind-CVE-2017-8779.patch		\
   %D%/packages/patches/rtags-separate-rct.patch			\
+  %D%/packages/patches/racket-enable-scheme-backport.patch	\
   %D%/packages/patches/racket-minimal-sh-via-rktio.patch	\
   %D%/packages/patches/remake-impure-dirs.patch			\
   %D%/packages/patches/restic-0.9.6-fix-tests-for-go1.15.patch	\
diff --git a/gnu/packages/chez-and-racket-bootstrap.scm b/gnu/packages/chez-and-racket-bootstrap.scm
index c6e4e07085..46da8e3ef2 100644
--- a/gnu/packages/chez-and-racket-bootstrap.scm
+++ b/gnu/packages/chez-and-racket-bootstrap.scm
@@ -34,15 +34,20 @@ (define-module (gnu packages chez-and-racket-bootstrap)
   #:use-module (guix build-system copy)
   #:use-module (guix build-system gnu)
   #:use-module (gnu packages)
+  #:use-module (gnu packages autotools)
+  #:use-module (gnu packages bash)
   #:use-module (gnu packages compression)
   #:use-module (gnu packages ghostscript)
+  #:use-module (gnu packages libffi)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages ncurses)
   #:use-module (gnu packages netpbm)
   #:use-module (gnu packages tex)
   #:use-module (gnu packages xorg)
   #:use-module ((guix licenses)
-                #:prefix license:))
+                #:prefix license:)
+  #:export (chez-scheme-for-system
+            racket-vm-for-system))
 
 ;; Commentary:
 ;;
@@ -62,8 +67,164 @@ (define-module (gnu packages chez-and-racket-bootstrap)
 ;; Putting the relevant definitions together in this module avoids having to
 ;; work around dependency cycles.
 ;;
+;; Anatomy of Racket:
+;; ------------------
+;;
+;; The main Racket Git repository (<https://github.com/racket/racket>) is
+;; organized broadly like this:
+;;
+;;     .
+;;     ├── Makefile
+;;     ├── pkgs/
+;;     └── racket/
+;;         ├── collects/
+;;         └── src/
+;;             ├── configure
+;;             ├── Makefile.in
+;;             ├── bc/
+;;             ├── cs/
+;;             ├── ChezScheme/
+;;             └── ...
+;;
+;; The 'racket/src/' directory contains the source of the runtime system, core
+;; compiler, and primitives for the major Racket implementations: this layer
+;; is called the ``Racket VM''. It is basically a normal autotools
+;; project. (Even when Racket VM implementations use components implemented in
+;; Racket, they are compiled in special modes to produce VM primitives.)
+;; (There are or have been experimental Racket VM implementations elsewhere,
+;; e.g. <https://github.com/pycket/pycket>.) One way of thinking about the
+;; bounary between the Racket VM and Racket programs is that the VM implements
+;; the primitives accessed by the 'ffi/unsafe/vm' library. Another perspective
+;; is that DrRacket's ``Open defining file''/``Jump to definition'' features
+;; can navigate into Racket programs, including into the implementation of
+;; 'racket/base', but can not jump into the implementation of the Racket VM
+;; itself. A third, related perspective is that Racket code is usually
+;; installed with source files alongside compiled code (though this is not
+;; mandatory), whereas the Racket VM is installed only in compiled form.
+;;
+;; The 'racket/collects/' directory contains ``built in'' Racket libraries
+;; that are not part of any package, including the implementation of
+;; 'racket/base': in particular, it must contain enough to implement `raco pkg
+;; install'. It is theoretically possible to use the Racket VM layer without
+;; the main collections, but it is not stable or useful.
+;;
+;; The 'pkgs/' directory contains Racket packages that are especially closely
+;; tied to the implementation of the Racket VM, including 'compiler-lib',
+;; 'racket-doc', and 'racket-test'. Some of these packages depend on Racket
+;; packages that are developed in other Git repositories, predominantly but
+;; not exclusively under the 'racket' GitHub organization. Conversely, not all
+;; of the packages developed in the main Git repository are part of the main
+;; Racket distribution.  (Additionally, components of the Racket VM that are
+;; implemented in Racket can be installed as packages, mostly for ease of
+;; development.)
+;;
+;; The top-level 'Makefile' is more like a directory of scripts: it has
+;; convienience targets for developing Racket, and it cooperates with the
+;; 'distro-build' package to assemble custom Racket distributions. It is not
+;; part of Racket source distributions: the root of a source distribution is
+;; basically 'racket/src' with some extra package sources and configuration
+;; added.
+;;
+;; A ''minimal Racket'' installation includes two packages: 'base', which is a
+;; sort of bridge between the current ``built-in'' collections and the package
+;; system's model of dependencies, and 'racket-lib', which, for installations
+;; that can not rely on a system package manager, pulls in the SQLite and
+;; OpenSSL shared libraries as platform-specific dependencies for use by the
+;; ``built-in'' collections.
+;;
+;; The main Racket distribution consists of installing the 'main-distribution'
+;; package and all of its dependencies.
+;;
+;; The default mode when building Racket (or installing it with the released
+;; installers) is an ``in-place build'', which produces a self-contained,
+;; relocatable, roughly FHS-like directory. (Racket also supports
+;; ``Unix-style'' installations, which rearrange the parts of an in-place
+;; build into Racket-specific subdirectories and generally tries to work for
+;; installation into an FHS-based system.) Certain tools, e.g. 'distro-build'
+;; and 'raco cross', are able to work with an in-place Racket build.
+;;
+;; This file defines the packages 'racket-vm-cgc', 'racket-vm-bc', and
+;; 'racket-vm-cs'. All three are in-place builds of 'racket/src/' and
+;; 'racket/collects/' and are installed to 'opt/racket-vm/' in the store
+;; output. The function 'racket-vm-for-system' returns the recomended Racket
+;; VM package for a given system.
+;;
+;; The file 'racket.scm' builds on these packages to define 'racket-minimal'
+;; and 'racket' packages. These use Racket's support for ``layered
+;; installations'', which allow an immutable base layer to be extended with
+;; additional packages. The use the layer configuration directly provide
+;; ready-to-install FHS-like trees, rather than relying on the built in
+;; ``Unix-style install'' mechanism.
+;;
+;; Bootstrapping Racket:
+;; ---------------------
+;;
+;; Here's how bootstrapping Racket works:
+;;
+;;   - Racket BC [CGC] can be built with only a C compiler (except for
+;;     one caveat discussed below).
+;;   - Racket BC [3M] needs an existing Racket to run "xform",
+;;     which transforms its own C source code to add additional annotations
+;;     for the precise garbage collector.
+;;   - Racket CS needs (bootfiles for) Racket's fork of Chez Scheme.
+;;     It also needs an existing Racket to compile Racket-implemented
+;;     parts of the runtime system to R6RS libraries.
+;;   - Chez Scheme also needs bootfiles for itself, but Racket can simulate
+;;     enough of Chez Scheme to load Racket's fork of the Chez Scheme compiler
+;;     purely from source into Racket and apply the compiler to itself,
+;;     producing the needed bootfiles (albeit very slowly).
+;;     Any variant of Racket since version 7.1 can run the simulation.
+;;
+;; So, we build CGC to build 3M to build bootfiles and CS.
+;;
+;; (Note: since the CGC variant is basically only for bootstrapping, we
+;; often use "BC" to mean "3M", consistent with `(banner)` and the
+;; suffixes used on executables when more than one variant co-exists.)
+;;
+;; One remaining bootstrapping limitation is that Racket's reader, module
+;; system, and macro expander are implemented in Racket. For Racket CS,
+;; they are compiled to R6RS libraries as discussed above. This note from the
+;; README file applies to all such subsystems:
+;;
+;;     The Racket version must be practically the same as the current Racket
+;;     verson, although it can be the Racket BC implementation (instead of
+;;     the Racket CS implementation).
+;;
+;;     Unlike Chez Scheme boot files, the files generated in "schemified"
+;;     are human-readable and -editable Scheme code. That provides a way
+;;     out of bootstrapping black holes, even without BC.
+;;
+;; However, other Racket subsystems implemented in Racket for Racket CS
+;; use older C implementations for Racket BC, whereas the reader, expander,
+;; and module system were completely replaced with the Racket implementation
+;;
+;; For Racket BC, the compiled "linklet" s-expressions (primitive modules)
+;; are embeded in C as a static string constant. Eventually, they are further
+;; compiled by the C-implemented Racket BC bytecode and JIT compilers.
+;; (On platforms where Racket BC's JIT is not supported, yet another compiler
+;; instead compiles the linklets to C code, but this is not a bootstrapping
+;; issue.)
+;;
 ;; Code:
 
+(define* (chez-scheme-for-system #:optional
+                                 (system (or (%current-target-system)
+                                             (%current-system))))
+  "Return 'chez-scheme' if it supports SYSTEM without restrictions;
+'chez-scheme-racket-variant' otherwise."
+  (if (and=> (nix-system->chez-machine system)
+             chez-machine->upstream-restriction)
+      chez-scheme-racket-variant
+      chez-scheme))
+
+(define* (racket-vm-for-system #:optional
+                               (system (or (%current-target-system)
+                                           (%current-system))))
+  "Return 'racket-vm-cs' if it supports SYSTEM; 'racket-vm-bc' otherwise."
+  (if (nix-system->chez-machine system)
+      racket-vm-cs
+      racket-vm-bc))
+
 (define (chez-machine->unthreaded mach)
   "Given a string MACH naming a Chez Scheme machine type, returns a string
 naming the unthreaded machine type for the same architecture and OS as MACH.
@@ -189,19 +350,19 @@ (define* (nix-system->chez-machine #:optional (system (%current-system))
                 (chez-machine->threaded mach)))))))
 
 ;;
-;; Chez Scheme:
+;; Chez auxiliary G-expressions:
 ;;
 
 (define unbundle-chez-submodules
   #~(begin
       (use-modules (guix build utils))
       (for-each (lambda (dir)
-                (when (directory-exists? dir)
-                  (delete-file-recursively dir)))
-              '("stex"
-                "nanopass"
-                "lz4"
-                "zlib"))))
+                  (when (directory-exists? dir)
+                    (delete-file-recursively dir)))
+                '("stex"
+                  "nanopass"
+                  "lz4"
+                  "zlib"))))
 
 (define unpack-nanopass+stex
   #~(begin
@@ -216,6 +377,235 @@ (define unpack-nanopass+stex
           ;; otherwise, it will try to download submodules
           (display "# to placate ../configure")))))
 
+;;
+;; Racket VM:
+;;
+
+(define (racket-vm-common-configure-flags)
+  ;; under a lambda extraction to avoid evaluating bash-minimal too early
+  #~`(,@(cond
+         ((false-if-exception
+           (search-input-file %build-inputs "/bin/libtool"))
+          => (lambda (libtool)
+               (list (string-append "--enable-lt=" libtool))))
+         (else
+          '()))
+      ,@(cond
+         ((false-if-exception
+           (search-input-file %build-inputs "/opt/racket-vm/bin/racket"))
+          => (lambda (racket)
+               (list (string-append "--enable-racket=" racket))))
+         (else
+          '()))
+      ,(string-append "CPPFLAGS=-DGUIX_RKTIO_PATCH_BIN_SH="
+                      #$(file-append bash-minimal "/bin/sh"))
+      "--disable-strip"
+      "--enable-origtree"))
+
+(define-public racket-vm-cgc
+  ;; Eventually, it may make sense for some vm packages to not be hidden,
+  ;; but this one is especially likely to remain hidden.
+  (hidden-package
+   (package
+     (name "racket-vm-cgc")
+     (version "8.3.900")
+     ;; ^ Remember to also update the version of
+     ;;   chez-scheme-racket-variant-bootstrap-bootfiles
+     (source
+      (origin
+        (method git-fetch)
+        (uri (git-reference
+              (url "https://github.com/racket/racket")
+              ;;(commit (string-append "v" version))))
+              (commit "a8f2969753f70e70d73308250cae1d4eda087319")))
+        (sha256
+         (base32 "141c18wmvb6039cw87mvmm6xxs6k01wkcrxj0hfa1r8za25qa934"))
+        (file-name (git-file-name "racket" version))
+        (patches (search-patches "racket-minimal-sh-via-rktio.patch"
+                                 ;; Remove by Racket 8.5:
+                                 "racket-enable-scheme-backport.patch"))
+        (modules '((guix build utils)))
+        (snippet
+         #~(begin
+             ;; Unbundle Chez submodules.
+             (with-directory-excursion "racket/src/ChezScheme"
+               #$unbundle-chez-submodules)
+             ;; Unbundle libffi.
+             (delete-file-recursively "racket/src/bc/foreign/libffi")))))
+     (inputs (list ncurses ;; <- common to all variants (for #%terminal)
+                   bash-minimal ;; <- common to all variants (for `system`)
+                   libffi)) ;; <- only for BC variants
+     (native-inputs (list libtool)) ;; <- only for BC variants
+     (outputs '("out" "debug"))
+     (build-system gnu-build-system)
+     (arguments
+      (list
+       #:configure-flags
+       #~(cons "--enable-cgcdefault"
+               #$(racket-vm-common-configure-flags))
+       ;; Tests are in packages like racket-test-core and
+       ;; main-distribution-test that aren't part of the main
+       ;; distribution.
+       #:tests? #f
+       ;; Upstream recommends #:out-of-source?, and it does
+       ;; help with debugging, but it confuses `install-license-files`.
+       #:modules '((ice-9 match)
+                   (ice-9 regex)
+                   (guix build gnu-build-system)
+                   (guix build utils))
+       #:strip-directories #~'("opt/racket-vm/bin"
+                               "opt/racket-vm/lib")
+       #:phases
+       #~(let ()
+           (define* ((wrap-racket-vm-outputs phase) . args)
+             (apply
+              phase
+              (let loop ((args args))
+                (match args
+                  ((#:outputs outputs . args)
+                   `(#:outputs
+                     ,(let loop ((outputs outputs))
+                        (match outputs
+                          ((("out" . out) . outputs)
+                           `(("out" . ,(string-append out "/opt/racket-vm/"))
+                             ,@outputs))
+                          ((other . outputs)
+                           (cons other (loop outputs)))))
+                     ,@args))
+                  ((arg . args)
+                   (cons arg (loop args)))))))
+           (modify-phases %standard-phases
+             (add-before 'configure 'initialize-config.rktd
+               (lambda* (#:key inputs #:allow-other-keys)
+                 (define (write-racket-hash alist)
+                   ;; inside must use dotted pair notation
+                   (display "#hash(")
+                   (for-each (match-lambda
+                               ((k . v)
+                                (format #t "(~s . ~s)" k v)))
+                             alist)
+                   (display ")\n"))
+                 (define maybe-release-catalog
+                   (let ((v #$(package-version this-package)))
+                     (if (string-match "^[0-9]+\\.[0-9]+($|\\.[0-8][0-9]*$)"
+                                       v)
+                         `(,(string-append
+                             "https://download.racket-lang.org/releases/"
+                             v
+                             "/catalog/"))
+                         '())))
+                 (mkdir-p "racket/etc")
+                 (with-output-to-file "racket/etc/config.rktd"
+                   (lambda ()
+                     (write-racket-hash
+                      `((build-stamp . "")
+                        (catalogs ,@maybe-release-catalog
+                                  #f)))))))
+             (add-before 'configure 'chdir
+               (lambda _
+                 (chdir "racket/src")))
+             (replace 'configure
+               (wrap-racket-vm-outputs
+                (assoc-ref %standard-phases 'configure)))
+             (replace 'patch-shebangs
+               (wrap-racket-vm-outputs
+                (assoc-ref %standard-phases 'patch-shebangs)))
+             (replace 'validate-runpath
+               (wrap-racket-vm-outputs
+                (assoc-ref %standard-phases 'validate-runpath)))
+             (replace 'make-dynamic-linker-cache
+               (wrap-racket-vm-outputs
+                (assoc-ref %standard-phases 'make-dynamic-linker-cache)))
+             (replace 'patch-dot-desktop-files
+               (wrap-racket-vm-outputs
+                (assoc-ref %standard-phases 'patch-dot-desktop-files)))))))
+     (home-page "https://racket-lang.org")
+     (synopsis "Old Racket implementation used for bootstrapping")
+     (description "This variant of the Racket BC (``before Chez'' or
+``bytecode'') implementation is not recommended for general use.  It uses
+CGC (a ``Conservative Garbage Collector''), which was succeeded as default in
+PLT Scheme version 370 (which translates to 3.7 in the current versioning
+scheme) by the 3M variant, which in turn was succeeded in version 8.0 by the
+Racket CS implementation.
+
+Racket CGC is primarily used for bootstrapping Racket BC [3M].  It may
+also be used for embedding applications without the annotations needed in C
+code to use the 3M garbage collector.")
+     ;; https://download.racket-lang.org/license.html
+     ;; The LGPL components are only used by Racket BC.
+     (license (list license:lgpl3+ license:asl2.0 license:expat)))))
+
+(define-public racket-vm-bc
+  (package
+    (inherit racket-vm-cgc)
+    (name "racket-vm-bc")
+    (native-inputs
+     (modify-inputs (package-native-inputs racket-vm-cgc)
+       (prepend racket-vm-cgc)))
+    (arguments
+     (substitute-keyword-arguments (package-arguments racket-vm-cgc)
+       ((#:configure-flags _ '())
+        #~(cons "--enable-bconly"
+                #$(racket-vm-common-configure-flags)))))
+    (synopsis "Racket BC [3M] implementation")
+    (description "The Racket BC (``before Chez'' or ``bytecode'')
+implementation was the default before Racket 8.0.  It uses a compiler written
+in C targeting architecture-independent bytecode, plus a JIT compiler on most
+platforms.  Racket BC has a different C API and supports a slightly different
+set of architectures than the current default runtime system, Racket CS (based
+on ``Chez Scheme'').  It is the recommended implementation for architectures
+that Racket CS doesn't support.
+
+This package is the normal implementation of Racket BC with a precise garbage
+collector, 3M (``Moving Memory Manager'').")))
+
+(define-public racket-vm-cs
+  (package
+    (inherit racket-vm-bc)
+    (name "racket-vm-cs")
+    (inputs
+     (modify-inputs (package-inputs racket-vm-cgc)
+       (prepend zlib lz4)
+       (delete "libffi")))
+    (native-inputs
+     (modify-inputs (package-native-inputs racket-vm-cgc)
+       (delete "libtool")
+       (prepend chez-scheme-racket-variant
+                chez-nanopass-bootstrap
+                racket-vm-bc)))
+    (arguments
+     (substitute-keyword-arguments (package-arguments racket-vm-cgc)
+       ((#:phases those-phases #~%standard-phases)
+        #~(modify-phases #$those-phases
+            (add-after 'unpack 'unpack-nanopass+stex
+              (lambda args
+                (with-directory-excursion "racket/src/ChezScheme"
+                  #$unpack-nanopass+stex)))))
+       ((#:configure-flags _ '())
+        #~(cons* "--enable-csonly"
+                 "--enable-libz"
+                 "--enable-lz4"
+                 (string-append "--enable-scheme="
+                                #$(this-package-native-input
+                                   "chez-scheme-racket-variant")
+                                "/bin/scheme")
+                 #$(racket-vm-common-configure-flags)))))
+    (synopsis "Racket CS implementation")
+    (description "The Racket CS implementation, which uses ``Chez Scheme'' as
+its core compiler and runtime system, has been the default Racket VM
+implemetation since Racket 8.0.  It performs better than the Racket BC
+implementation for most programs.
+
+Using the Racket VM packages directly is not recommended: instead, install the
+@code{racket-minimal} or @code{racket} packages.")
+    ;; https://download.racket-lang.org/license.html
+    ;; The LGPL components are only used by Racket BC.
+    (license (list license:asl2.0 license:expat))))
+
+;;
+;; Chez Scheme:
+;;
+
 (define-public chez-scheme-bootstrap-bootfiles
   (package
     (name "chez-scheme-bootstrap-bootfiles")
@@ -401,6 +791,112 @@ (define* (stex-make #:optional (suffix ""))
 and 32-bit PowerPC architectures.")
     (license license:asl2.0)))
 
+
+(define-public chez-scheme-racket-variant-bootstrap-bootfiles
+  (package
+    (inherit chez-scheme-bootstrap-bootfiles)
+    (name "chez-scheme-racket-variant-bootstrap-bootfiles")
+    (version "9.5.7.3")
+    ;; The version should match `(scheme-fork-version-number)`.
+    ;; See racket/src/ChezScheme/s/cmacros.ss c. line 360.
+    ;; It will always be different than the upstream version!
+    (source (package-source racket-vm-cgc))
+    (native-inputs (list chez-nanopass-bootstrap racket-vm-bc))
+    (arguments
+     (substitute-keyword-arguments
+         (package-arguments chez-scheme-bootstrap-bootfiles)
+       ((#:phases those-phases #~%standard-phases)
+        #~(modify-phases #$those-phases
+            (add-after 'unpack 'chdir
+              (lambda args
+                (chdir "racket/src/ChezScheme")))
+            (add-after 'chdir 'unpack-nanopass+stex
+              (lambda args
+                #$unpack-nanopass+stex))
+            (add-before 'install 'build
+              (lambda* (#:key native-inputs inputs #:allow-other-keys)
+                (invoke (search-input-file (or native-inputs inputs)
+                                           "/opt/racket-vm/bin/racket")
+                        "rktboot/main.rkt")))))))
+    (home-page "https://github.com/racket/ChezScheme")
+    ;; ^ This is downstream of https://github.com/racket/racket,
+    ;; but it's designed to be a friendly landing place for people
+    ;; who want a ChezScheme-shaped repositroy.
+    (synopsis "Chez Scheme bootfiles bootstrapped by Racket")
+    (description "Chez Scheme is a self-hosting compiler: building it
+requires ``bootfiles'' containing the Scheme-implemented portions compiled for
+the current platform.  (Chez can then cross-compile bootfiles for all other
+supported platforms.)
+
+The Racket package @code{cs-bootstrap} (part of the main Racket Git
+repository) implements enough of a Chez Scheme simulation to load the Chez
+Scheme compiler purely from source into Racket and apply the compiler to
+itself, thus bootstrapping Chez Scheme.  Bootstrapping takes about 10 times as
+long as using an existing Chez Scheme, but @code{cs-bootstrap} supports Racket
+7.1 and later, including the Racket BC variant.
+
+Note that the generated bootfiles are specific to Racket's fork of Chez
+Scheme, and @code{cs-bootstrap} does not currently support building upstream
+Chez Scheme.")
+    (properties `())
+    (license license:asl2.0)))
+
+(define-public chez-scheme-racket-variant
+  (package
+    (inherit chez-scheme)
+    (name "chez-scheme-racket-variant")
+    (version (package-version chez-scheme-racket-variant-bootstrap-bootfiles))
+    (source (package-source racket-vm-cgc))
+    (inputs
+     (modify-inputs (package-inputs chez-scheme)
+       (delete "libx11" "util-linux:lib")))
+    (native-inputs
+     (modify-inputs (package-native-inputs chez-scheme)
+       (replace "chez-scheme-bootstrap-bootfiles"
+         chez-scheme-racket-variant-bootstrap-bootfiles)))
+    (arguments
+     (substitute-keyword-arguments (package-arguments chez-scheme)
+       ((#:configure-flags cfg-flags #~'())
+        #~(cons "--disable-x11" #$cfg-flags))
+       ((#:phases those-phases #~%standard-phases)
+        #~(modify-phases #$those-phases
+            (add-after 'unpack 'chdir
+              (lambda args
+                (chdir "racket/src/ChezScheme")))))))
+    (supported-systems (filter nix-system->chez-machine
+                               %supported-systems))
+    (home-page
+     (package-home-page chez-scheme-racket-variant-bootstrap-bootfiles))
+    (synopsis "Variant of Chez Scheme extended for Racket")
+    (description "This variant of Chez Scheme is extended to support the
+implementation of Racket.  It may be useful on platforms that are not yet
+supported by upstream Chez Scheme.
+
+Main additions to Chez Scheme in the Racket variant:
+@itemize @bullet
+@item
+AArch64 support
+@item
+Portable bytes (@code{pb}) support, which is mainly useful for bootstrapping
+a build on any supported platform
+@item
+Unboxed floating-point arithmetic and flvectors
+@item
+Type reconstruction during optimization (especially for safe code)
+@item
+Continuation attachments
+@item
+Parallel garbage collection, in-place garbage collection for old-generation
+objects (instead of always copying), and reachability-based memory
+accounting
+@item
+Ordered finalization, immobile (but collectable) objects, weak/ephemeron
+generic hash tables, and reference bytevectors
+@item
+Faster multiplication and division for large exact numbers
+@end itemize")
+    (license license:asl2.0)))
+
 ;;
 ;; Chez's bootstrap dependencies:
 ;;
diff --git a/gnu/packages/chez.scm b/gnu/packages/chez.scm
index 54bbee7923..aa8c305d72 100644
--- a/gnu/packages/chez.scm
+++ b/gnu/packages/chez.scm
@@ -74,7 +74,7 @@ (define-public chez-srfi
        (file-name (git-file-name name version))))
     (build-system gnu-build-system)
     (native-inputs
-     (list chez-scheme))
+     (list (chez-scheme-for-system)))
     (arguments
      (list #:make-flags (chez-make-flags name version)
            #:test-target "test"
@@ -105,7 +105,7 @@ (define-public chez-web
           (base32 "1dq25qygyncbfq4kwwqqgyyakfqjwhp5q23vrf3bff1p66nyfl3b"))))
       (build-system gnu-build-system)
       (native-inputs
-       (list chez-scheme
+       (list (chez-scheme-for-system)
              ghostscript
              ;; FIXME: This package fails to build with the error:
              ;;     mktexpk: don't know how to create bitmap font for bchr8r
@@ -170,7 +170,7 @@ (define-public chez-sockets
           (base32 "1n5fbwwz51fdzvjackgmnsgh363g9inyxv7kmzi0469cwavwcx5m"))))
       (build-system gnu-build-system)
       (native-inputs
-       (list chez-scheme
+       (list (chez-scheme-for-system)
              chez-web
              (texlive-updmap.cfg (list texlive-pdftex))))
       (arguments
@@ -256,7 +256,7 @@ (define-public chez-matchable
     (inputs
      (list chez-srfi)) ; for tests
     (native-inputs
-     (list chez-scheme))
+     (list (chez-scheme-for-system)))
     (arguments
      (list #:make-flags (chez-make-flags name version)
            #:test-target "test"
@@ -288,7 +288,7 @@ (define-public chez-irregex
     (propagated-inputs
      (list chez-srfi)) ; for irregex-utils
     (native-inputs
-     (list chez-scheme))
+     (list (chez-scheme-for-system)))
     (arguments
      (list #:make-flags (chez-make-flags name version)
            #:test-target "test"
@@ -319,7 +319,7 @@ (define-public chez-fmt
     (propagated-inputs
      (list chez-srfi)) ; for irregex-utils
     (native-inputs
-     (list chez-scheme))
+     (list (chez-scheme-for-system)))
     (arguments
      (list #:make-flags (chez-make-flags name version)
            #:test-target "chez-check"
@@ -355,12 +355,34 @@ (define-public chez-mit
              (commit (string-append "v" version))))
        (sha256
         (base32 "0c7i3b6i90xk96nmxn1pc9272a4yal4v40dm1a4ybdi87x53zkk0"))
-       (file-name (git-file-name name version))))
+       (file-name (git-file-name name version))
+       (snippet
+        ;; Workaround for chez-scheme-racket-variant.
+        ;; See: https://github.com/racket/racket/issues/4151
+        #~(begin
+            (use-modules (guix build utils))
+            (substitute* "mit/core.sls"
+              (("[(]import ")
+               "(import (only (chezscheme) import)\n")
+              (("[(]define string->uninterned-symbol gensym[)]")
+               (format #f "~s"
+                       '(begin
+                          (import (only (chezscheme)
+                                        meta-cond
+                                        library-exports))
+                          (meta-cond
+                           ((memq 'string->uninterned-symbol
+                                  (library-exports '(chezscheme)))
+                            (import (only (chezscheme)
+                                          string->uninterned-symbol)))
+                           (else
+                            (define string->uninterned-symbol
+                              gensym)))))))))))
     (build-system gnu-build-system)
     (inputs
      (list chez-srfi))       ; for tests
     (native-inputs
-     (list chez-scheme))
+     (list (chez-scheme-for-system)))
     (arguments
      (list #:make-flags (chez-make-flags name version)
            #:test-target "test"
@@ -391,7 +413,7 @@ (define-public chez-scmutils
     (inputs
      (list chez-srfi))       ; for tests
     (native-inputs
-     (list chez-scheme))
+     (list (chez-scheme-for-system)))
     (propagated-inputs
      (list chez-mit chez-srfi))
     (arguments
diff --git a/gnu/packages/emacs-xyz.scm b/gnu/packages/emacs-xyz.scm
index c6a62e8767..54774d9cad 100644
--- a/gnu/packages/emacs-xyz.scm
+++ b/gnu/packages/emacs-xyz.scm
@@ -451,7 +451,7 @@ (define-public emacs-geiser-chez
                 (string-append
                  "(eval-after-load 'geiser-impl '" all ")"))))))))
     (inputs
-     (list chez-scheme))
+     (list (chez-scheme-for-system)))
     (propagated-inputs
      (list emacs-geiser))
     (home-page "https://nongnu.org/geiser/")
diff --git a/gnu/packages/loko.scm b/gnu/packages/loko.scm
index 74a649b8a1..a7ab12a0c4 100644
--- a/gnu/packages/loko.scm
+++ b/gnu/packages/loko.scm
@@ -71,7 +71,7 @@ (define-public loko-scheme
              #t)))))
     (native-inputs
      `(("akku" ,akku)
-       ("chez-scheme" ,chez-scheme)
+       ("chez-scheme" ,(chez-scheme-for-system))
        ("struct" ,guile-struct-pack)
        ("laesare" ,guile-laesare)
        ("pfds" ,guile-pfds)
diff --git a/gnu/packages/patches/racket-enable-scheme-backport.patch b/gnu/packages/patches/racket-enable-scheme-backport.patch
new file mode 100644
index 0000000000..3a5a4a3d82
--- /dev/null
+++ b/gnu/packages/patches/racket-enable-scheme-backport.patch
@@ -0,0 +1,465 @@
+From 8d7687842f099e3e7e60d3a83fed58b2c6a92863 Mon Sep 17 00:00:00 2001
+From: Matthew Flatt <mflatt@racket-lang.org>
+Date: Sun, 6 Feb 2022 10:36:09 -0700
+Subject: [PATCH 1/2] Chez Scheme: adapt bootfile build for supplied `Scheme=`
+
+(cherry picked from commit fca1e02349664060e10278ca2ce6577a949bebf5)
+
+(Fixed conflicts by dropping pbchunks and pbarch changes.)
+---
+ racket/src/ChezScheme/configure  | 15 ++++++++++++++-
+ racket/src/ChezScheme/s/Mf-base  |  4 ++--
+ racket/src/ChezScheme/s/Mf-cross |  4 +++-
+ 3 files changed, 19 insertions(+), 4 deletions(-)
+
+diff --git a/racket/src/ChezScheme/configure b/racket/src/ChezScheme/configure
+index 4515ffc105..0098829091 100755
+--- a/racket/src/ChezScheme/configure
++++ b/racket/src/ChezScheme/configure
+@@ -45,6 +45,7 @@ threads=yes
+ nothreads=no
+ temproot=""
+ help=no
++forceworkarea=no
+ gzipmanpages=yes
+ installowner=""
+ installgroup=""
+@@ -205,6 +206,9 @@ while [ $# != 0 ] ; do
+     --pb)
+       pb=yes
+       ;;
++    --force)
++      forceworkarea=yes
++      ;;
+     --installprefix=*)
+       installprefix=`echo $1 | sed -e 's/^--installprefix=//'`
+       ;;
+@@ -439,6 +443,7 @@ if [ "$help" = "yes" ]; then
+   echo "  --toolprefix=<prefix>             prefix tool (compiler, linker, ...) names"
+   echo "  --[no]gzip-man-pages              compress manual pages ($gzipmanpages)"
+   echo "  --workarea=<pathname>             build directory ($w)"
++  echo "  --force                           configure even without boot files"
+   echo "  CC=<C compiler>                   C compiler"
+   echo "  CPPFLAGS=<C preprocessor flags>   C preprocessor flags"
+   echo "  CFLAGS=<C compiler flags>         C compiler flags"
+@@ -721,8 +726,16 @@ case "${flagsmuni}" in
+         ;;
+ esac
+ 
++if [ "$w" = "$m" ] ; then
++    configuringin=""
++else
++    configuringin=" in $w"
++fi
++
+ if [ -f boot/$m/scheme.boot -o -f "$srcdir"/boot/$m/scheme.boot ] ; then
+-  echo "Configuring for $m"
++    echo "Configuring for $m$configuringin"
++elif [ "$forceworkarea" = yes ] ; then
++    echo "Configuring for $m$configuringin despite missing boot files"
+ else
+   if [ "$m" = "" ] ; then
+       maybem="<machine type>"
+diff --git a/racket/src/ChezScheme/s/Mf-base b/racket/src/ChezScheme/s/Mf-base
+index cc6178c973..1f4a967998 100644
+--- a/racket/src/ChezScheme/s/Mf-base
++++ b/racket/src/ChezScheme/s/Mf-base
+@@ -94,7 +94,7 @@ endif
+ # that Scheme and SCHEMEHEAPDIRS are set by Mf-cross to point to the host Scheme
+ # implementation
+ Scheme = ../bin/$m/scheme${ExeSuffix}
+-export SCHEMEHEAPDIRS=../boot/%m
++export SCHEMEHEAPDIRS=../boot/$m
+ export CHEZSCHEMELIBDIRS=.
+ 
+ # Define the libdirs separator character
+@@ -691,4 +691,4 @@ reset-one:
+ 
+ .PHONY: run
+ run:
+-	env SCHEMEHEAPDIRS=../boot/$m/ ../bin/$m/scheme $(ARGS)
++	env SCHEMEHEAPDIRS=${SCHEMEHEAPDIRS} ${Scheme} $(ARGS)
+diff --git a/racket/src/ChezScheme/s/Mf-cross b/racket/src/ChezScheme/s/Mf-cross
+index d796cbb459..397af59a28 100644
+--- a/racket/src/ChezScheme/s/Mf-cross
++++ b/racket/src/ChezScheme/s/Mf-cross
+@@ -43,5 +43,7 @@ x$(xm).$(m):
+ 	$(MAKE) -f Mf-cross m=$(m) xm=$(xm) i=f o=3 d=0 xpatch
+ 	mv xpatch x$(xm).$(m)
+ 
++ifneq ($(SCHEMEHEAPDIRS),:)
+ # Ensure that cross-compiling "nanopass.so" is rebuilt if the host compiler changed
+-nanopass.so: ${SCHEME} ${SCHEMEHEAPDIRS}/petite.boot ${SCHEMEHEAPDIRS}/scheme.boot
++nanopass.so: ${Scheme} ${SCHEMEHEAPDIRS}/petite.boot ${SCHEMEHEAPDIRS}/scheme.boot
++endif
+-- 
+2.32.0
+
+
+From 26c8e2c1d9b02ad85acef8bda40d92154cf0b699 Mon Sep 17 00:00:00 2001
+From: Matthew Flatt <mflatt@racket-lang.org>
+Date: Sun, 6 Feb 2022 11:03:30 -0700
+Subject: [PATCH 2/2] configure: make `--enable-scheme` work with an executable
+
+When the same Chez Scheme version as used by Racket is already
+available, then `--enable-scheme=...` can supply an executable. For
+cross builds, `--enable-scheme=...` can still supply a build
+directory, instead, as before.
+
+(cherry picked from commit 4f0e76855ce7e86107de495292a553469daf0b3f)
+---
+ racket/src/ChezScheme/makefiles/Makefile.in |  3 ++
+ racket/src/README.txt                       | 30 +++++++++++---
+ racket/src/configure                        |  8 +++-
+ racket/src/cs/README.txt                    |  6 ++-
+ racket/src/cs/c/Makefile.in                 | 44 ++++++++++++++++-----
+ racket/src/cs/c/configure                   | 24 +++++++++--
+ racket/src/cs/c/configure.ac                | 21 ++++++++--
+ 7 files changed, 112 insertions(+), 24 deletions(-)
+
+diff --git a/racket/src/ChezScheme/makefiles/Makefile.in b/racket/src/ChezScheme/makefiles/Makefile.in
+index c396efc851..3998ef9ccd 100644
+--- a/racket/src/ChezScheme/makefiles/Makefile.in
++++ b/racket/src/ChezScheme/makefiles/Makefile.in
+@@ -59,6 +59,9 @@ reset:
+ %.boot:
+ 	(cd $(workarea) && $(MAKE) $*.boot)
+ 
++auto.boot:
++	(cd $(workarea) && $(MAKE) $(defaultm).boot)
++
+ # <machine>.bootquick to build boot files for <machine>
+ # with o=3 d=0 for the cross compiler, and only after
+ # building the kernel for the configured machine
+diff --git a/racket/src/README.txt b/racket/src/README.txt
+index 98647aebce..d77310b4a4 100644
+--- a/racket/src/README.txt
++++ b/racket/src/README.txt
+@@ -354,6 +354,10 @@ variant of MinGW without "libdelayimp.a", get the implementation of
+ ========================================================================
+ 
+ Cross-compilation requires at least two flags to `configure`:
++`--host=OS` and either `--enable-racket=RACKET` or (for Racket CS)
++`--enable-scheme-SCHEME`.
++
++More information:
+ 
+  * `--host=OS`, where OS is something like `i386-gnu-linux` to
+    indicate the target platform.
+@@ -374,11 +378,27 @@ Cross-compilation requires at least two flags to `configure`:
+    run `configure` again (with no arguments) in a "local" subdirectory
+    to create a build for the current platform.
+ 
+-An additional flag is needed for building Racket CS, unless the flag
+-`--enable-racket=auto` is used:
+-
+- * `--enable-scheme=DIR`, where DIR is a path that has a "ChezScheme"
+-   directory where Chez Scheme is built for the host system.
++ * `--enable-scheme=SCHEME`, where SCHEME is a Chez Scheme executable
++   executable that runs on the build platform; the executable must be
++   the same version as used in Racket built for the target platform.
++ 
++   Supplying `--enable-scheme=DIR` is also supported in cross-build
++   mode, where DIR is a path that has a "ChezScheme" directory where
++   Chez Scheme is built for the host system.
++
++The `--enable-racket=RACKET` and `--enable-scheme=SCHEME` flags are
++allowed for non-cross builds, too:
++
++ * For Racket CS, supplying either selects a Racket or Chez Scheme
++   implementation used to create boot files to the build platform.
++   Suppling Chez Scheme is a much more direct path, but when Racket is
++   supplied, its version does not have to match the version being
++   built.
++
++ * For Racket BC, `--enable-racket=RACKET` selects a Racket for
++   prepare C sources to cooperate with garbage collection. Its version
++   needs to be close to the one being built, and potentially exactly
++   the same version.
+ 
+ Some less commonly needed `configure` flags are for Racket BC:
+ 
+diff --git a/racket/src/configure b/racket/src/configure
+index c9f3ba4419..1b53ec7ce2 100755
+--- a/racket/src/configure
++++ b/racket/src/configure
+@@ -9,6 +9,7 @@ pb_dir="$dir/ChezScheme/boot/pb"
+ use_cs=maybe
+ use_bc=maybe
+ supplied_racket=no
++supplied_scheme=no
+ enable_boothelp=
+ 
+ # We don't have to detect conflicts like `--enable-csdefault --enable-bcdefault`,
+@@ -34,6 +35,9 @@ for arg in $*; do
+         --enable-racket=*)
+             supplied_racket=yes
+             ;;
++        --enable-scheme=*)
++            supplied_scheme=yes
++            ;;
+         --help | -h)
+             echo $0:
+             echo see --help-bc or --help-cs, since the Racket CS build and the
+@@ -70,8 +74,8 @@ elif test "$use_cs" = "maybe" ; then
+ fi
+ 
+ if test "$use_cs" = "yes" ; then
+-    if test $use_bc = no  -a $supplied_racket = no -a ! -d "$pb_dir" ; then
+-        echo $0: must have $pb_dir or --enable-racket=... for --enable-csonly
++    if test $use_bc = no  -a $supplied_racket = no  -a $supplied_scheme = no  -a ! -d "$pb_dir" ; then
++        echo $0: must have $pb_dir, --enable-racket=... or --enable-scheme=... for --enable-csonly
+         exit 1
+     fi
+ 
+diff --git a/racket/src/cs/README.txt b/racket/src/cs/README.txt
+index 2ece417b78..8e6fc57b74 100644
+--- a/racket/src/cs/README.txt
++++ b/racket/src/cs/README.txt
+@@ -39,6 +39,11 @@ build:
+    installed in the "../ChezScheme/boot/pb" directory as described by
+    "../ChezScheme/BUILDING".
+ 
++   Supplying `--enable-scheme=...` is also an option if you alerady
++   have the same version of Chez Scheme built on the current platform.
++   Another build will be created, anyway, but more quickly than
++   without Chez Scheme.
++
+  * Racket is needed to generate the files in the "schemified"
+    directory from the sources in sibling directories like "../io". The
+    Racket version must be practically the same as the current Racket
+@@ -48,7 +53,6 @@ build:
+    Unlike Chez Scheme boot files, the files generated in "schemified"
+    are human-readable and -editable Scheme code. That provides a way
+    out of bootstrapping black holes, even without BC.
+-   
+ 
+ 
+ ========================================================================
+diff --git a/racket/src/cs/c/Makefile.in b/racket/src/cs/c/Makefile.in
+index 54a644a1d9..d73993f0fc 100644
+--- a/racket/src/cs/c/Makefile.in
++++ b/racket/src/cs/c/Makefile.in
+@@ -12,7 +12,9 @@ CS_HOST_WORKAREA_PREFIX = @CS_HOST_WORKAREA_PREFIX@
+ SCHEME_HOST_WORKAREA = $(CS_HOST_WORKAREA_PREFIX)$(SCHEME_WORKAREA)
+ SCHEME_BIN = $(SCHEME_HOST_WORKAREA)/$(MACH)/bin/$(MACH)/scheme
+ SCHEME_INC = $(SCHEME_HOST_WORKAREA)/$(MACH)/boot/$(MACH)
+-SCHEME = $(SCHEME_BIN) -B $(SCHEME_INC)/petite.boot -B $(SCHEME_INC)/scheme.boot
++SCHEME_built = $(SCHEME_BIN) -B $(SCHEME_INC)/petite.boot -B $(SCHEME_INC)/scheme.boot
++SCHEME_existing = @MAKE_SCHEME_SCHEME@
++SCHEME = $(SCHEME@USE_SCHEME_MODE@)
+ 
+ TARGET_MACH = @TARGET_MACH@
+ SCHEME_TARGET_INC = $(SCHEME_WORKAREA)/$(TARGET_MACH)/boot/$(TARGET_MACH)
+@@ -88,7 +90,7 @@ mainsrcdir = @srcdir@/../..
+ @INCLUDEDEP@ @srcdir@/../../version/version.mak
+ 
+ cs:
+-	$(MAKE) scheme@T_CROSS_MODE@
++	$(MAKE) scheme@MAKE_SCHEME_MODE@
+ 	$(MAKE) racket-so
+ 	cd rktio; $(MAKE)
+ 	$(MAKE) racketcs
+@@ -121,9 +123,13 @@ racket-so:
+ 
+ RACKET_SO_ENV = @CONFIGURE_RACKET_SO_COMPILE@
+ 
++TARGET_MACH_built = $(TARGET_MACH)
++TARGET_MACH_existing = xc-$(TARGET_MACH)
++XPATCH_FILE = $(SCHEME_WORKAREA)/$(TARGET_MACH@USE_SCHEME_MODE@)/s/xpatch
++
+ CS_PROGS = SCHEME="$(SCHEME)"
+ CS_OPTS = COMPRESS_COMP=@COMPRESS_COMP@ @ENABLE_OR_DISABLE_WPO@
+-CS_OPTScross = $(CS_OPTS) CSO=$(MACH) CROSS_COMP="--xpatch $(SCHEME_WORKAREA)/$(TARGET_MACH)/s/xpatch"
++CS_OPTScross = $(CS_OPTS) CSO=$(MACH) CROSS_COMP="--xpatch $(XPATCH_FILE)"
+ PASS_COMPILE_DEPS = EXTRA_COMPILE_DEPS="$(SCHEME_INC)/petite.boot $(SCHEME_INC)/scheme.boot"
+ 
+ build-racket-so:
+@@ -163,6 +169,15 @@ pb-bootquick:
+ 	cd $(SCHEME_WORKAREA) && $(MAKE) reset
+ 	$(SHELL) $(srcdir)/ready_boot.sh $(MACH) $(SCHEME_WORKAREA)
+ 
++scheme-via-scheme:
++	$(MAKE) $(SCHEME_WORKAREA)/boot/$(MACH)/scheme.boot
++	$(MAKE) mach-make
++
++$(SCHEME_WORKAREA)/boot/$(MACH)/scheme.boot:
++	mkdir -p $(SCHEME_WORKAREA)
++	$(MAKE) config-scheme CONFIG_SCHEME_MODE="$(CONFIG_SCHEME_MODE) --force"
++	cd $(SCHEME_WORKAREA) && $(MAKE) $(MACH).boot Scheme="$(SCHEME)" SCHEMEHEAPDIRS=: o=3 d=0 what=all
++
+ mach-make:
+ 	$(MAKE) config-scheme
+ 	cd $(SCHEME_WORKAREA) && $(MAKE)
+@@ -182,24 +197,33 @@ config-scheme:
+ 
+ scheme-cross:
+ 	env MAKE_BOOT_FOR_CROSS=yes SCHEME_SRC="$(SCHEME_DIR)" SCHEME_WORKAREA=$(SCHEME_WORKAREA) MACH="$(TARGET_MACH)" $(BOOTSTRAP_RACKET) "$(SCHEME_DIR)"/rktboot/make-boot.rkt
++	$(MAKE) finish-scheme-cross
++
++finish-scheme-cross:
+ 	$(SHELL) $(srcdir)/reset_boot.sh $(TARGET_MACH) $(SCHEME_WORKAREA)
+ 	cd $(SCHEME_WORKAREA) && "$(UP_SCHEME_DIR)"/configure @SCHEME_CROSS_CONFIG_ARGS@ $(SCHEME_CONFIG_VARS)
+ 	cd $(SCHEME_WORKAREA)/$(TARGET_MACH)/c && $(CHOST_HACK@T_CROSS_MODE@) $(MAKE) o=o cross=t
+-	$(MAKE) $(SCHEME_WORKAREA)/$(TARGET_MACH)/s/xpatch
++	$(MAKE) $(XPATCH_FILE)
++
++scheme-cross-via-scheme:
++	$(MAKE) $(SCHEME_WORKAREA)/boot/$(TARGET_MACH)/scheme.boot MACH=$(TARGET_MACH)
++	$(MAKE) finish-scheme-cross
+ 
+ # Rebuild patch file and cross "petite.boot" and "scheme.boot" when older
+-# than the build-host "scheme.boot" or when "make-boot.rkt" touchs dummy boot files
+-XPATCH_DEPS = $(SCHEME_HOST_WORKAREA)/$(MACH)/boot/$(MACH)/scheme.boot \
+-              $(SCHEME_WORKAREA)/boot/$(TARGET_MACH)/scheme.boot
++# than the build-<host "scheme.boot" or when "make-boot.rkt" touchs dummy boot files
++XPATCH_DEPS_built = $(SCHEME_HOST_WORKAREA)/$(MACH)/boot/$(MACH)/scheme.boot \
++                    $(SCHEME_WORKAREA)/boot/$(TARGET_MACH)/scheme.boot
++XPATCH_DEPS_existing = 
++XPATCH_DEPS = $(XPATCH_DEPS@USE_SCHEME_MODE@)
+ 
+-$(SCHEME_WORKAREA)/$(TARGET_MACH)/s/xpatch: $(XPATCH_DEPS)
++$(XPATCH_FILE): $(XPATCH_DEPS)
+ 	$(MAKE) bounce TARGET=build-xpatch-using-host
+ 
+ build-xpatch-using-host:
+ 	cd $(SCHEME_WORKAREA)/$(TARGET_MACH)/s && $(MAKE) -f Mf-cross m=$(MACH) xm=$(TARGET_MACH) Scheme="$(SCHEME_BIN)" SCHEMEHEAPDIRS="$(SCHEME_INC)"
+ 
+ XPATCH =
+-XPATCHcross = --xpatch $(SCHEME_WORKAREA)/$(TARGET_MACH)/s/xpatch
++XPATCHcross = --xpatch $(XPATCH_FILE)
+ 
+ racket.boot: racket.so
+ 	$(SCHEME) --script $(srcdir)/convert-to-boot.ss @BOOT_COMPRESS_COMP@ $(XPATCH@CROSS_MODE@) racket.so racket.boot $(TARGET_MACH)
+@@ -410,7 +434,7 @@ install-cross:
+ 	$(MAKE) compile-xpatch.$(TARGET_MACH)
+ 	$(MAKE) library-xpatch.$(TARGET_MACH)
+ 
+-SCHEME_XPATCH = $(SCHEME_WORKAREA)/$(TARGET_MACH)/s/xpatch
++SCHEME_XPATCH = $(XPATCH_FILE)
+ 
+ CROSS_SERVE_DEPS = $(srcdir)/mk-cross-serve.ss $(srcdir)/cross-serve.ss \
+                    $(srcdir)/../expander/env.ss $(srcdir)/../linklet/config.ss
+diff --git a/racket/src/cs/c/configure b/racket/src/cs/c/configure
+index 21695a431a..1eeef57753 100755
+--- a/racket/src/cs/c/configure
++++ b/racket/src/cs/c/configure
+@@ -654,6 +654,9 @@ MINGW
+ NOT_OSX
+ OSX
+ SETUP_BOOT_MODE
++USE_SCHEME_MODE
++MAKE_SCHEME_SCHEME
++MAKE_SCHEME_MODE
+ TT_CROSS_MODE
+ T_CROSS_MODE
+ CROSS_MODE
+@@ -1448,7 +1451,7 @@ Optional Features:
+   --enable-docs           build docs on install (enabled by default)
+   --enable-usersetup      setup user-specific files on install
+   --enable-racket=<path>  use <path> as Racket for build; or "auto" to create
+-  --enable-scheme=<path>  use <path> as host's build directory for cross
++  --enable-scheme=<path>  use <path> as host build for cross
+   --enable-mach=<mach>    use Chez Scheme machine type <mach>
+   --enable-target=<mach>  cross-build for Chez Scheme machine type <mach>
+   --enable-portable       prefer portable to host-specific
+@@ -2867,7 +2870,7 @@ show_explicitly_enabled "${enable_xonx}" "Unix style"
+ show_explicitly_enabled "${enable_libzo}" 'Compiled ".zo" files moved to lib'
+ 
+ show_explicitly_set "${enable_racket}" "Racket"
+-show_explicitly_set "${enable_scheme}" "Chez Scheme build directory"
++show_explicitly_set "${enable_scheme}" "Chez Scheme for build"
+ show_explicitly_set "${enable_mach}" "machine type"
+ show_explicitly_set "${enable_target}" "cross-build machine type"
+ show_explicitly_enabled "${enable_portable}" "portable"
+@@ -4745,9 +4748,21 @@ esac
+ 
+ SCHEME_DIR=${srcdir}/../../ChezScheme
+ MAKE_BUILD_SCHEME=checkout
++USE_SCHEME_MODE="_built"
++MAKE_SCHEME_MODE="${T_CROSS_MODE}"
+ 
+ if test "${enable_scheme}" != "" ; then
+-  CS_HOST_WORKAREA_PREFIX="${enable_scheme}/"
++   if test -d "${enable_scheme}" ; then
++     # Directory exists, so use it as a build directory
++     echo "Using supplied Scheme path as a build directory"
++     CS_HOST_WORKAREA_PREFIX="${enable_scheme}/"
++   else
++     # Directory does not exist, so assume it's an executable
++     echo "Using supplied Scheme path as an executable"
++     MAKE_SCHEME_MODE="${T_CROSS_MODE}-via-scheme"
++     MAKE_SCHEME_SCHEME="${enable_scheme}"
++     USE_SCHEME_MODE="_existing"
++   fi
+ fi
+ 
+ if test "${enable_racket}" != "" ; then
+@@ -6012,6 +6027,9 @@ SCHEME_CROSS_CONFIG_ARGS="--machine=${TARGET_MACH} --disable-x11 ${cs_auto_flags
+ 
+ 
+ 
++
++
++
+ 
+ 
+ 
+diff --git a/racket/src/cs/c/configure.ac b/racket/src/cs/c/configure.ac
+index 464ebe1760..aaee88156d 100644
+--- a/racket/src/cs/c/configure.ac
++++ b/racket/src/cs/c/configure.ac
+@@ -23,7 +23,7 @@ AC_ARG_ENABLE(compressmore, [  --enable-compressmore   compress compiled code ev
+ AC_ARG_ENABLE(compressboot, [  --enable-compressboot   compress boot files])
+ m4_include(../ac/path_arg.m4)
+ AC_ARG_ENABLE(racket,     [  --enable-racket=<path>  use <path> as Racket for build; or "auto" to create])
+-AC_ARG_ENABLE(scheme,     [  --enable-scheme=<path>  use <path> as host's build directory for cross])
++AC_ARG_ENABLE(scheme,     [  --enable-scheme=<path>  use <path> as host build for cross])
+ AC_ARG_ENABLE(mach,       [  --enable-mach=<mach>    use Chez Scheme machine type <mach>])
+ AC_ARG_ENABLE(target,     [  --enable-target=<mach>  cross-build for Chez Scheme machine type <mach>])
+ m4_include(../ac/portable_arg.m4)
+@@ -81,7 +81,7 @@ show_explicitly_disabled "${enable_compressboot}" "Compressed boot files"
+ show_explicitly_enabled "${enable_xonx}" "Unix style"
+ m4_include(../ac/path_show.m4)
+ show_explicitly_set "${enable_racket}" "Racket"
+-show_explicitly_set "${enable_scheme}" "Chez Scheme build directory"
++show_explicitly_set "${enable_scheme}" "Chez Scheme for build"
+ show_explicitly_set "${enable_mach}" "machine type"
+ show_explicitly_set "${enable_target}" "cross-build machine type"
+ m4_include(../ac/portable_show.m4)
+@@ -504,9 +504,21 @@ esac
+ 
+ SCHEME_DIR=${srcdir}/../../ChezScheme
+ MAKE_BUILD_SCHEME=checkout
++USE_SCHEME_MODE="_built"
++MAKE_SCHEME_MODE="${T_CROSS_MODE}"
+ 
+ if test "${enable_scheme}" != "" ; then
+-  CS_HOST_WORKAREA_PREFIX="${enable_scheme}/"
++   if test -d "${enable_scheme}" ; then
++     # Directory exists, so use it as a build directory
++     echo "Using supplied Scheme path as a build directory"
++     CS_HOST_WORKAREA_PREFIX="${enable_scheme}/"
++   else
++     # Directory does not exist, so assume it's an executable
++     echo "Using supplied Scheme path as an executable"
++     MAKE_SCHEME_MODE="${T_CROSS_MODE}-via-scheme"
++     MAKE_SCHEME_SCHEME="${enable_scheme}"
++     USE_SCHEME_MODE="_existing"
++   fi     
+ fi
+ 
+ if test "${enable_racket}" != "" ; then
+@@ -821,6 +833,9 @@ AC_SUBST(DIFF_MACH)
+ AC_SUBST(CROSS_MODE)
+ AC_SUBST(T_CROSS_MODE)
+ AC_SUBST(TT_CROSS_MODE)
++AC_SUBST(MAKE_SCHEME_MODE)
++AC_SUBST(MAKE_SCHEME_SCHEME)
++AC_SUBST(USE_SCHEME_MODE)
+ AC_SUBST(SETUP_BOOT_MODE)
+ AC_SUBST(OSX)
+ AC_SUBST(NOT_OSX)
+-- 
+2.32.0
+
-- 
2.32.0
P
P
Philip McGrath wrote on 8 Feb 16:18 +0100
[RFC PATCH 9/9] gnu: racket: Update to 8.3.900.
(address . 53878@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
20220208151857.1900389-9-philip@philipmcgrath.com
* gnu/packages/patches/racket-gui-tethered-launcher-backport.patch: New
patch.
* gnu/local.mk (dist_patch_DATA): Add it.
* gnu/packages/racket.scm (racket-minimal, racket): Update to 8.3.900.
Rewrite to use 'racket-vm-for-system', label-less inputs,
G-expressions, and Git origins for main-distribution packages.
---
gnu/local.mk | 3 +-
...acket-gui-tethered-launcher-backport.patch | 26 +
gnu/packages/racket.scm | 1549 +++++++++++------
3 files changed, 1053 insertions(+), 525 deletions(-)
create mode 100644 gnu/packages/patches/racket-gui-tethered-launcher-backport.patch

Toggle diff (1674 lines)
diff --git a/gnu/local.mk b/gnu/local.mk
index 94de782ca9..742e072e73 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -41,7 +41,7 @@
 # Copyright © 2020 Vinicius Monego <monego@posteo.net>
 # Copyright © 2021 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
 # Copyright © 2021 Greg Hogan <code@greghogan.com>
-# Copyright © 2021 Philip McGrath <philip@philipmcgrath.com>
+# Copyright © 2021, 2022 Philip McGrath <philip@philipmcgrath.com>
 # Copyright © 2021 Arun Isaac <arunisaac@systemreboot.net>
 # Copyright © 2021 Sharlatan Hellseher <sharlatanus@gmail.com>
 # Copyright © 2021 Dmitry Polyakov <polyakov@liltechdude.xyz>
@@ -1786,6 +1786,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/rpcbind-CVE-2017-8779.patch		\
   %D%/packages/patches/rtags-separate-rct.patch			\
   %D%/packages/patches/racket-enable-scheme-backport.patch	\
+  %D%/packages/patches/racket-gui-tethered-launcher-backport.patch	\
   %D%/packages/patches/racket-minimal-sh-via-rktio.patch	\
   %D%/packages/patches/remake-impure-dirs.patch			\
   %D%/packages/patches/restic-0.9.6-fix-tests-for-go1.15.patch	\
diff --git a/gnu/packages/patches/racket-gui-tethered-launcher-backport.patch b/gnu/packages/patches/racket-gui-tethered-launcher-backport.patch
new file mode 100644
index 0000000000..1e018eaa79
--- /dev/null
+++ b/gnu/packages/patches/racket-gui-tethered-launcher-backport.patch
@@ -0,0 +1,26 @@
+From aa792e707b1fbc5cc33691bfaee5828dc3fbebaa Mon Sep 17 00:00:00 2001
+From: Matthew Flatt <mflatt@racket-lang.org>
+Date: Mon, 31 Jan 2022 15:31:22 -0700
+Subject: [PATCH] fix creation of tethered launchers
+
+Related to racket/racket#4133
+
+(cherry picked from commit 563c68432f127729592f234ef30c31e92618b517)
+---
+ gui-lib/mred/installer.rkt | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/gui-lib/mred/installer.rkt b/gui-lib/mred/installer.rkt
+index b1691472..9ef06c53 100644
+--- a/gui-lib/mred/installer.rkt
++++ b/gui-lib/mred/installer.rkt
+@@ -72,4 +72,5 @@
+    (list "-A" (path->string (find-system-path 'addon-dir)))))
+ 
+ (define (config-flags)
+-  (list "-G" (path->string (find-config-dir))))
++  (list "-X" (path->string (find-collects-dir))
++        "-G" (path->string (find-config-dir))))
+-- 
+2.32.0
+
diff --git a/gnu/packages/racket.scm b/gnu/packages/racket.scm
index e8d016c07b..e3c38714c1 100644
--- a/gnu/packages/racket.scm
+++ b/gnu/packages/racket.scm
@@ -2,7 +2,7 @@
 ;;; Copyright © 2013, 2014, 2015, 2016, 2018, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2017, 2018, 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2020 Pierre Neidhardt <mail@ambrevar.xyz>
-;;; Copyright © 2021 Philip McGrath <philip@philipmcgrath.com>
+;;; Copyright © 2021, 2022 Philip McGrath <philip@philipmcgrath.com>
 ;;; Copyright © 2021 jgart <jgart@dismail.de>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -21,8 +21,6 @@
 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (gnu packages racket)
-  #:use-module ((guix licenses)
-                #:select (asl2.0 expat lgpl3+))
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix git-download)
@@ -30,7 +28,10 @@ (define-module (gnu packages racket)
   #:use-module (guix gexp)
   #:use-module (guix build-system gnu)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-26)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 regex)
+  #:use-module (ice-9 exceptions)
   #:use-module (gnu packages)
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages bash)
@@ -47,200 +48,87 @@ (define-module (gnu packages racket)
   #:use-module (gnu packages multiprecision)
   #:use-module (gnu packages sqlite)
   #:use-module (gnu packages tls)
-  #:use-module (gnu packages xorg))
-
-;; Commentary:
-;;
-;; Here's how bootstrapping minimal Racket works:
-;;
-;;   - Racket BC [CGC] can be built with only a C compiler (except for
-;;     one caveat discussed below).
-;;   - Racket BC [3M] needs an existing Racket to run "xform",
-;;     which transforms its own C source code to add additional annotations
-;;     for the precise garbage collector.
-;;   - Racket CS needs (bootfiles for) Racket's fork of Chez Scheme.
-;;     It also needs an existing Racket to compile Racket-implemented
-;;     parts of the runtime system to R6RS libraries.
-;;   - Chez Scheme also needs bootfiles for itself, but Racket can simulate
-;;     enough of Chez Scheme to load Racket's fork of the Chez Scheme compiler
-;;     purely from source into Racket and apply the compiler to itself,
-;;     producing the needed bootfiles (albeit very slowly).
-;;     Any variant of Racket since version 7.1 can run the simulation.
-;;
-;; So, we build CGC to build 3M to build bootfiles and CS.
-;;
-;; One remaining bootstrapping limitation is that Racket's reader, module
-;; system, and macro expander are implemented in Racket. For Racket CS,
-;; they are compiled to R6RS libraries as discussed above. This note from the
-;; README file applies to all such subsystems:
-;;
-;;     The Racket version must be practically the same as the current Racket
-;;     verson, although it can be the Racket BC implementation (instead of
-;;     the Racket CS implementation).
-;;
-;;     Unlike Chez Scheme boot files, the files generated in "schemified"
-;;     are human-readable and -editable Scheme code. That provides a way
-;;     out of bootstrapping black holes, even without BC.
-;;
-;; However, other Racket subsystems implemented in Racket for Racket CS
-;; use older C implementations for Racket BC, whereas the reader, expander,
-;; and module system were completely replaced with the Racket implementation
-;; as of Racket 7.0.
-;;
-;; For Racket BC, the compiled "linklet" s-expressions (primitive modules)
-;; are embeded in C as a static string constant. Eventually, they are further
-;; compiled by the C-implemented Racket BC bytecode and JIT compilers.
-;; (On platforms where Racket BC's JIT is not supported, yet another compiler
-;; instead compiles the linklets to C code, but this is not a bootstrapping
-;; issue.)
-;;
-;; Code:
-
-(define cfg-flag:sh-for-rktio
-  `(string-append "CPPFLAGS=-DGUIX_RKTIO_PATCH_BIN_SH="
-                  (assoc-ref %build-inputs "sh")
-                  "/bin/sh"))
-(define cfg-flag:enable-lt
-  `(string-append "--enable-lt="
-                  (assoc-ref %build-inputs "libtool")
-                  "/bin/libtool"))
-(define cfg-flag:enable-racket
-  `(let ((racket (assoc-ref %build-inputs "racket")))
-     (string-append "--enable-racket="
-                    racket
-                    "/bin/racket")))
-
-(define unpack-nanopass+stex
-  ;; Copied from chez-scheme.
-  ;; TODO: Eventually, we should refactor Chez Scheme
-  ;; enough to share more directly, so that we can make
-  ;; Racket's version of Chez avalable as a Guix package,
-  ;; e.g. for architectures not supported upstream.
-  ;; For now, we let Racket drive the Chez build process
-  ;; other than this step.
-  `(for-each (lambda (dep)
-               (define src
-                 (assoc-ref (or native-inputs inputs) dep))
-               (copy-recursively src dep
-                                 #:keep-mtime? #t))
-             '("nanopass" "stex")))
-
+  #:use-module (gnu packages xorg)
+  #:use-module ((guix licenses)
+                #:prefix license:))
 
 (define-public racket-minimal
   (package
     (name "racket-minimal")
-    (version "8.3")            ; note: remember to also update racket!
-    (source
-     (origin
-       (method git-fetch)
-       (uri (git-reference
-             (url "https://github.com/racket/racket")
-             (commit (string-append "v" version))))
-       (sha256
-        "1i1jnv1wb0kanfg47hniafx2vhwjc33qqx66lq7wkf5hbmgsyws3")
-       (file-name (git-file-name name version))
-       (patches (search-patches "racket-minimal-sh-via-rktio.patch"))
-       (modules '((guix build utils)))
-       (snippet
-        (with-imported-modules '((guix build utils))
-          #~(begin
-              ;; Unbundle Chez submodules.
-              (with-directory-excursion "racket/src/ChezScheme"
-                ;; Remove bundled libraries (copied from 'chez-scheme').
-                (for-each delete-file-recursively
-                          '("stex"
-                            "nanopass"
-                            "lz4"
-                            "zlib")))
-              ;; Unbundle libffi.
-              (delete-file-recursively "racket/src/bc/foreign/libffi"))))))
-    (inputs
-     `(;; common to all racket-minimal variants:
-       ("openssl" ,openssl)
-       ("sqlite" ,sqlite)
-       ("sh" ,bash-minimal)
-       ;; only for CS
-       ("zlib" ,zlib)
-       ("zlib:static" ,zlib "static")
-       ("lz4" ,lz4)
-       ("lz4:static" ,lz4 "static")))
-    (native-inputs
-     `(("bootfiles" ,racket-bootstrap-chez-bootfiles)
-       ,@(package-native-inputs racket-bootstrap-chez-bootfiles)))
+    (version (package-version (racket-vm-for-system)))
+    (source (package-source (racket-vm-for-system)))
+    ;; For cross-compilation, Matthew Flatt recommends reusing
+    ;; as much of `raco cross` as possible. So, put that off until
+    ;; we have a build system for Racket packages.
+    (inputs (list openssl sqlite (racket-vm-for-system)))
     (build-system gnu-build-system)
     (arguments
-     `(#:configure-flags
-       (list "--enable-csonly"
-             "--enable-libz"
-             "--enable-liblz4"
-             ,cfg-flag:enable-racket
-             ,cfg-flag:sh-for-rktio)
-       #:out-of-source? #true
-       ;; Tests are in packages like racket-test-core and
-       ;; main-distribution-test that aren't part of the main distribution.
-       #:tests? #f
-       #:modules ((ice-9 match)
-                  (guix build gnu-build-system)
-                  (guix build utils))
-       #:phases
-       (modify-phases %standard-phases
-         (add-after 'unpack 'unpack-nanopass+stex
-           (lambda* (#:key inputs native-inputs #:allow-other-keys)
-             (with-directory-excursion "racket/src/ChezScheme"
-               ,unpack-nanopass+stex)
-             #t))
-         (add-after 'unpack-nanopass+stex 'unpack-bootfiles
-           (lambda* (#:key inputs #:allow-other-keys)
-             (with-directory-excursion "racket/src/ChezScheme"
-               (copy-recursively
-                (string-append (assoc-ref inputs "bootfiles") "/boot")
-                "boot"))
-             #t))
-         (add-before 'configure 'initialize-config.rktd
-           (lambda* (#:key inputs #:allow-other-keys)
-             (define (write-racket-hash alist)
-               ;; inside must use dotted pair notation
-               (display "#hash(")
-               (for-each (match-lambda
-                           ((k . v)
-                            (format #t "(~s . ~s)" k v)))
-                         alist)
-               (display ")\n"))
-             (mkdir-p "racket/etc")
-             (with-output-to-file "racket/etc/config.rktd"
-               (lambda ()
-                 (write-racket-hash
-                  `((lib-search-dirs
-                     . (#f ,@(map (lambda (lib)
-                                    (string-append (assoc-ref inputs lib)
-                                                   "/lib"))
-                                  '("openssl"
-                                    "sqlite"))))
-                    (build-stamp . "")
-                    (catalogs
-                     . (,(string-append
-                          "https://download.racket-lang.org/releases/"
-                          ,version
-                          "/catalog/")
-                        #f))))))
-             #t))
-         (add-before 'configure 'change-directory
-           (lambda _
-             (chdir "racket/src")
-             #t))
-         (add-after 'install 'remove-pkgs-directory
-           ;; If the configured pkgs-dir exists, "pkgs.rktd" does not
-           ;; exist, and a lock file does not exist, commands like
-           ;; `raco pkg show` will try to create a lock file and fail
-           ;; due to the read-only store.
-           ;; Arguably this may be a bug in `pkg/private/lock`:
-           ;; see <https://github.com/racket/racket/issues/3851>.
-           ;; As a workaround, remove the directory.
-           (lambda* (#:key outputs #:allow-other-keys)
-             ;; rmdir because we want an error if it isn't empty
-             (rmdir (string-append (assoc-ref outputs "out")
-                                   "/share/racket/pkgs"))
-             #t)))))
+     (list
+      #:configure-flags
+      #~`("--tethered"
+          "--extra-foreign-lib-search-dirs"
+          ,(format #f "~s"
+                   (list #$(file-append (this-package-input "openssl") "/lib")
+                         #$(file-append (this-package-input "sqlite") "/lib"))))
+      #:make-flags #~`("base")
+      #:tests? #f ;; packaged separately
+      #:modules '((guix build gnu-build-system)
+                  (guix build utils)
+                  (ice-9 match))
+      #:phases
+      #~(modify-phases %standard-phases
+          (replace 'configure
+            (lambda* (#:key inputs configure-flags make-flags
+                            #:allow-other-keys)
+              (let* ((vm-dir (search-input-directory inputs "opt/racket-vm"))
+                     (racket (string-append vm-dir "/bin/racket")))
+                (apply invoke
+                       racket
+                       #$make-installation-layer.rkt
+                       `(,@(cond
+                            ((false-if-exception
+                              (search-input-file
+                               inputs "etc/racket/config.rktd"))
+                             => (lambda (file)
+                                  `("--parent"
+                                    ,(dirname (dirname (dirname file))))))
+                            (else
+                             '()))
+                         ,@configure-flags
+                         ,vm-dir
+                         ,#$output))
+                (invoke racket
+                        "--config" (string-append #$output "/etc/racket")
+                        "-l" "raco" "setup"
+                        "--no-user"))))
+          (replace 'build
+            (lambda* (#:key inputs #:allow-other-keys)
+              (mkdir-p (string-append #$output "/lib/racket/pkgs"))
+              (for-each (lambda (name)
+                          (copy-recursively
+                           (string-append "pkgs/" name)
+                           (string-append #$output "/lib/racket/pkgs/" name)))
+                        '("base" "racket-lib"))))
+          (replace 'install
+            (lambda* (#:key inputs make-flags #:allow-other-keys)
+              (let ((racket
+                     (search-input-file inputs "/opt/racket-vm/bin/racket")))
+                (unless (null? make-flags)
+                  (invoke racket
+                          "-l-"
+                          "pkg/dirs-catalog"
+                          "--link"
+                          "local-catalog"
+                          (string-append #$output "/lib/racket/pkgs"))
+                  (apply invoke
+                         racket
+                         "--config" (string-append #$output "/etc/racket")
+                         "-l" "raco"
+                         "pkg" "install"
+                         "--installation"
+                         "--auto"
+                         "--catalog" "local-catalog"
+                         make-flags))))))))
     (home-page "https://racket-lang.org")
     (synopsis "Racket without bundled packages such as DrRacket")
     (description
@@ -254,280 +142,77 @@ (define (write-racket-hash alist)
 DrRacket IDE, are not included.")
     ;; https://download.racket-lang.org/license.html
     ;; The LGPL components are only used by Racket BC.
-    (license (list asl2.0 expat))))
-
-
-(define-public racket-minimal-bc-3m
-  (hidden-package
-   (package
-     (inherit racket-minimal)
-     (name "racket-minimal-bc-3m")
-     (inputs
-      (modify-inputs (package-inputs racket-minimal)
-        (delete "zlib" "zlib:static" "lz4" "lz4:static")
-        (prepend libffi ;; <- only for BC variants
-                 )))
-     (native-inputs
-      `(("libtool" ,libtool)
-        ("racket" ,(if (%current-target-system)
-                       racket-minimal
-                       racket-minimal-bc-cgc))))
-     (arguments
-      (substitute-keyword-arguments (package-arguments racket-minimal)
-        ((#:configure-flags _ '())
-         `(list "--enable-bconly"
-                ,cfg-flag:enable-racket
-                ,cfg-flag:enable-lt
-                ,cfg-flag:sh-for-rktio))
-        ((#:phases usual-phases)
-         `(modify-phases ,usual-phases
-            (delete 'unpack-nanopass+stex)
-            (delete 'unpack-bootfiles)))))
-     (synopsis "Minimal Racket with the BC [3M] runtime system")
-     (description "The Racket BC (``before Chez'' or ``bytecode'')
-implementation was the default before Racket 8.0.  It uses a compiler written
-in C targeting architecture-independent bytecode, plus a JIT compiler on most
-platforms.  Racket BC has a different C API and supports a slightly different
-set of architectures than the current default runtime system, Racket CS (based
-on ``Chez Scheme'').
-
-This package is the normal implementation of Racket BC with a precise garbage
-collector, 3M (``Moving Memory Manager'').")
-     ;; https://download.racket-lang.org/license.html
-     ;; The LGPL components are only used by Racket BC.
-     (license (list lgpl3+ asl2.0 expat)))))
-
-
-(define-public racket-minimal-bc-cgc
-  (package
-    (inherit racket-minimal-bc-3m)
-    (name "racket-minimal-bc-cgc")
-    (native-inputs
-     (alist-delete "racket" (package-native-inputs racket-minimal-bc-3m)))
-    (arguments
-     (substitute-keyword-arguments (package-arguments racket-minimal-bc-3m)
-       ((#:configure-flags _ '())
-        `(list "--enable-cgcdefault"
-               ,cfg-flag:enable-lt
-               ,cfg-flag:sh-for-rktio))))
-    (synopsis "Old Racket implementation used for bootstrapping")
-    (description "This variant of the Racket BC (``before Chez'' or
-``bytecode'') implementation is not recommended for general use.  It uses
-CGC (a ``Conservative Garbage Collector''), which was succeeded as default in
-PLT Scheme version 370 (which translates to 3.7 in the current versioning
-scheme) by the 3M variant, which in turn was succeeded in version 8.0 by the
-Racket CS implementation.
-
-Racket BC [CGC] is primarily used for bootstrapping Racket BC [3M].  It may
-also be used for embedding applications without the annotations needed in C
-code to use the 3M garbage collector.")))
-
-
-(define-public racket-bootstrap-chez-bootfiles
-  (hidden-package
-   (package
-     (inherit racket-minimal)
-     (name "racket-bootstrap-chez-bootfiles")
-     (inputs `())
-     (native-inputs
-      `(("racket" ,(if (%current-target-system)
-                       racket-minimal
-                       racket-minimal-bc-3m))
-        ("stex" ,(package-source stex))
-        ("nanopass" ,(package-source chez-nanopass))))
-     (arguments
-      `(#:phases
-        (modify-phases %standard-phases
-          (add-after 'unpack 'unpack-nanopass+stex
-            (lambda* (#:key inputs native-inputs #:allow-other-keys)
-              (with-directory-excursion "racket/src/ChezScheme"
-                ,unpack-nanopass+stex)
-              #t))
-          (delete 'configure)
-          (delete 'patch-generated-file-shebangs)
-          (replace 'build
-            (lambda* (#:key inputs outputs #:allow-other-keys)
-              (with-directory-excursion "racket/src/ChezScheme"
-                (invoke (string-append (assoc-ref inputs "racket")
-                                       "/bin/racket")
-                        "rktboot/main.rkt"
-                        "--dest" (assoc-ref outputs "out")))
-              #t))
-          (delete 'check)
-          (delete 'install))))
-     (synopsis "Chez Scheme bootfiles bootstrapped by Racket")
-     (description "Chez Scheme is a self-hosting compiler: building it
-requires ``bootfiles'' containing the Scheme-implemented portions compiled for
-the current platform.  (Chez can then cross-compile bootfiles for all other
-supported platforms.)
-
-The Racket package @code{cs-bootstrap} (part of the main Racket Git
-repository) implements enough of a Chez Scheme simulation to load the Chez
-Scheme compiler purely from source into Racket and apply the compiler to
-itself, thus bootstrapping Chez Scheme.  Bootstrapping takes about 10 times as
-long as using an existing Chez Scheme, but @code{cs-bootstrap} supports Racket
-7.1 and later, including the Racket BC variant.
-
-Note that the generated bootfiles are specific to Racket's fork of Chez
-Scheme, and @code{cs-bootstrap} does not currently support building upstream
-Chez Scheme.")
-     (license (list asl2.0)))))
-
-
-(define %installer-mirrors
-  ;; Source:
-  ;; https://github.com/racket/racket-lang-org/blob/master/download/data.rkt#L58
-  ;; Matthew Flatt says: "note that many are commented out"
-  ;; INVARIANT: End with a trailing "/"!
-  '("https://mirror.racket-lang.org/installers/"
-    "https://www.cs.utah.edu/plt/installers/"
-    "https://plt.cs.northwestern.edu/racket-mirror/"
-    "https://mirror.csclub.uwaterloo.ca/racket/racket-installers/"
-    ;; Universität Tübingen is using a self-signed HTTPS certificate:
-    "http://mirror.informatik.uni-tuebingen.de/mirror/racket/"
-    "https://racket.infogroep.be/"
-    ))
-
-(define %main-repo-main-distribution-pkgs
-  ;; These are the packages developed in the main Racket Git repository
-  ;; that are part of the main distribution.
-  '("at-exp-lib"
-    "base"
-    "compiler-lib"
-    ;; NOT "compiler-test"
-    "compiler"
-    "net-doc"
-    "net-lib"
-    ;; NOT "net-test"
-    "net"
-    ;; NOT "plt-services"
-    ;; NOT "racket-benchmarks"
-    ;; NOT "racket-build-guide"
-    "racket-doc"
-    "racket-index"
-    "racket-lib"
-    ;; NOT "racket-test-core"
-    ;; NOT "racket-test-extra"
-    ;; NOT "racket-test"
-    "zo-lib"))
-
+    (license (list license:asl2.0 license:expat))))
 
 (define-public racket
   (package
     (inherit racket-minimal)
     (name "racket")
-    (version (package-version racket-minimal)) ; needed for origin uri to work
-    (source
-     (origin
-       (method url-fetch)
-       (uri (map (lambda (base)
-                   (string-append base version "/racket-src.tgz"))
-                 %installer-mirrors))
-       (sha256
-        (base32
-         "0jdr0y7scvv2a3sq456ifrgq0yfsbiwavdf2m86zmrapp481mby4"))
-       (snippet
-        #~(begin
-            (use-modules (guix build utils)
-                         (ice-9 match)
-                         (ice-9 regex))
-            ;; unbundle minimal Racket
-            (for-each delete-file-recursively
-                      '("collects"
-                        "doc"
-                        "etc"
-                        "README"
-                        "src"))
-            ;; unbundle package sources included elsewhere
-            (with-directory-excursion "share/pkgs"
-              (for-each delete-file-recursively
-                        '#+%main-repo-main-distribution-pkgs))
-            #t))))
+    (source #f)
     (inputs
-     `(("cairo" ,cairo)
-       ("fontconfig" ,fontconfig)
-       ("glib" ,glib)
-       ("glu" ,glu)
-       ("gmp" ,gmp)
-       ("gtk+" ,gtk+)                   ; propagates gdk-pixbuf+svg
-       ("libjpeg" ,libjpeg-turbo)
-       ("libpng" ,libpng)
-       ("libx11" ,libx11)
-       ("mesa" ,mesa)
-       ("mpfr" ,mpfr)
-       ("pango" ,pango)
-       ("unixodbc" ,unixodbc)
-       ("libedit" ,libedit)))
-    (native-inputs
-     `(("racket" ,racket-minimal)
-       ("extend-layer" ,extend-layer)
-       ("main-repo" ,(package-source racket-minimal))))
+     (list cairo
+           fontconfig
+           glib
+           glu
+           gmp
+           gtk+ ;; propagates gdk-pixbuf+svg
+           libjpeg-turbo
+           libpng
+           libx11 ;; ?? wayland ??
+           mesa
+           mpfr
+           pango
+           unixodbc
+           libedit ;; TODO reconsider in light of expeditor and readline-gpl
+           racket-minimal ;; <-- TODO non-tethered layer
+           (racket-vm-for-system)))
     (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (add-before 'configure 'unpack-packages
-           (let ((unpack (assoc-ref %standard-phases 'unpack)))
-             (lambda* (#:key  native-inputs inputs outputs #:allow-other-keys)
-               (let* ((racket (assoc-ref (or native-inputs inputs) "racket"))
-                      (prefix (assoc-ref outputs "out"))
-                      (pkgs-dir (string-append prefix "/share/racket/pkgs")))
-                 (mkdir-p pkgs-dir)
-                 (copy-recursively
-                  "share/links.rktd"
-                  (string-append prefix "/share/racket/links.rktd"))
-                 (copy-recursively "share/pkgs" pkgs-dir)
-                 ;; NOTE: unpack changes the working directory
-                 (unpack #:source (assoc-ref (or native-inputs inputs)
-                                             "main-repo"))
-                 (for-each (lambda (pkg)
-                             (define dest (string-append pkgs-dir "/" pkg))
-                             (mkdir-p dest)
-                             (copy-recursively (string-append "pkgs/" pkg)
-                                               dest))
-                           ',%main-repo-main-distribution-pkgs)
-                 #t))))
-         (replace 'configure
-           (lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
-             (let ((racket (assoc-ref (or native-inputs inputs) "racket"))
-                   (prefix (assoc-ref outputs "out")))
-               (apply invoke
-                      (string-append racket "/bin/racket")
-                      (assoc-ref inputs "extend-layer")
-                      racket
-                      prefix
-                      (map
-                       (lambda (lib)
-                         (string-append (assoc-ref inputs lib) "/lib"))
-                       '("cairo"
-                         "fontconfig"
-                         "glib"
-                         "glu"
-                         "gmp"
-                         "gtk+"
-                         "libjpeg"
-                         "libpng"
-                         "libx11"
-                         "mesa"
-                         "mpfr"
-                         "pango"
-                         "unixodbc"
-                         "libedit")))
-               #t)))
-         (replace 'build
-           (lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
-             (invoke (string-append (assoc-ref (or native-inputs inputs)
-                                               "racket")
-                                    "/bin/racket")
-                     "--config"
-                     (string-append (assoc-ref outputs "out")
-                                    "/etc/racket")
-                     "-l"
-                     "raco"
-                     "setup")
-             #t))
-         (delete 'install))
-       ;; we still don't have these:
-       #:tests? #f))
+     (substitute-keyword-arguments (package-arguments racket-minimal)
+       ((#:configure-flags _ '())
+        #~`("--tethered"
+            "--extra-foreign-lib-search-dirs"
+            ,(format #f "~s"
+                     '(#$@(map (lambda (name)
+                                 (cond
+                                  ((this-package-input name)
+                                   => (cut file-append <> "/lib"))
+                                  (else
+                                   (raise-exception
+                                    (make-exception
+                                     (make-assertion-failure)
+                                     (make-exception-with-message
+                                      "missing input to the 'racket' package")
+                                     (make-exception-with-irritants
+                                      (list name)))))))
+                               '("cairo"
+                                 "fontconfig-minimal" ;; aka fontconfig
+                                 "glib"
+                                 "glu"
+                                 "gmp"
+                                 "gtk+"
+                                 "libjpeg-turbo"
+                                 "libpng"
+                                 "libx11"
+                                 "mesa"
+                                 "mpfr"
+                                 "pango"
+                                 "unixodbc"
+                                 "libedit"))))))
+       ((#:make-flags _ '())
+        #~`("main-distribution"))
+       ((#:phases parent-phases #~%standard-phases)
+        #~(modify-phases #$parent-phases
+            (delete 'unpack)
+            (replace 'build
+              (lambda args
+                (mkdir-p (string-append #$output "/lib/racket/pkgs"))
+                (for-each
+                 (match-lambda
+                   ((name src)
+                    (copy-recursively
+                     src
+                     (string-append #$output "/lib/racket/pkgs/" name))))
+                 '(#$@main-distribution-packages))))))))
     (synopsis "Programmable programming language in the Scheme family")
     (description
      "Racket is a general-purpose programming language in the Scheme family,
@@ -539,82 +224,898 @@ (define dest (string-append pkgs-dir "/" pkg))
 DrRacket IDE, libraries for GUI and web programming, and implementations of
 languages such as Typed Racket, R5RS and R6RS Scheme, Algol 60, and Datalog.")))
 
-
-(define extend-layer
+(define make-installation-layer.rkt
   (scheme-file
-   "extend-layer.rkt"
+   "make-installation-layer.rkt"
    `(module
-     extend-layer racket/base
+     make-installation-layer racket/base
      (require racket/cmdline
               racket/match
               racket/file
+              racket/port
               racket/list
               racket/pretty)
-     (define config-file-pth
-       "etc/racket/config.rktd")
      (define (build-path-string . args)
        (path->string (apply build-path args)))
      (define rx:racket
        ;; Guile's reader doesn't support #rx"racket"
        (regexp "racket"))
-     (command-line
-      #:args (parent-layer prefix . lib-dir*)
-      (let* ([config
-              (for/fold
-               ([config (file->value (build-path parent-layer
-                                                 config-file-pth))])
-               ([spec (in-list
-                       '((lib-dir lib-search-dirs "lib/racket")
-                         (share-dir share-search-dirs "share/racket")
-                         (links-file
-                          links-search-files
-                          "share/racket/links.rktd")
-                         (pkgs-dir pkgs-search-dirs "share/racket/pkgs")
-                         (bin-dir bin-search-dirs "bin")
-                         (man-dir man-search-dirs "share/man")
-                         (doc-dir doc-search-dirs "share/doc/racket")
-                         (include-dir
-                          include-search-dirs
-                          "include/racket")))])
-               (match-define (list main-key search-key pth) spec)
-               (hash-set*
-                config
-                main-key
-                (build-path-string prefix pth)
-                search-key
-                (list* #f
-                       (hash-ref config
-                                 main-key
-                                 (build-path-string parent-layer pth))
-                       (filter values (hash-ref config search-key null)))))]
-             [config
-              (hash-set config
-                        'apps-dir
-                        (build-path-string prefix "share/applications"))]
-             [config
-              ;; place new foreign lib-search-dirs before old
-              ;; foreign dirs, but after Racket layers
-              (let-values
-                  ([(rkt extra)
-                    (partition (lambda (pth)
-                                 (or (not pth)
-                                     (regexp-match? rx:racket pth)))
-                               (hash-ref config 'lib-search-dirs))])
-                (hash-set config
+     (define tethered? #f)
+     (define parent #f)
+     (define extra-foreign-lib-search-dirs '())
+     (define-values [vm-dir prefix]
+       (command-line
+        #:once-each
+        [("--tethered") "create a tethered layer"
+         (set! tethered? #t)]
+        [("--parent") dir "path of parent layer, if any"
+         (set! parent dir)]
+        [("--extra-foreign-lib-search-dirs") dir-list
+         "foreign library directories, as a list of strings in `read` syntax"
+         (set! extra-foreign-lib-search-dirs
+               (call-with-input-string dir-list read))]
+        #:args (vm-dir prefix)
+        (values vm-dir prefix)))
+     (let* ([config
+             (for/fold
+              ([config (file->value
+                        (if parent
+                            (build-path parent "etc/racket/config.rktd")
+                            (build-path vm-dir "etc/config.rktd")))])
+              ([spec
+                (in-list
+                 '((lib-dir lib-search-dirs "lib/racket" "lib")
+                   (share-dir share-search-dirs "share/racket" "share")
+                   (links-file links-search-files
+                               "lib/racket/links.rktd"
+                               "share/links.rktd")
+                   (pkgs-dir pkgs-search-dirs "lib/racket/pkgs" "share/pkgs")
+                   ;; Partial workaround for:
+                   ;; https://github.com/racket/racket/issues/4133
+                   #;(bin-dir bin-search-dirs "bin" "bin")
+                   (bin-dir bin-search-dirs "unused-untethered-bin" "bin")
+                   (man-dir man-search-dirs "share/man" "share/man")
+                   (doc-dir doc-search-dirs "share/doc/racket" "doc")
+                   (include-dir include-search-dirs
+                                "include/racket"
+                                "include")))])
+              (match-define (list main-key search-key pth vm-pth) spec)
+              (hash-set*
+               config
+               main-key
+               (build-path-string prefix pth)
+               search-key
+               (list* #f
+                      (hash-ref config
+                                main-key
+                                (lambda ()
+                                  (if parent
+                                      (build-path-string parent pth)
+                                      (build-path-string vm-dir vm-pth))))
+                      (filter values (hash-ref config search-key null)))))]
+            [config
+             (hash-update config
                           'lib-search-dirs
-                          (append rkt
-                                  lib-dir*
-                                  extra)))]
-             [bin-dir
-              (hash-ref config 'bin-dir)]
-             [config
-              (hash-set* config
-                         'config-tethered-console-bin-dir bin-dir
-                         'config-tethered-gui-bin-dir bin-dir)]
-             [new-config-pth
-              (build-path prefix config-file-pth)])
-        (make-parent-directory* new-config-pth)
-        (call-with-output-file*
-         new-config-pth
-         (lambda (out)
-           (pretty-write config out))))))))
+                          (lambda (dirs)
+                            ;; add after other layers, but before older
+                            ;; foreign lib search directories
+                            (define-values [rkt old-foreign-dirs]
+                              (partition (lambda (pth)
+                                           (or (not pth)
+                                               (regexp-match? rx:racket pth)))
+                                         dirs))
+                            (append rkt
+                                    extra-foreign-lib-search-dirs
+                                    old-foreign-dirs)))]
+            [config
+             (hash-set* config
+                        'apps-dir
+                        (build-path-string prefix "share/applications")
+                        'absolute-installation? #t
+                        ;; Let Guix coexist with other installation
+                        ;; methods without clobbering user-specific packages
+                        ;; This could be set in various places, but doing
+                        ;; it here is convienient, at least until we support
+                        ;; cross-compilation.
+                        'installation-name
+                        (string-append (version)
+                                       (match (system-type 'gc)
+                                         ['cgc "-cgc"]
+                                         ;; workaroung Guile reader/printer:
+                                         ['|3m| "-bc"]
+                                         [_ ""])
+                                       "-guix"))]
+            [config
+             (cond
+              [tethered?
+               ;; Partial workaround for:
+               ;; https://github.com/racket/racket/issues/4133
+               #;(define bin-dir (hash-ref config 'bin-dir))
+               (define bin-dir (build-path-string prefix "bin"))
+               (hash-set* config
+                          'config-tethered-apps-dir (hash-ref config 'apps-dir)
+                          'config-tethered-console-bin-dir bin-dir
+                          'config-tethered-gui-bin-dir bin-dir)]
+              [else
+               config])])
+       (define new-config-pth
+         (build-path prefix "etc/racket/config.rktd"))
+       (make-parent-directory* new-config-pth)
+       (call-with-output-file*
+        new-config-pth
+        (lambda (out)
+          (pretty-write config out)))))))
+
+(define-public main-distribution-packages
+  (let* ((%racket-version (package-version (racket-vm-for-system)))
+         (%racket-commit (string-append "v" %racket-version)))
+    ;; on release, commit will be %racket-commit
+    (append-map
+     (match-lambda
+       ((source . pkgs)
+        (map (match-lambda
+               ((? string? name)
+                (list name (file-append source (string-append "/" name))))
+               ((name ".")
+                (list name source))
+               ((name rel-path)
+                (list name (file-append source (string-append "/" rel-path)))))
+             pkgs)))
+     `((,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/2d")
+                 (commit "9519bb9102389fb8716703176540ba3949770b82")))
+           (sha256 (base32
+                    "1zzcz5qyjv7syi41vb8jkxjp1rqgj61zbsdrg0nlc4qy9qsafzgr"))
+           (file-name
+            (git-file-name "racket-2d" %racket-version)))
+        "2d" "2d-doc" "2d-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/algol60")
+                 (commit "e9bcd18562c84eaff34f220312f102bd8db46e97")))
+           (sha256 (base32
+                    "09kj6asypmc24n29w0izc9p0q8hpga2hpkchsypfwn5c8zpvihlx"))
+           (file-name
+            (git-file-name "racket-algol60" %racket-version)))
+        ("algol60" "."))
+       (,(package-source (racket-vm-for-system))
+        ("at-exp-lib" "pkgs/at-exp-lib")
+        ("compiler" "pkgs/compiler")
+        ("compiler-lib" "pkgs/compiler-lib")
+        ("net" "pkgs/net")
+        ("net-doc" "pkgs/net-doc")
+        ("net-lib" "pkgs/net-lib")
+        ("racket-doc" "pkgs/racket-doc")
+        ("racket-index" "pkgs/racket-index")
+        ("sandbox-lib" "pkgs/sandbox-lib")
+        ("zo-lib" "pkgs/zo-lib"))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/cext-lib")
+                 (commit "0552d61f3b019167c4144fcb4e2108732d30f85c")))
+           (sha256 (base32
+                    "00w38jpv88fpl4pgj6ndnysvn0s21rjvj0xhznay80msan0vc341"))
+           (file-name (git-file-name "racket-cext-lib" %racket-version)))
+        "cext-lib" "dynext-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/class-iop")
+                 (commit "f640064b50109887c40da6df3d3cebf635040794")))
+           (sha256 (base32
+                    "08z57q83cr7wnh6g8ah3hdhmsmf9zp1jfs7yvxv188l3hzvygy5l"))
+           (file-name (git-file-name "racket-class-iop" %racket-version)))
+        "class-iop-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/compatibility")
+                 (commit "37f11132cdad7ef27386b68383d073f275d67c31")))
+           (sha256 (base32
+                    "0bfqwscjpyi325br5pa6g62g9c8lq18a80zp5g3d2qzn3n3mi6x0"))
+           (file-name (git-file-name "racket-compatibility" %racket-version)))
+        "compatibility" "compatibility-doc" "compatibility-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/contract-profile")
+                 (commit "95d980a076126b8e4e4284e912f2a7d9d3ab6860")))
+           (sha256 (base32
+                    "1xm2z8g0dpv5d9h2sg680vx1a8ix9gbsdpxxb8qv1w7akp73paj3"))
+           (file-name
+            (git-file-name "racket-contract-profile" %racket-version)))
+        ("contract-profile" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/data")
+                 (commit "e32d012b394e32e102e8a9adfcc885bb0541ab51")))
+           (sha256 (base32
+                    "10iabgrk9alaggvksnyb0hdq7f1p30pq6pq2bcakvhzpxwiv1f55"))
+           (file-name (git-file-name "racket-data" %racket-version)))
+        "data" "data-doc" "data-enumerate-lib" "data-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/datalog")
+                 (commit "7d160a86451af8298093d07674a2eb0e1a0161a4")))
+           (sha256 (base32
+                    "0n5j5gnqh7g31mvgx19ggl18hirzbvq2r189lbngmnrmbc7b73fp"))
+           (file-name (git-file-name "racket-datalog" %racket-version)))
+        ("datalog" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/db")
+                 (commit "a692d8ebf93ddde5f6cf3c2405b6651039afc2dc")))
+           (sha256 (base32
+                    "1n02ja0yj3mjjhmz0yv04yfhyvrsznbljn8bjviyfxnm4xf9rcc5"))
+           (file-name (git-file-name "racket-db" %racket-version)))
+        "db" "db-doc" "db-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/deinprogramm")
+                 (commit "2894fce2d5296c0eb5d7dcbf4828995941e5a476")))
+           (sha256 (base32
+                    "1is6fapgv6rxfjz47nh6qf3kh7y7sjdinakaxqffi46gf1al8prd"))
+           (file-name (git-file-name "racket-deinprogramm" %racket-version)))
+        "deinprogramm" "deinprogramm-signature")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/distributed-places")
+                 (commit "4e75977ab091999dfd7de765e7807fabc06a6bf3")))
+           (sha256 (base32
+                    "1dajpkj9balqcpv6cdk9hwjz592h1vq8rrx5vncariiac4vbdpa0"))
+           (file-name
+            (git-file-name "racket-distributed-places" %racket-version)))
+        "distributed-places" "distributed-places-doc" "distributed-places-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/draw")
+                 (commit "cca0deb3ff5a570c1c3c03ea0983d106492444b7")))
+           (sha256 (base32
+                    "1qai7sph1pyvc5j2pvwkxlzl2jgzj23s8nlfbdx74xk17i4p0xzp"))
+           (file-name (git-file-name "racket-draw" %racket-version)))
+        "draw" "draw-doc" "draw-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/drracket")
+                 (commit "601bc502eda4ca2739189dd17afe6cb664f5ff53")))
+           (sha256 (base32
+                    "183bhyhihp9rbhq6jbjxns57xxdxwf1j2ypbx6cdx5x4bhii9qk1"))
+           (file-name (git-file-name "racket-drracket" %racket-version)))
+        "drracket"
+        "drracket-plugin-lib"
+        "drracket-tool"
+        "drracket-tool-doc"
+        "drracket-tool-lib"
+        "drracket-tool-text-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/ds-store")
+                 (commit "949ca63dd00522b3ab8aec2d71c543ece8266872")))
+           (sha256 (base32
+                    "0ajr27kipp4dr1qlisaghsb3h7lhhjwrfw2r79b5myczsa1mp661"))
+           (file-name (git-file-name "racket-ds-store" %racket-version)))
+        "ds-store" "ds-store-doc" "ds-store-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/eli-tester")
+                 (commit "036e07d43a1f478ea1750881d5591d983ce1ffaf")))
+           (sha256 (base32
+                    "0icx6wn14gjm8kdmq1jppqgq87sxkras4qb5xmdr6wigxafhjqyk"))
+           (file-name (git-file-name "racket-eli-tester" %racket-version)))
+        ("eli-tester"  "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/eopl")
+                 (commit "d0550fdd1c2e5b20640f94ed99602d4e79ea20a4")))
+           (sha256 (base32
+                    "1fmiixj6rxsgzwvgva8lvrvv0gl49v2405mp3s0i7ipis5c4n27s"))
+           (file-name (git-file-name "racket-eopl" %racket-version)))
+        ("eopl" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/errortrace")
+                 (commit "6e89c54a5f9de8b925ad668888aa241722e5bbfc")))
+           (sha256 (base32
+                    "14m7rhaxngj36070iw15am434hm438pfgmwjfsiqhsglz4pcxhip"))
+           (file-name (git-file-name "racket-errortrace"
+                                     (package-version (racket-vm-for-system)))))
+        "errortrace" "errortrace-doc" "errortrace-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/expeditor")
+                 (commit "34973c081bdf6ffec0c69c0126d8849a00e012a3")))
+           (sha256 (base32
+                    "0wsjisd81lhr3g1alg51v8pzwz53zfjx6c36sg7fjcza4crhk1pf"))
+           (file-name (git-file-name "racket-expeditor" %racket-version)))
+        "expeditor" "expeditor-doc" "expeditor-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/frtime")
+                 (commit "a3c93aeae3e3d2a421afb7269ff282c573507cd0")))
+           (sha256 (base32
+                    "0ydz2yn8vvv6z7brwlswcyx0f31a6y6d443i89rysfvd2xkhpfd5"))
+           (file-name (git-file-name "racket-frtime" %racket-version)))
+        ("frtime" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/future-visualizer")
+                 (commit "671d32970eef64d549a5cdbe5e3d048474c7304a")))
+           (sha256 (base32
+                    "1758qq769m0r14xf64sl2ix2l9z340kvapar0j7s5kdg42lmvnhm"))
+           (file-name
+            (git-file-name "racket-future-visualizer" %racket-version)))
+        "future-visualizer" "future-visualizer-pict" "future-visualizer-typed")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/games")
+
+                 (commit "56d67ba04465aa19f1b3057df46bf235c79bba14")))
+           (sha256 (base32
+                    "0kpn3izlx1ccd0pj0dnvmnrhny51b85xy418a7psj70lz8j8415d"))
+           (file-name (git-file-name "racket-games" %racket-version)))
+        ("games" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/gui")
+                 (commit "3b27c9f593e138c71ae009ad5741bf7f7282e6b3")))
+           (sha256 (base32
+                    "1x33jgrx3r32k7hgwr591z3xqv1m2r5nc4km2fnxv0ak2xa0j3gj"))
+           (patches
+            ;; remove in Racket 8.5
+            ;; see https://github.com/racket/racket/issues/4133
+            (search-patches "racket-gui-tethered-launcher-backport.patch"))
+           (file-name (git-file-name "racket-gui" %racket-version)))
+        "gui" "gui-doc" "gui-lib" "tex-table")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/gui-pkg-manager")
+                 (commit "70cc90538c5dffb722e17cabb769aeadfef32ec4")))
+           (sha256 (base32
+                    "1ji9448d723nklqvycwdswj0ni28sabrncag14f9mx47did5myb5"))
+           (file-name
+            (git-file-name "racket-gui-pkg-manager" %racket-version)))
+        "gui-pkg-manager-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/htdp")
+                 (commit "9cf89561d818be718a07c9b8f214af83a914e86c")))
+           (sha256 (base32
+                    "0r4ykybcpr10y2db9rlza9pr0xh58nd7ac389mjcxp8g386hgihl"))
+           (file-name (git-file-name "racket-htdp" %racket-version)))
+        "htdp" "htdp-doc" "htdp-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/html")
+                 (commit "9331d4f7169f8c5932f8d2ae721b2a96515ac895")))
+           (sha256 (base32
+                    "18n1jnjgzfknc8nv8dppi85nb8q08gqdwkg6hfjk08x0p00anx2x"))
+           (file-name (git-file-name "racket-html" %racket-version)))
+        "html" "html-doc" "html-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/icons")
+                 (commit "14b164c20e1214ffa1e7585d0b6597d5c3f0351a")))
+           (sha256 (base32
+                    "1s5a6j11fg3fdr6b7vm2q7q178d7q8b8igy73bs211r27qrd1gg7"))
+           (file-name (git-file-name "racket-icons" %racket-version)))
+        ("icons" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/images")
+                 (commit "b3d032087d9544a0561b61fedc09adc2c63ed29d")))
+           (sha256 (base32
+                    "0rpjxqw34bq5m08kh1ldl1mr7s9z1lyydxxcyzb292kqh9qiqvfl"))
+           (file-name (git-file-name "racket-images" %racket-version)))
+        "images" "images-doc" "images-gui-lib" "images-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/lazy")
+                 (commit "a35720c304eafa6f9610b9ac986a89d3e0f0e889")))
+           (sha256 (base32
+                    "176ylzgbdsbmqknpihaz519afq71pyjkv1h87j5v8jfbpbddyfsf"))
+           (file-name (git-file-name "racket-lazy" %racket-version)))
+        ("lazy" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/macro-debugger")
+                 (commit "e5bbfbeeff6f4a41e7d66b1a1c3da47bdc0d5b6b")))
+           (sha256 (base32
+                    "14hyrwbkffr61fk44l02xb47bhv5zccw0ymaa9kxld86hvyqhqbm"))
+           (file-name (git-file-name "racket-macro-debugger" %racket-version)))
+        "macro-debugger" "macro-debugger-text-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/main-distribution")
+                 (commit "df36b6bb46f038f6e22a19b7b9d7d061b9631600")))
+           (sha256 (base32
+                    "0m2n9s32s8a4a2gn4ywrm9l8jycdm5ayi5w9kh5wchhrrw7qzq7y"))
+           (file-name
+            (git-file-name "racket-main-distribution" %racket-version)))
+        ("main-distribution" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/make")
+                 (commit "7493795aba151f7164caf497003746dd049b8ae4")))
+           (sha256 (base32
+                    "10852fj30bz5r46c3d99s37fkgy5yh44gb01j29sf3kxnhi0g2sa"))
+           (file-name (git-file-name "racket-make" %racket-version)))
+        ("make" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/math")
+                 (commit "67e19384a0923ccbf2ed9e8b7ce55ff92fdefe0e")))
+           (sha256 (base32
+                    "02sqbnvxvmvslk33b44fx4v93zafcvhva0cx8z21jqbl5wp217ac"))
+           (file-name (git-file-name "racket-math" %racket-version)))
+        "math" "math-doc" "math-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/mysterx")
+                 (commit "905834527683db700b87ba2b510c07aa0c688de4")))
+           (sha256 (base32
+                    "11p9jzrafw0hizhl0cs4sxx7rv281185q8hryic2rpk0kzjdyr48"))
+           (file-name (git-file-name "racket-mysterx" %racket-version)))
+        ("mysterx" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/mzcom")
+                 (commit "14a3d57e7020e5fc65d60d20849ca6378f4d4def")))
+           (sha256 (base32
+                    "0rc9pfj7gwm5azghqvcibz6si1x5s2v8mr2yngk7ssq9gzfbi6a4"))
+           (file-name (git-file-name "racket-mzcom" %racket-version)))
+        ("mzcom" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/mzscheme")
+                 (commit "b7e47a2244d848820f7eb1c80cad62b7cfdcb987")))
+           (sha256 (base32
+                    "192c52zi726h5wjamxrhivjw2waq1im0zpyxhbrkrxknm8x84bs9"))
+           (file-name (git-file-name "racket-mzscheme" %racket-version)))
+        "mzscheme" "mzscheme-doc" "mzscheme-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/RenaissanceBug/racket-cookies")
+                 (commit "06e14b37fbd237b74563661c522df02855dadd2f")))
+           (sha256 (base32
+                    "0k0hifxhywl5c3hjcaiizc098dpyk001d981p572gly116yvjxc1"))
+           (file-name
+            (git-file-name "RenaissanceBug-racket-cookies" %racket-version)))
+        "net-cookies" "net-cookies-doc" "net-cookies-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/stamourv/optimization-coach")
+                 (commit "dbd6cf06613bf285b4540301ea86dd87239eab7d")))
+           (sha256 (base32
+                    "0b27sw48d7rhz0hin88c7rbr9vpg1c23sn82nd4jkmq54h6gasr1"))
+           (file-name
+            (git-file-name "stamourv-optimization-coach" %racket-version)))
+        ("optimization-coach" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/option-contract")
+                 (commit "399ad3351df83dee3dd2e8c4bec14ad5bcd2be8e")))
+           (sha256 (base32
+                    "026b7n5l0c3024nymshz8zp1yhn493rdzgpflzfd52hj7awafqhk"))
+           (file-name
+            (git-file-name "racket-option-contract" %racket-version)))
+        "option-contract" "option-contract-doc" "option-contract-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/parser-tools")
+                 (commit "4f9bcab9167b690b16b79a13ce91e8ec765c00a3")))
+           (sha256 (base32
+                    "08pvz4zramirzm3j64hbhjm0mmh5zfy37iv4s3vmq0rj49cr8fl3"))
+           (file-name (git-file-name "racket-parser-tools" %racket-version)))
+        "parser-tools" "parser-tools-doc" "parser-tools-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/pconvert")
+                 (commit "d8ab4fd6f5e2f35d9738db1677dfb89e3c4ce011")))
+           (sha256 (base32
+                    "00czi0p399mmyrvxyrs5kniizpkqfxyz2ncxqi2jy79a7wk79pb1"))
+           (file-name (git-file-name "racket-pconvert" %racket-version)))
+        "pconvert-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/pict")
+                 (commit "9e0de9ea7204219a95d734c250afac740cb35534")))
+           (sha256 (base32
+                    "0g1iwdr6qh1xb0crhj96830vjjnbds409xbpqn7j5sh0ksy6vr5x"))
+           (file-name (git-file-name "racket-pict" %racket-version)))
+        "pict" "pict-doc" "pict-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/pict-snip")
+                 (commit "cd389ba6471a045c791e2dd6e483e356017499d8")))
+           (sha256 (base32
+                    "081nwiy4a0n4f7xws16hqbhf0j3kz5alizndi3nnyr3chm4kng6x"))
+           (file-name (git-file-name "racket-pict-snip" %racket-version)))
+        "pict-snip" "pict-snip-doc" "pict-snip-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/picturing-programs")
+                 (commit "f2ce24d8e7cbefe585e3d849324b61ad2e680556")))
+           (sha256 (base32
+                    "1g6xr39hx1j03gb3d4dljm3v91xcj2gfpq3dgy5xvplzr6cmmxgr"))
+           (file-name
+            (git-file-name "racket-picturing-programs" %racket-version)))
+        ("picturing-programs" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/plai")
+                 (commit "9f227e6403a07735765a57ff521d5f78588543c6")))
+           (sha256 (base32
+                    "0i983sh0r0zm2ng4j44m5aw9669kh5fhp91bzpc9jm280rfcqvyl"))
+           (file-name (git-file-name "racket-plai" %racket-version)))
+        "plai" "plai-doc" "plai-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/planet")
+                 (commit "350f5da48d98303fe6ee510892c958ed46766154")))
+           (sha256 (base32
+                    "0r2yqrzrmdjjyr14k6hhlzc5kzrcx3583m1s02mhrcmpfw0s85w9"))
+           (file-name (git-file-name "racket-planet" %racket-version)))
+        "planet" "planet-doc" "planet-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/plot")
+                 (commit "6da78b761a6005fdfe771318097513adf38c9564")))
+           (sha256 (base32
+                    "07kq32si34ybcwz8idxxcrzssg8diyrp1nfgkcj0mmvr45321zm7"))
+           (file-name (git-file-name "racket-plot" %racket-version)))
+        "plot" "plot-compat" "plot-doc" "plot-gui-lib" "plot-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/preprocessor")
+                 (commit "8e683244eea9dd5526324529f972947f7111810f")))
+           (sha256 (base32
+                    "1p5aid58ifnjy4xl0ysh85cq39k25661v975jrpk182z3k5621mg"))
+           (file-name (git-file-name "racket-preprocessor" %racket-version)))
+        ("preprocessor" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/profile")
+                 (commit "a9fc521dbeb859ea6683cee4a83ed24d1e15ca12")))
+           (sha256 (base32
+                    "179i86lyby29nywz60l4vnadi02w8b12h7501nm5h5g4pq9jjmbb"))
+           (file-name (git-file-name "racket-profile" %racket-version)))
+        "profile" "profile-doc" "profile-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/Metaxal/quickscript")
+                 (commit "24912978e7b104449e801cf0a8469b8f363aa170")))
+           (sha256 (base32
+                    "100g3yqhbjdq06b6l6d72ywsw29awgy8crqg33wj7h12xq07nzcr"))
+           (file-name (git-file-name "Metaxal-quickscript" %racket-version)))
+        ("quickscript" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/r5rs")
+                 (commit "26ca7fc5a03cc7ae797e9269444d97e6728a1b0d")))
+           (sha256 (base32
+                    "1g3cysj7z88r38vkzvi8g2fb2hn4yg1fdhy5smxw303jxgl3inp6"))
+           (file-name (git-file-name "racket-r5rs" %racket-version)))
+        "r5rs" "r5rs-doc" "r5rs-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/r6rs")
+                 (commit "f4d66a2c31749e3795722092b0a9d4fa698c2992")))
+           (sha256 (base32
+                    "0b1ymzdp10r0flw2acbidjsh5ma1pm5hy54jss37sxf89z3xbvm4"))
+           (file-name (git-file-name "racket-r6rs" %racket-version)))
+        "r6rs" "r6rs-doc" "r6rs-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/jeapostrophe/racket-cheat")
+                 (commit "6e79a13b9e24969a87c8a1c191d38ee4f4c55cf9")))
+           (sha256 (base32
+                    "06wcj558rzkbl2bwkmikyspya9v1f4iwlzwnwxpkc33h2xapwabr"))
+           (file-name
+            (git-file-name "jeapostrophe-racket-cheat" %racket-version)))
+        ("racket-cheat" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/racklog")
+                 (commit "4bad4b9e9bcc363df453ae5e4211641cddc29e4b")))
+           (sha256 (base32
+                    "1rgrvwy3kr9b9w5cghsffiv3ly00yfvvzr5xaaw83g1w7yin0mnb"))
+           (file-name (git-file-name "racket-racklog" %racket-version)))
+        ("racklog" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/rackunit")
+                 (commit "6c04ee267d258a13f9c5cbc437dac60234e54ef4")))
+           (sha256 (base32
+                    "057z31rja6h3nabh5b2xgwfrzmlm6h1cv1qcgf3xfy4g2q5dqn5p"))
+           (file-name (git-file-name "racket-rackunit" %racket-version)))
+        "rackunit"
+        "rackunit-doc"
+        "rackunit-gui"
+        "rackunit-lib"
+        "rackunit-plugin-lib"
+        "rackunit-typed"
+        "schemeunit"
+        "testing-util-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/readline")
+                 (commit "df55a811d57d6677959fde479106bc43b99d6bdd")))
+           (sha256 (base32
+                    "13kbcn2wchv82d709mw3r8n37bk8iwq0y4kpvm9dbzx0w2pxkfwn"))
+           (file-name (git-file-name "racket-readline" %racket-version)))
+        "readline" "readline-doc" "readline-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/realm")
+                 (commit "81afce5b4c4fc3e9a06e813b888d7c8ea10b6a32")))
+           (sha256 (base32
+                    "0hxcgla08iack54j8v40fj51811chpy66ym2zq76zb52c7kzn0hi"))
+           (file-name (git-file-name "racket-realm" %racket-version)))
+        ("realm" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/redex")
+                 (commit "85446b0caf8560c30d7e2ed9c23104bf20b27ae6")))
+           (sha256 (base32
+                    "1jv0b043ppph75bjzfdc0jibgpig34lnsbksxnqz03pmv3yxp6cr"))
+           (file-name (git-file-name "racket-redex" %racket-version)))
+        "redex"
+        "redex-benchmark"
+        "redex-doc"
+        "redex-examples"
+        "redex-gui-lib"
+        "redex-lib"
+        "redex-pict-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/sasl")
+                 (commit "3fd78eb8a0ba7ad86d8f78e866d737b177144729")))
+           (sha256 (base32
+                    "0ibh4wb4gn8pggx6gkv4vk4d6rwzn5nrvjibhvkzhaynf6lhb824"))
+           (file-name (git-file-name "racket-sasl" %racket-version)))
+        "sasl" "sasl-doc" "sasl-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/scheme-lib")
+                 (commit "408f9398ec237b791ca103bb9e1400df1cef18f5")))
+           (sha256 (base32
+                    "0pcf0y8rp4qyjhaz5ww5sr5diq0wpcdfrrnask7zapyklzx1jx8x"))
+           (file-name (git-file-name "racket-scheme-lib" %racket-version)))
+        ("scheme-lib" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/scribble")
+                 (commit "d2d820bdedf7ec4971ed03e9a0adcfb5f71ed1fa")))
+           (sha256 (base32
+                    "15rhf4lhrwqab9vdq42mf227ialm6yi5q8hxsb4kw4yq6dks4xcd"))
+           (file-name (git-file-name "racket-scribble" %racket-version)))
+        "scribble" "scribble-doc" "scribble-html-lib" "scribble-lib"
+        "scribble-text-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/serialize-cstruct-lib")
+                 (commit "cabf4188a34c70af2f6a376fc3b0f55d035a2ab7")))
+           (sha256 (base32
+                    "1rq3n1fa7ldjwx3lrh9ybhig7jlsw1crpzyklbzp3xqdw6jymfnz"))
+           (file-name
+            (git-file-name "racket-serialize-cstruct-lib" %racket-version)))
+        ("serialize-cstruct-lib" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/sgl")
+                 (commit "d1906923a74a362a2bfb32f3b9bfe1351f4d1534")))
+           (sha256 (base32
+                    "0nkymhdyjrwi5h199j4w5zh7y3x3ai42gsiwxzh0hy7yqrqqg9zv"))
+           (file-name (git-file-name "racket-sgl" %racket-version)))
+        ("sgl" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/shell-completion")
+                 (commit "3bc582e4167a46ade43dfd50df06a2e6e08e90ab")))
+           (sha256 (base32
+                    "04m144gy2mp4fiq6rcbf12wjr8mws8k9scfhg9lc38vqppp4lxsj"))
+           (file-name
+            (git-file-name "racket-shell-completion" %racket-version)))
+        ("shell-completion" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/simple-tree-text-markup")
+                 (commit "06bbcd3651e518a53cffa5f8484fe127574fed06")))
+           (sha256 (base32
+                    "0fyd9gfz6bnv0m1901wv5mnhc05rm8hw9i6ddrqx33hs6qsg2zqr"))
+           (file-name
+            (git-file-name "racket-simple-tree-text-markup" %racket-version)))
+        "simple-tree-text-markup"
+        "simple-tree-text-markup-doc"
+        "simple-tree-text-markup-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/slatex")
+                 (commit "47e1d3e3e33d826bc2b26f9e8998eb235b23a9a5")))
+           (sha256 (base32
+                    "0pkm2isbbdk63slrbsxcql7rr0wdrw5kapw1xq4ps5k8dhlzv8x0"))
+           (file-name (git-file-name "racket-slatex" %racket-version)))
+        ("slatex" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/slideshow")
+                 (commit "e8b2471aaafef035e12e641dd34226f36a9ca16a")))
+           (sha256 (base32
+                    "1znv1i2d0610hhy71q932xy7wka00q3q50in1xfnk8ibg7nzkagm"))
+           (file-name (git-file-name "racket-slideshow" %racket-version)))
+        "slideshow" "slideshow-doc" "slideshow-exe" "slideshow-lib"
+        "slideshow-plugin")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/snip")
+                 (commit "d553e3bd27c866cb93d5144c0f07e4024827167b")))
+           (sha256 (base32
+                    "01r9wc5xr3q3n4yyif6j0a37rgdzmpslxn05k13ksik73b3wj6hj"))
+           (file-name (git-file-name "racket-snip" %racket-version)))
+        "snip" "snip-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/typed-racket")
+                 (commit "4b07b7b6cab5c08b5b589d3f501376fc0a2b935d")))
+           (sha256 (base32
+                    "0vvy7byynbk7rx2a0cr3ky2ifgmhcrw22xyiibd4c4knqqkdcmc7"))
+           (file-name (git-file-name "racket-typed-racket" %racket-version)))
+        "source-syntax"
+        "typed-racket"
+        "typed-racket-compatibility"
+        "typed-racket-doc"
+        "typed-racket-lib"
+        "typed-racket-more")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 ;;(url "https://github.com/racket/srfi")
+                 (url "https://github.com/LiberalArtist/srfi")
+                 ;; FSDG fix for SRFI 5:
+                 ;; see https://github.com/racket/srfi/pull/15 and
+                 ;; https://lists.gnu.org/archive/html/guix-devel/2022-01/msg00426.html
+                 ;; (Probably can be merged upstream before we update to 8.4.)
+                 (commit "8de2fb2c566f285ee3fc14bad15d74e21de014cd")))
+           (sha256 (base32
+                    "07xi9pdg5sqcy1njppmqaaigrf054d6h74wfcwq5ikg2kjgc0d5w"))
+           (file-name (git-file-name "racket-srfi" %racket-version)))
+        "srfi" "srfi-doc" "srfi-lib" "srfi-lite-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/string-constants")
+                 (commit "90fdb2613beaefe57fa0305fe90e635e2b8a8f57")))
+           (sha256 (base32
+                    "1qizjq4n0hzdgdcjjpr94464gsywpsk2g9mnvwzqr7dcqbrsfvn6"))
+           (file-name
+            (git-file-name "racket-string-constants" %racket-version)))
+        "string-constants" "string-constants-doc" "string-constants-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/swindle")
+                 (commit "122e38efb9842394ef6462053991efb4bd0edf3b")))
+           (sha256 (base32
+                    "164gdsphjzdl2vv7zxz7dfk9jwax8njpmim6sidm8qz8a8589y67"))
+           (file-name (git-file-name "racket-swindle" %racket-version)))
+        ("swindle" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/syntax-color")
+                 (commit "c3ba4e86790946ed77192b541f49930e5861619d")))
+           (sha256 (base32
+                    "1dwl0v2ghdyyk5x5rw20il192wrq9myijz98dfncy5cz0hqlm25f"))
+           (file-name (git-file-name "racket-syntax-color" %racket-version)))
+        "syntax-color" "syntax-color-doc" "syntax-color-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/trace")
+                 (commit "7878c9ed33da27810a55d8bdd603f56dd4c89fb7")))
+           (sha256 (base32
+                    "070ihla5j796hdarn5wxdwn4xj0xnkm50shgh49jy994mribvhia"))
+           (file-name (git-file-name "racket-trace" %racket-version)))
+        ("trace" "."))
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/unix-socket")
+                 (commit "698eade65ae2cd8b747ba08a3820950e385b2a81")))
+           (sha256 (base32
+                    "02dfwas5ynbpyz74w9kwb4wgb37y5wys7svrlmir8k0n9ph9vq0y"))
+           (file-name (git-file-name "racket-unix-socket" %racket-version)))
+        "unix-socket" "unix-socket-doc" "unix-socket-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/web-server")
+                 (commit "655676cdebe6d6223935ec5b288d574639ced431")))
+           (sha256 (base32
+                    "1zgb6jl7zx6258ljs8f3lvryrq5n5zpd71dqzr698m92kw3x2pkn"))
+           (file-name (git-file-name "racket-web-server" %racket-version)))
+        "web-server" "web-server-doc" "web-server-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/wxme")
+                 (commit "555a380a63e63977fec77c4063d58f6bdf646249")))
+           (sha256 (base32
+                    "1qp5gr9gqsakiq3alw6m4yyv5vw4i3hp4y4nhq8vl2nkjmirvn0b"))
+           (file-name (git-file-name "racket-wxme" %racket-version)))
+        "wxme" "wxme-lib")
+       (,(origin
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/racket/xrepl")
+                 (commit "3f3d7c2619ca73df982dc1dc67ed8040709b6d38")))
+           (sha256 (base32
+                    "1sw0g0cnkq6xc8x8i2mfz7qkimrv1c7gbhqfkm0zwafzi2zbvbh7"))
+           (file-name (git-file-name "racket-xrepl" %racket-version)))
+        "xrepl" "xrepl-doc" "xrepl-lib")))))
-- 
2.32.0
L
L
Liliana Marie Prikler wrote on 9 Feb 14:42 +0100
Re: [RFC PATCH 8/9] gnu: Add chez-scheme-racket-variant.
769cda9ec17a152dc999592827759234436da712.camel@ist.tugraz.at
Am Dienstag, dem 08.02.2022 um 10:18 -0500 schrieb Philip McGrath:
Toggle quote (33 lines)
> The Racket variant of Chez Scheme can be used to support platforms
> that
> are not yet supported by upstream Chez Scheme. The new function
> 'chez-scheme-for-system' selects the Chez Scheme package that best
> supports the target system.
>
> In the process, we also add packages for 'racket-vm-cgc',
> 'racket-vm-bc', and 'racket-vm-cs'. A future commit will change
> 'racket-minimal' to use the Racket VM implementation that best
> supports
> the target system, as reported by 'racket-vm-for-system'.
>
> * gnu/packages/patches/racket-enable-scheme-backport.patch: New
> patch.
> * gnu/local.mk (dist_patch_DATA): Add it.
> * gnu/packages/chez-and-racket-bootstrap.scm (racket-vm-cgc):
> (racket-vm-bc):
> (racket-vm-cs):
> (chez-scheme-racket-variant-bootstrap-bootfiles):
> (chez-scheme-racket-variant): New variables.
> (chez-scheme-for-system, racket-vm-for-system): New exported
> functions.
> * gnu/packages/loko.scm (loko-scheme): Use 'chez-scheme-for-system'.
> * gnu/packages/emacs-xyz.scm (emacs-geiser-chez): Likewise
> * gnu/packages/chez.scm (chez-srfi):
> (chez-web):
> (chez-sockets):
> (chez-matchable):
> (chez-irregex):
> (chez-fmt):
> (chez-mit):
> (chez-scmutils): Likewise.
> (chez-mit)[origin]<snippet>: Add workaround for Racket variant.
This patch does a lot and should probably be separated into several
commits. As far as the name "chez-scheme-racket-variant" is concerned,
I am not really a fan of it. How would "chez-scheme-for-racket" sound?
P
P
Philip McGrath wrote on 10 Feb 02:30 +0100
6abafa84-4f63-2bf0-4464-9c7742798902@philipmcgrath.com
Hi,

On 2/9/22 08:42, Liliana Marie Prikler wrote:
Toggle quote (6 lines)
> Am Dienstag, dem 08.02.2022 um 10:18 -0500 schrieb Philip McGrath:
> This patch does a lot and should probably be separated into several
> commits. As far as the name "chez-scheme-racket-variant" is concerned,
> I am not really a fan of it. How would "chez-scheme-for-racket" sound?
>

Thanks for taking a look!

Calling it "chez-scheme-for-racket" is fine with me---it's a little
shorter, at least.

As far as splitting it up, yes, that makes sense. (There had at one
point been some entanglements that I thought would make that difficult,
but I've since fixed all those issues anyway.) What do you think of
splitting it like this?

>> * gnu/packages/patches/racket-enable-scheme-backport.patch: New
>> patch.
>> * gnu/local.mk (dist_patch_DATA): Add it.
>> * gnu/packages/chez-and-racket-bootstrap.scm (racket-vm-cgc):
---
>> (racket-vm-bc):
---
>> (racket-vm-cs):
---
>> (chez-scheme-racket-variant-bootstrap-bootfiles):
>> (chez-scheme-racket-variant): New variables.
---
>> (chez-scheme-for-system,
---
>> (chez-mit)[origin]<snippet>: Add workaround for Racket variant.
---
>> * gnu/packages/loko.scm (loko-scheme): Use 'chez-scheme-for-system'.
>> * gnu/packages/emacs-xyz.scm (emacs-geiser-chez): Likewise
>> * gnu/packages/chez.scm (chez-srfi):
>> (chez-web):
>> (chez-sockets):
>> (chez-matchable):
>> (chez-irregex):
>> (chez-fmt):
>> (chez-mit):
>> (chez-scmutils): Likewise.
---
>> racket-vm-for-system): New exported
>> functions.

Alternatively, I could see adding the snippet to "chez-mit" in the same
commit as changing it to use "chez-scheme-for-system", or I could split
each changed package into its own commit (though those would be
extremely small), or put the definition of "chez-scheme-for-system"
together with its uses, or ...

Racket 8.4 was just released,[0] so I plan to send a revised series
today or tomorrow.

-Philip

L
L
Liliana Marie Prikler wrote on 10 Feb 08:08 +0100
aa99da7a8bf48cb2f375dfad0bca7ddd67c48916.camel@ist.tugraz.at
Hi,

Am Mittwoch, dem 09.02.2022 um 20:30 -0500 schrieb Philip McGrath:
Toggle quote (2 lines)
> Calling it "chez-scheme-for-racket" is fine with me---it's a little
> shorter, at least.
Okay.

Toggle quote (4 lines)
> As far as splitting it up, yes, that makes sense. (There had at one
> point been some entanglements that I thought would make that
> difficult, but I've since fixed all those issues anyway.) What do you
> think of splitting it like this?
I'm not entirely sure how the interdependencies are, but I'd do...

Toggle quote (11 lines)
>  >> * gnu/packages/patches/racket-enable-scheme-backport.patch: New
>  >> patch.
>  >> * gnu/local.mk (dist_patch_DATA): Add it.
>  >> * gnu/packages/chez-and-racket-bootstrap.scm (racket-vm-cgc):
> ---
>  >> (racket-vm-bc):
> ---
>  >> (racket-vm-cs):
> ---
>  >> (chez-scheme-for-racket-bootstrap-bootfiles):
>  >> (chez-scheme-for-racket): New variables.
These, then
Toggle quote (2 lines)
> >> (chez-mit)[origin]<snippet>: Add workaround for chez-scheme-for-
> racket.
then
Toggle quote (15 lines)
> ---
>  >> (chez-scheme-for-system, racket-vm-for-system): New variables.
> ---
>  >> * gnu/packages/loko.scm (loko-scheme): Use 'chez-scheme-for-
> system'.
>  >> * gnu/packages/emacs-xyz.scm (emacs-geiser-chez): Likewise
>  >> * gnu/packages/chez.scm (chez-srfi):
>  >> (chez-web):
>  >> (chez-sockets):
>  >> (chez-matchable):
>  >> (chez-irregex):
>  >> (chez-fmt):
>  >> (chez-mit):
>  >> (chez-scmutils): Likewise.
> ---
If that's not possible, you can keep racket-vm-for-system as the final
patch.

Toggle quote (2 lines)
> Racket 8.4 was just released,[0] so I plan to send a revised series
> today or tomorrow.
Cool.

Toggle quote (1 lines)
P
P
Philip McGrath wrote on 13 Feb 22:51 +0100
[PATCH 00/11] Update Racket to 8.4. Adjust Chez Scheme packages.
(address . 53878@debbugs.gnu.org)
20220213215127.218952-1-philip@philipmcgrath.com
Hi,

Here's a revised series with the actual Racket 8.4 release!

I've split the 'chez-scheme-for-racket' patch basically as Liliana suggested
in https://issues.guix.gnu.org/53878#12 except that I've added
'racket-vm-for-system' in the commit which actually uses it (the final one),
rather than the commit that adds 'chez-scheme-for-system'.

-Philip

Philip McGrath (11):
gnu: chez-scheme: Move to (gnu packages chez-and-racket-bootstrap).
gnu: chez-scheme: Use "lib/chez-scheme" for search path.
gnu: chez-scheme: Use shared zlib and lz4.
gnu: chez-and-racket-bootstrap: Add utilities for Chez machine types.
gnu: Add stex.
gnu: Add chez-nanopass.
gnu: chez-scheme: Explicitly package bootstrap bootfiles.
gnu: Add chez-scheme-for-racket.
gnu: chez-mit: Support chez-scheme-for-racket.
gnu: chez-and-racket-bootstrap: Add 'chez-scheme-for-system'.
gnu: racket: Update to 8.4.

gnu/local.mk | 6 +-
gnu/packages/chez-and-racket-bootstrap.scm | 1103 +
gnu/packages/chez.scm | 628 +-
gnu/packages/emacs-xyz.scm | 4 +-
gnu/packages/loko.scm | 4 +-
.../racket-enable-scheme-backport.patch | 465 +
...acket-gui-tethered-launcher-backport.patch | 26 +
.../patches/racket-srfi-fsdg-backport.patch | 41622 ++++++++++++++++
gnu/packages/racket.scm | 1554 +-
9 files changed, 44470 insertions(+), 942 deletions(-)
create mode 100644 gnu/packages/chez-and-racket-bootstrap.scm
create mode 100644 gnu/packages/patches/racket-enable-scheme-backport.patch
create mode 100644 gnu/packages/patches/racket-gui-tethered-launcher-backport.patch
create mode 100644 gnu/packages/patches/racket-srfi-fsdg-backport.patch

--
2.32.0
P
P
Philip McGrath wrote on 13 Feb 22:51 +0100
[PATCH 01/11] gnu: chez-scheme: Move to (gnu packages chez-and-racket-bootstrap).
(address . 53878@debbugs.gnu.org)
20220213215127.218952-2-philip@philipmcgrath.com
* gnu/packages/chez.scm (nanopass, stex, chez-scheme): Move to ...
* gnu/packages/chez-and-racket-bootstrap.scm: ... this new file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add it.
* gnu/packages/emacs-xyz.scm: Adjust imports accordingly.
* gnu/packages/loko.scm: Likewise.
* gnu/packages/racket.scm: Likewise.
---
gnu/local.mk | 1 +
gnu/packages/chez-and-racket-bootstrap.scm | 278 +++++++++++++++++++++
gnu/packages/chez.scm | 225 +----------------
gnu/packages/emacs-xyz.scm | 2 +-
gnu/packages/loko.scm | 2 +-
gnu/packages/racket.scm | 2 +-
6 files changed, 283 insertions(+), 227 deletions(-)
create mode 100644 gnu/packages/chez-and-racket-bootstrap.scm

Toggle diff (585 lines)
diff --git a/gnu/local.mk b/gnu/local.mk
index 1b08b40b9c..72e086d465 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -144,6 +144,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/certs.scm			\
   %D%/packages/check.scm			\
   %D%/packages/chemistry.scm			\
+  %D%/packages/chez-and-racket-bootstrap.scm	\
   %D%/packages/chez.scm				\
   %D%/packages/chicken.scm				\
   %D%/packages/chromium.scm			\
diff --git a/gnu/packages/chez-and-racket-bootstrap.scm b/gnu/packages/chez-and-racket-bootstrap.scm
new file mode 100644
index 0000000000..f102b099fb
--- /dev/null
+++ b/gnu/packages/chez-and-racket-bootstrap.scm
@@ -0,0 +1,278 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2016 Federico Beffa <beffa@fbengineering.ch>
+;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2017, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
+;;; Copyright © 2019 Brett Gilio <brettg@gnu.org>
+;;; Copyright © 2020 Brendan Tildesley <mail@brendan.scot>
+;;; Copyright © 2021, 2022 Philip McGrath <philip@philipmcgrath.com>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages chez-and-racket-bootstrap)
+  #:use-module (guix packages)
+  #:use-module (guix download)
+  #:use-module (guix git-download)
+  #:use-module (guix utils)
+  #:use-module (guix gexp)
+  #:use-module (ice-9 match)
+  #:use-module (srfi srfi-1)
+  #:use-module (guix build-system gnu)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages compression)
+  #:use-module (gnu packages ghostscript)
+  #:use-module (gnu packages linux)
+  #:use-module (gnu packages ncurses)
+  #:use-module (gnu packages netpbm)
+  #:use-module (gnu packages tex)
+  #:use-module (gnu packages xorg)
+  #:use-module ((guix licenses)
+                #:prefix license:))
+
+;; Commentary:
+;;
+;; Alphabetically and chronologically, Chez comes before Racket.
+;;
+;; The bootstrapping paths for Chez Scheme and Racket are closely
+;; entwined. Racket CS (the default Racket implementation) is based on (a fork
+;; of) Chez Scheme. Racket's variant of Chez Scheme shares sources for
+;; nanopass and stex with upstream Chez Scheme.
+;;
+;; Racket's variant of Chez Scheme can be bootstrapped by an older Racket
+;; implementation, Racket BC, which can be bootstrapped from C. Porting that
+;; code to work with upstream Chez Scheme (or finding an old version that
+;; does) is our best hope for some day bootstrapping upstream Chez Scheme from
+;; source.
+;;
+;; Putting the relevant definitions together in this module avoids having to
+;; work around dependency cycles.
+;;
+;; Code:
+
+(define nanopass
+  (let ((version "1.9.2"))
+    (origin
+      (method git-fetch)
+      (uri (git-reference
+            (url "https://github.com/nanopass/nanopass-framework-scheme")
+            (commit (string-append "v" version))))
+      (sha256 (base32 "16vjsik9rrzbabbhbxbaha51ppi3f9n8rk59pc6zdyffs0vziy4i"))
+      (file-name (git-file-name "nanopass" version)))))
+
+(define stex
+  ;; This commit includes a fix, which we would otherwise want to use as
+  ;; patch.  Let's revert to tagged releases as soon as one becomes available.
+  (let* ((commit "54051494434a197772bf6ca5b4e6cf6be55f39a5")
+         (version "1.2.2")
+         (version (git-version version "1" commit)))
+    (origin
+      (method git-fetch)
+      (uri (git-reference
+            (url "https://github.com/dybvig/stex")
+            (commit commit)))
+      (sha256 (base32 "01jnvw8qw33gnpzwrakwhsr05h6b609lm180jnspcrb7lds2p23d"))
+      (file-name (git-file-name "stex" version)))))
+
+(define-public chez-scheme
+  (package
+    (name "chez-scheme")
+    (version "9.5.6")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/cisco/ChezScheme")
+             (commit (string-append "v" version))))
+       (sha256
+        (base32 "07s433hn1z2slfc026sidrpzxv3a8narcd40qqr1xrpb9012xdky"))
+       (file-name (git-file-name name version))
+       (snippet
+        ;; Remove bundled libraries.
+        (with-imported-modules '((guix build utils))
+          #~(begin
+              (use-modules (guix build utils))
+              (for-each (lambda (dir)
+                          (when (directory-exists? dir)
+                            (delete-file-recursively dir)))
+                        '("stex"
+                          "nanopass"
+                          "lz4"
+                          "zlib")))))))
+    (build-system gnu-build-system)
+    (inputs
+     `(("libuuid" ,util-linux "lib")
+       ("zlib" ,zlib)
+       ("zlib:static" ,zlib "static")
+       ("lz4" ,lz4)
+       ("lz4:static" ,lz4 "static")
+       ;; for expeditor:
+       ("ncurses" ,ncurses)
+       ;; for X11 clipboard support in expeditor:
+       ;; https://github.com/cisco/ChezScheme/issues/9#issuecomment-222057232
+       ("libx11" ,libx11)))
+    (native-inputs
+     `(("nanopass" ,nanopass) ; source only
+       ;; for docs
+       ("stex" ,stex)
+       ("xorg-rgb" ,xorg-rgb)
+       ("texlive" ,(texlive-updmap.cfg (list texlive-dvips-l3backend
+                                             texlive-epsf
+                                             texlive-fonts-ec
+                                             texlive-oberdiek)))
+       ("ghostscript" ,ghostscript)
+       ("netpbm" ,netpbm)))
+    (native-search-paths
+     (list (search-path-specification
+            (variable "CHEZSCHEMELIBDIRS")
+            (files (list (string-append "lib/csv" version "-site"))))))
+    (outputs '("out" "doc"))
+    (arguments
+     `(#:modules
+       ((guix build gnu-build-system)
+        (guix build utils)
+        (ice-9 ftw)
+        (ice-9 match))
+       #:test-target "test"
+       #:configure-flags
+       '("--threads") ;; TODO when we fix armhf, it doesn't support --threads
+       #:phases
+       (modify-phases %standard-phases
+         ;; put these where configure expects them to be
+         (add-after 'unpack 'unpack-nanopass+stex
+           (lambda* (#:key native-inputs inputs #:allow-other-keys)
+             (for-each (lambda (dep)
+                         (define src
+                           (assoc-ref (or native-inputs inputs) dep))
+                         (copy-recursively src dep
+                                           #:keep-mtime? #t))
+                       '("nanopass" "stex"))))
+         ;; NOTE: the custom Chez 'configure' script doesn't allow
+         ;; unrecognized flags, such as those automatically added
+         ;; by `gnu-build-system`.
+         (replace 'configure
+           (lambda* (#:key inputs outputs
+                           (configure-flags '())
+                           #:allow-other-keys)
+             (let* ((zlib-static (assoc-ref inputs "zlib:static"))
+                    (lz4-static (assoc-ref inputs "lz4:static"))
+                    (out (assoc-ref outputs "out"))
+                    ;; add flags which are always required:
+                    (flags (cons*
+                            (string-append "--installprefix=" out)
+                            (string-append "ZLIB=" zlib-static "/lib/libz.a")
+                            (string-append "LZ4=" lz4-static "/lib/liblz4.a")
+                            ;; Guix will do compress man pages,
+                            ;; and letting Chez try causes an error
+                            "--nogzip-man-pages"
+                            configure-flags)))
+               (format #t "configure flags: ~s~%" flags)
+               ;; Some makefiles (for tests) don't seem to propagate CC
+               ;; properly, so we take it out of their hands:
+               (setenv "CC" ,(cc-for-target))
+               (setenv "HOME" "/tmp")
+               (apply invoke
+                      "./configure"
+                      flags))))
+         ;; The binary file name is called "scheme" as is the one from MIT/GNU
+         ;; Scheme.  We add a symlink to use in case both are installed.
+         (add-after 'install 'install-symlink
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (bin (string-append out "/bin"))
+                    (lib (string-append out "/lib"))
+                    (name "chez-scheme"))
+               (symlink (string-append bin "/scheme")
+                        (string-append bin "/" name))
+               (map (lambda (file)
+                      (symlink file (string-append (dirname file)
+                                                   "/" name ".boot")))
+                    (find-files lib "scheme.boot")))))
+         ;; Building explicitly lets us avoid using substitute*
+         ;; to re-write makefiles.
+         (add-after 'install-symlink 'prepare-stex
+           (lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
+             (let* ((stex+version
+                     (strip-store-file-name
+                      (assoc-ref (or native-inputs inputs) "stex")))
+                    ;; Eventually we want to install stex as a real
+                    ;; package so it's reusable. For now:
+                    (stex-output "/tmp")
+                    (doc-dir (string-append stex-output
+                                            "/share/doc/"
+                                            stex+version)))
+               (with-directory-excursion "stex"
+                 (invoke "make"
+                         "install"
+                         (string-append "LIB="
+                                        stex-output
+                                        "/lib/"
+                                        stex+version)
+                         (string-append "Scheme="
+                                        (assoc-ref outputs "out")
+                                        "/bin/scheme"))
+                 (for-each (lambda (pth)
+                             (install-file pth doc-dir))
+                           '("ReadMe" ; includes the license
+                             "doc/stex.html"
+                             "doc/stex.css"
+                             "doc/stex.pdf"))))))
+         ;; Building the documentation requires stex and a running scheme.
+         ;; FIXME: this is probably wrong for cross-compilation
+         (add-after 'prepare-stex 'install-doc
+           (lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
+             (let* ((chez+version (strip-store-file-name
+                                   (assoc-ref outputs "out")))
+                    (stex+version
+                     (strip-store-file-name
+                      (assoc-ref (or native-inputs inputs) "stex")))
+                    (scheme (string-append (assoc-ref outputs "out")
+                                           "/bin/scheme"))
+                    ;; see note on stex-output in phase build-stex, above:
+                    (stexlib (string-append "/tmp"
+                                            "/lib/"
+                                            stex+version))
+                    (doc-dir (string-append (assoc-ref outputs "doc")
+                                            "/share/doc/"
+                                            chez+version)))
+               (define* (stex-make #:optional (suffix ""))
+                 (invoke "make"
+                         "install"
+                         (string-append "Scheme=" scheme)
+                         (string-append "STEXLIB=" stexlib)
+                         (string-append "installdir=" doc-dir suffix)))
+               (with-directory-excursion "csug"
+                 (stex-make "/csug"))
+               (with-directory-excursion "release_notes"
+                 (stex-make "/release_notes"))
+               (with-directory-excursion doc-dir
+                 (symlink "release_notes/release_notes.pdf"
+                          "release_notes.pdf")
+                 (symlink "csug/csug9_5.pdf"
+                          "csug.pdf"))))))))
+    ;; Chez Scheme does not have a  MIPS backend.
+    ;; FIXME: Debian backports patches to get armhf working.
+    ;; We should too. It is the Chez machine type arm32le
+    ;; (no threaded version upstream yet, though there is in
+    ;; Racket's fork), more specifically (per the release notes) ARMv6.
+    (supported-systems (fold delete %supported-systems
+                             '("mips64el-linux" "armhf-linux")))
+    (home-page "https://cisco.github.io/ChezScheme/")
+    (synopsis "R6RS Scheme compiler and run-time")
+    (description
+     "Chez Scheme is a compiler and run-time system for the language of the
+Revised^6 Report on Scheme (R6RS), with numerous extensions.  The compiler
+generates native code for each target processor, with support for x86, x86_64,
+and 32-bit PowerPC architectures.")
+    (license license:asl2.0)))
diff --git a/gnu/packages/chez.scm b/gnu/packages/chez.scm
index 47904e7b4e..caf61a95f5 100644
--- a/gnu/packages/chez.scm
+++ b/gnu/packages/chez.scm
@@ -4,7 +4,6 @@
 ;;; Copyright © 2017, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2019 Brett Gilio <brettg@gnu.org>
 ;;; Copyright © 2020 Brendan Tildesley <mail@brendan.scot>
-;;; Copyright © 2021 Philip McGrath <philip@philipmcgrath.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -32,234 +31,12 @@ (define-module (gnu packages chez)
   #:use-module (guix utils)
   #:use-module (guix gexp)
   #:use-module (guix build-system gnu)
-  #:use-module (gnu packages compression)
-  #:use-module (gnu packages ncurses)
+  #:use-module (gnu packages chez-and-racket-bootstrap)
   #:use-module (gnu packages ghostscript)
-  #:use-module (gnu packages linux)
-  #:use-module (gnu packages netpbm)
   #:use-module (gnu packages tex)
-  #:use-module (gnu packages compression)
-  #:use-module (gnu packages image)
-  #:use-module (gnu packages xorg)
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-1))
 
-(define nanopass
-  (let ((version "1.9.2"))
-    (origin
-      (method git-fetch)
-      (uri (git-reference
-            (url "https://github.com/nanopass/nanopass-framework-scheme")
-            (commit (string-append "v" version))))
-      (sha256 (base32 "16vjsik9rrzbabbhbxbaha51ppi3f9n8rk59pc6zdyffs0vziy4i"))
-      (file-name (git-file-name "nanopass" version)))))
-
-(define stex
-  ;; This commit includes a fix, which we would otherwise want to use as
-  ;; patch.  Let's revert to tagged releases as soon as one becomes available.
-  (let* ((commit "54051494434a197772bf6ca5b4e6cf6be55f39a5")
-         (version "1.2.2")
-         (version (git-version version "1" commit)))
-    (origin
-      (method git-fetch)
-      (uri (git-reference
-            (url "https://github.com/dybvig/stex")
-            (commit commit)))
-      (sha256 (base32 "01jnvw8qw33gnpzwrakwhsr05h6b609lm180jnspcrb7lds2p23d"))
-      (file-name (git-file-name "stex" version)))))
-
-(define-public chez-scheme
-  (package
-    (name "chez-scheme")
-    (version "9.5.6")
-    (source
-     (origin
-       (method git-fetch)
-       (uri (git-reference
-             (url "https://github.com/cisco/ChezScheme")
-             (commit (string-append "v" version))))
-       (sha256
-        (base32 "07s433hn1z2slfc026sidrpzxv3a8narcd40qqr1xrpb9012xdky"))
-       (file-name (git-file-name name version))
-       (snippet
-        ;; Remove bundled libraries.
-        (with-imported-modules '((guix build utils))
-          #~(begin
-              (use-modules (guix build utils))
-              (for-each (lambda (dir)
-                          (when (directory-exists? dir)
-                            (delete-file-recursively dir)))
-                        '("stex"
-                          "nanopass"
-                          "lz4"
-                          "zlib")))))))
-    (build-system gnu-build-system)
-    (inputs
-     `(("libuuid" ,util-linux "lib")
-       ("zlib" ,zlib)
-       ("zlib:static" ,zlib "static")
-       ("lz4" ,lz4)
-       ("lz4:static" ,lz4 "static")
-       ;; for expeditor:
-       ("ncurses" ,ncurses)
-       ;; for X11 clipboard support in expeditor:
-       ;; https://github.com/cisco/ChezScheme/issues/9#issuecomment-222057232
-       ("libx11" ,libx11)))
-    (native-inputs
-     `(("nanopass" ,nanopass) ; source only
-       ;; for docs
-       ("stex" ,stex)
-       ("xorg-rgb" ,xorg-rgb)
-       ("texlive" ,(texlive-updmap.cfg (list texlive-dvips-l3backend
-                                             texlive-epsf
-                                             texlive-fonts-ec
-                                             texlive-oberdiek)))
-       ("ghostscript" ,ghostscript)
-       ("netpbm" ,netpbm)))
-    (native-search-paths
-     (list (search-path-specification
-            (variable "CHEZSCHEMELIBDIRS")
-            (files (list (string-append "lib/csv" version "-site"))))))
-    (outputs '("out" "doc"))
-    (arguments
-     `(#:modules
-       ((guix build gnu-build-system)
-        (guix build utils)
-        (ice-9 ftw)
-        (ice-9 match))
-       #:test-target "test"
-       #:configure-flags
-       '("--threads") ;; TODO when we fix armhf, it doesn't support --threads
-       #:phases
-       (modify-phases %standard-phases
-         ;; put these where configure expects them to be
-         (add-after 'unpack 'unpack-nanopass+stex
-           (lambda* (#:key native-inputs inputs #:allow-other-keys)
-             (for-each (lambda (dep)
-                         (define src
-                           (assoc-ref (or native-inputs inputs) dep))
-                         (copy-recursively src dep
-                                           #:keep-mtime? #t))
-                       '("nanopass" "stex"))))
-         ;; NOTE: the custom Chez 'configure' script doesn't allow
-         ;; unrecognized flags, such as those automatically added
-         ;; by `gnu-build-system`.
-         (replace 'configure
-           (lambda* (#:key inputs outputs
-                           (configure-flags '())
-                           #:allow-other-keys)
-             (let* ((zlib-static (assoc-ref inputs "zlib:static"))
-                    (lz4-static (assoc-ref inputs "lz4:static"))
-                    (out (assoc-ref outputs "out"))
-                    ;; add flags which are always required:
-                    (flags (cons*
-                            (string-append "--installprefix=" out)
-                            (string-append "ZLIB=" zlib-static "/lib/libz.a")
-                            (string-append "LZ4=" lz4-static "/lib/liblz4.a")
-                            ;; Guix will do compress man pages,
-                            ;; and letting Chez try causes an error
-                            "--nogzip-man-pages"
-                            configure-flags)))
-               (format #t "configure flags: ~s~%" flags)
-               ;; Some makefiles (for tests) don't seem to propagate CC
-               ;; properly, so we take it out of their hands:
-               (setenv "CC" ,(cc-for-target))
-               (setenv "HOME" "/tmp")
-               (apply invoke
-                      "./configure"
-                      flags))))
-         ;; The binary file name is called "scheme" as is the one from MIT/GNU
-         ;; Scheme.  We add a symlink to use in case both are installed.
-         (add-after 'install 'install-symlink
-           (lambda* (#:key outputs #:allow-other-keys)
-             (let* ((out (assoc-ref outputs "out"))
-                    (bin (string-append out "/bin"))
-                    (lib (string-append out "/lib"))
-                    (name "chez-scheme"))
-               (symlink (string-append bin "/scheme")
-                        (string-append bin "/" name))
-               (map (lambda (file)
-                      (symlink file (string-append (dirname file)
-                                                   "/" name ".boot")))
-                    (find-files lib "scheme.boot")))))
-         ;; Building explicitly lets us avoid using substitute*
-         ;; to re-write makefiles.
-         (add-after 'install-symlink 'prepare-stex
-           (lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
-             (let* ((stex+version
-                     (strip-store-file-name
-                      (assoc-ref (or native-inputs inputs) "stex")))
-                    ;; Eventually we want to install stex as a real
-                    ;; package so it's reusable. For now:
-                    (stex-output "/tmp")
-                    (doc-dir (string-append stex-output
-                                            "/share/doc/"
-                                            stex+version)))
-               (with-directory-excursion "stex"
-                 (invoke "make"
-                         "install"
-                         (string-append "LIB="
-                                        stex-output
-                                        "/lib/"
-                                        stex+version)
-                         (string-append "Scheme="
-                                        (assoc-ref outputs "out")
-                                        "/bin/scheme"))
-                 (for-each (lambda (pth)
-                             (install-file pth doc-dir))
-                           '("ReadMe" ; includes the license
-                             "doc/stex.html"
-                             "doc/stex.css"
-                             "doc/stex.pdf"))))))
-         ;; Building the documentation requires stex and a running scheme.
-         ;; FIXME: this is probably wrong for cross-compilation
-         (add-after 'prepare-stex 'install-doc
-           (lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
-             (let* ((chez+version (strip-store-file-name
-                                   (assoc-ref outputs "out")))
-                    (stex+version
-                     (strip-store-file-name
-                      (assoc-ref (or native-inputs inputs) "stex")))
-                    (scheme (string-append (assoc-ref outputs "out")
-                                           "/bin/scheme"))
-                    ;; see note on stex-output in phase build-stex, above:
-                    (stexlib (string-append "/tmp"
-                                            "/lib/"
-                                            stex+version))
-                    (doc-dir (string-append (assoc-ref outputs "doc")
-                                            "/share/doc/"
-                                            chez+version)))
-               (define* (stex-make #:optional (suffix ""))
-                 (invoke "make"
-                         "install"
-                         (string-append "Scheme=" scheme)
-                         (string-append "STEXLIB=" stexlib)
-                         (string-append "installdir=" doc-dir suffix)))
-               (with-directory-excursion "csug"
-                 (stex-make "/csug"))
-               (with-directory-excursion "release_notes"
-                 (stex-make "/release_notes"))
-               (with-directory-excursion doc-dir
-                 (symlink "release_notes/release_notes.pdf"
-                          "release_notes.pdf")
-                 (symlink "csug/csug9_5.pdf"
-                          "csug.pdf"))))))))
-    ;; Chez Scheme does not have a  MIPS backend.
-    ;; FIXME: Debian backports patches to get armhf working.
-    ;; We should too. It is the Chez machine type arm32le
-    ;; (no threaded version upstream yet, though there is in
-    ;; Racket's fork), more specifically (per the release notes) ARMv6.
-    (supported-systems (fold delete %supported-systems
-                             '("mips64el-linux" "armhf-linux")))
-    (home-page "https://cisco.github.io/ChezScheme/")
-    (synopsis "R6RS Scheme compiler and run-time")
-    (description
-     "Chez Scheme is a compiler and run-time system for the language of the
-Revised^6 Report on Scheme (R6RS), with numerous extensions.  The compiler
-generates native code for each target processor, with support for x86, x86_64,
-and 32-bit PowerPC architectures.")
-    (license asl2.0)))
-
 (define-public chez-srfi
   (package
     (name "chez-srfi")
diff --git a/gnu/packages/emacs-xyz.scm b/gnu/packages/emacs-xyz.scm
index e4390bad96..02694b636a 100644
--- a/gnu/packages/emacs-xyz.scm
+++ b/gnu/packages/emacs-xyz.scm
@@ -145,7 +145,7 @@ (define-module (gnu packages emacs-xyz)
   #:use-module (gnu packages aspell)
   #:use-module (gnu packages audio)
   #:use-module (gnu packages bash)
-  #:use-module (gnu packages chez)
+  #:use-module (gnu packages chez-and-racket-bootstrap)
   #:use-module (gnu packages cmake)
   #:use-module (gnu packages code)
   #:use-module (gnu packages cpp)
diff --git a/gnu/packages/loko.scm b/gnu/packages/loko.scm
index ef9312afe3..74a649b8a1 100644
--- a/gnu/packages/loko.scm
+++ b/gnu/packages/loko.scm
@@ -24,7 +24,7 @@ (define-module (gnu packages loko)
   #:use-module (gnu packages package-management)
   #:use-module (gnu packages guile)
   #:use-module (gnu packages guile-xyz)
-  #:use-module (gnu packages chez))
+  #:use-module (gnu packages chez-and-racket-bootstrap))
 
 (define-public loko-scheme
   (package
diff --git a/gnu/packages/racket.scm b/gnu/packages/racket.scm
index d0a5ca494b..865fdff70f 100644
--- a/gnu/packages/racket.scm
+++ b/gnu/packages/racket.scm
@@ -34,7 +34,7 @@ (define-module (gnu packages racket)
   #:use-module (gnu packages)
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages bash)
-  #:use-module (gnu packages chez)
+  #:use-module (gnu packages chez-and-racket-bootstrap)
   #:use-module (gnu packages compression)
   #:use-module (gnu packages databases)
   #:use-module (gnu packages fontutils)
-- 
2.32.0
P
P
Philip McGrath wrote on 13 Feb 22:51 +0100
[PATCH 02/11] gnu: chez-scheme: Use "lib/chez-scheme" for search path.
(address . 53878@debbugs.gnu.org)
20220213215127.218952-3-philip@philipmcgrath.com
There does not seem to be any widely accepted standard path to use for
"CHEZSCHEMELIBDIRS". Using a path without a version number in it avoids
having to compute the actual path everywhere, which would be especially
unpleasant when support is added for the Racket variant of Chez Scheme,
which always has a different version number than upstream.

* gnu/packages/chez-and-racket-bootstrap.scm
(chez-scheme)[native-search-paths]: Change to use "lib/chez-scheme"
instead of "lib/csvX.Y.Z-site" for "CHEZSCHEMELIBDIRS".
* gnu/packages/chez.scm (chez-srfi, chez-web, chez-sockets,
chez-matchable, chez-irregex, chez-fmt, chez-mit, chez-scmutils): Update
accordingly. Also, remove input labels and use G-expressions.
---
gnu/packages/chez-and-racket-bootstrap.scm | 2 +-
gnu/packages/chez.scm | 373 +++++++++++----------
2 files changed, 191 insertions(+), 184 deletions(-)

Toggle diff (467 lines)
diff --git a/gnu/packages/chez-and-racket-bootstrap.scm b/gnu/packages/chez-and-racket-bootstrap.scm
index f102b099fb..1ed4631ced 100644
--- a/gnu/packages/chez-and-racket-bootstrap.scm
+++ b/gnu/packages/chez-and-racket-bootstrap.scm
@@ -136,7 +136,7 @@ (define-public chez-scheme
     (native-search-paths
      (list (search-path-specification
             (variable "CHEZSCHEMELIBDIRS")
-            (files (list (string-append "lib/csv" version "-site"))))))
+            (files (list (string-append "lib/chez-scheme"))))))
     (outputs '("out" "doc"))
     (arguments
      `(#:modules
diff --git a/gnu/packages/chez.scm b/gnu/packages/chez.scm
index caf61a95f5..54bbee7923 100644
--- a/gnu/packages/chez.scm
+++ b/gnu/packages/chez.scm
@@ -37,6 +37,28 @@ (define-module (gnu packages chez)
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-1))
 
+
+;; Help function for Chez Scheme to add the current path to
+;; CHEZSCHEMELIBDIRS.
+(define chez-configure
+  #~(lambda _
+      (let ((chez-env (getenv "CHEZSCHEMELIBDIRS")))
+        (setenv "CHEZSCHEMELIBDIRS"
+                (if chez-env
+                    (string-append ".:" chez-env)
+                    ".")))))
+
+;; Help function to define make flags for some Chez Scheme custom make
+;; files.
+(define (chez-make-flags name version)
+  #~(let ((out #$output))
+      (list
+       ;; Set 'schemedir' so that libraries are installed in
+       ;; 'lib/chez-scheme' like Chez's 'native-search-paths' expects.
+       (string-append "schemedir=" out "/lib/chez-scheme")
+       (string-append "PREFIX=" out)
+       (string-append "DOCDIR=" out "/share/doc/" #$name "-" #$version))))
+
 (define-public chez-srfi
   (package
     (name "chez-srfi")
@@ -54,13 +76,11 @@ (define-public chez-srfi
     (native-inputs
      (list chez-scheme))
     (arguments
-     `(#:make-flags (let ((out (assoc-ref %outputs "out")))
-                      (list (string-append "PREFIX=" out)
-                            "CHEZ=chez-scheme --libdirs ./"
-                            (string-append "chezversion=" ,(package-version chez-scheme))))
-       #:test-target "test"
-       #:phases (modify-phases %standard-phases
-                  (delete 'configure))))
+     (list #:make-flags (chez-make-flags name version)
+           #:test-target "test"
+           #:phases #~(modify-phases %standard-phases
+                        (replace 'configure
+                          #$chez-configure))))
     (home-page "https://github.com/fedeinthemix/chez-srfi")
     (synopsis "SRFI libraries for Chez Scheme")
     (description
@@ -85,42 +105,48 @@ (define-public chez-web
           (base32 "1dq25qygyncbfq4kwwqqgyyakfqjwhp5q23vrf3bff1p66nyfl3b"))))
       (build-system gnu-build-system)
       (native-inputs
-       `(("chez-scheme" ,chez-scheme)
-         ("ghostscript" ,ghostscript)
-         ("texlive" ,(texlive-updmap.cfg (list texlive-oberdiek
-                                          texlive-epsf
-                                          texlive-metapost
-                                          texlive-charter
-                                          texlive-pdftex
-                                          texlive-context
-                                          texlive-cm
-                                          texlive-tex-plain)))))
+       (list chez-scheme
+             ghostscript
+             ;; FIXME: This package fails to build with the error:
+             ;;     mktexpk: don't know how to create bitmap font for bchr8r
+             ;; Replacing the following with `texlive` fixes it.
+             ;; What is missing?
+             (texlive-updmap.cfg (list texlive-oberdiek
+                                       texlive-epsf
+                                       texlive-metapost
+                                       texlive-charter
+                                       texlive-pdftex
+                                       texlive-context
+                                       texlive-cm
+                                       texlive-tex-plain))))
       (arguments
-       `(#:make-flags (list (string-append "PREFIX=" %output)
-                            (string-append "DOCDIR=" %output "/share/doc/"
-                                           ,name "-" ,version)
-                            (string-append "LIBDIR=" %output "/lib/chezweb")
-                            (string-append "TEXDIR=" %output "/share/texmf-local"))
-                      #:tests? #f        ; no tests
-                      #:phases
-                      (modify-phases %standard-phases
-                        ;; This package has a custom "bootstrap" script that
-                        ;; is meant to be run from the Makefile.
-                        (delete 'bootstrap)
-                        (replace 'configure
-                          (lambda* _
-                            (copy-file "config.mk.template" "config.mk")
-                            (substitute* "tangleit"
-                              (("\\./cheztangle\\.ss" all)
-                               (string-append "chez-scheme --program " all)))
-                            (substitute* "weaveit"
-                              (("mpost chezweb\\.mp")
-                               "mpost --tex=tex chezweb.mp")
-                              (("\\./chezweave" all)
-                               (string-append "chez-scheme --program " all)))
-                            (substitute* "installit"
-                              (("-g \\$GROUP -o \\$OWNER") ""))
-                            #t)))))
+       (list
+        #:make-flags
+        #~(list (string-append "PREFIX=" #$output)
+                (string-append "DOCDIR=" #$output "/share/doc/"
+                               #$name "-" #$version)
+                ;; lib/chez-scheme/chezweb ???
+                (string-append "LIBDIR=" #$output "/lib/chezweb")
+                (string-append "TEXDIR=" #$output "/share/texmf-local"))
+        #:tests? #f ; no tests
+        #:phases
+        #~(modify-phases %standard-phases
+            ;; This package has a custom "bootstrap" script that
+            ;; is meant to be run from the Makefile.
+            (delete 'bootstrap)
+            (replace 'configure
+              (lambda* _
+                (copy-file "config.mk.template" "config.mk")
+                (substitute* "tangleit"
+                  (("\\./cheztangle\\.ss" all)
+                   (string-append "scheme --program " all)))
+                (substitute* "weaveit"
+                  (("mpost chezweb\\.mp")
+                   "mpost --tex=tex chezweb.mp")
+                  (("\\./chezweave" all)
+                   (string-append "scheme --program " all)))
+                (substitute* "installit"
+                  (("-g \\$GROUP -o \\$OWNER") "")))))))
       (home-page "https://github.com/arcfide/ChezWEB")
       (synopsis "Hygienic Literate Programming for Chez Scheme")
       (description "ChezWEB is a system for doing Knuthian style WEB
@@ -144,95 +170,74 @@ (define-public chez-sockets
           (base32 "1n5fbwwz51fdzvjackgmnsgh363g9inyxv7kmzi0469cwavwcx5m"))))
       (build-system gnu-build-system)
       (native-inputs
-       `(("chez-scheme" ,chez-scheme)
-         ("chez-web" ,chez-web)
-         ("texlive" ,(texlive-updmap.cfg (list texlive-pdftex)))))
+       (list chez-scheme
+             chez-web
+             (texlive-updmap.cfg (list texlive-pdftex))))
       (arguments
-       `(#:tests? #f              ; no tests
-         #:phases
-         (modify-phases %standard-phases
-           (replace 'configure
-             (lambda* (#:key outputs inputs #:allow-other-keys)
-               (let* ((out (assoc-ref outputs "out"))
-                      (chez-web (assoc-ref inputs "chez-web"))
-                      (chez (assoc-ref inputs "chez-scheme"))
-                      (chez-h (dirname (car (find-files chez "scheme\\.h")))))
-                 (substitute* "Makefile"
-                   (("(SCHEMEH=).*$" all var)
-                    (string-append var chez-h)))
-                 #t)))
-           (add-before 'build 'tangle
-             (lambda* (#:key inputs #:allow-other-keys)
-               (setenv "TEXINPUTS"
-                       (string-append
-                        (getcwd) ":"
-                        (assoc-ref inputs "chez-web") "/share/texmf-local/tex/generic:"
-                        ":"))
-               ;; just using "make" tries to build the .c files before
-               ;; they are created.
-               (and (invoke "make" "sockets")
-                    (invoke "make"))))
-           (replace 'build
-             (lambda* (#:key outputs inputs #:allow-other-keys)
-               (let* ((out (assoc-ref outputs "out"))
-                      (chez-site (string-append out "/lib/csv"
-                                                ,(package-version chez-scheme)
-                                                "-site/arcfide")))
-                 ;; make sure Chez Scheme can find the shared libraries.
-                 (substitute* "sockets.ss"
-                   (("(load-shared-object) \"(socket-ffi-values\\.[sd][oy].*)\""
-                     all cmd so)
-                    (string-append cmd " \"" chez-site "/" so "\""))
-                   (("sockets-stub\\.[sd][oy].*" all)
-                    (string-append chez-site "/" all)))
-                 ;; to compile chez-sockets, the .so files must be
-                 ;; installed (because of the absolute path we
-                 ;; inserted above).
-                 (for-each (lambda (f d) (install-file f d))
-                           '("socket-ffi-values.so" "sockets-stub.so")
-                           (list chez-site chez-site))
-                 (zero? (system "echo '(compile-file \"sockets.sls\")' | scheme -q")))))
-           (replace 'install
-             (lambda* (#:key outputs inputs #:allow-other-keys)
-               (let* ((out (assoc-ref outputs "out"))
-                      (lib (string-append out "/lib/chez-sockets"))
-                      (doc (string-append out "/share/doc/" ,name "-" ,version))
-                      (chez-site (string-append out "/lib/csv"
-                                                ,(package-version chez-scheme)
-                                                "-site/arcfide")))
-                 (for-each (lambda (f d) (install-file f d))
-                           '("sockets.pdf" "sockets.so")
-                           (list doc chez-site))
-                 #t))))))
+       (list
+        #:tests? #f ; no tests
+        #:phases
+        #~(modify-phases %standard-phases
+            (replace 'configure
+              (lambda* (#:key native-inputs inputs #:allow-other-keys)
+                (let* ((scheme (search-input-file (or native-inputs inputs)
+                                                  "/bin/scheme"))
+                       (lib (string-append (dirname scheme) "/../lib"))
+                       (header-file (car (find-files lib "scheme\\.h")))
+                       (include-dir (dirname header-file)))
+                  (substitute* "Makefile"
+                    (("(SCHEMEH=).*$" _ var)
+                     (string-append var include-dir))))))
+            (add-before 'build 'tangle
+              (lambda* (#:key inputs #:allow-other-keys)
+                (setenv "TEXINPUTS"
+                        (string-append
+                         (getcwd) ":"
+                         (assoc-ref inputs "chez-web")
+                         "/share/texmf-local/tex/generic:"
+                         ":"))
+                ;; just using "make" tries to build the .c files before
+                ;; they are created.
+                (and (invoke "make" "sockets")
+                     (invoke "make"))))
+            (replace 'build
+              (lambda args
+                (let ((chez-site (string-append #$output
+                                                "/lib/chez-scheme/arcfide")))
+                  ;; make sure Chez Scheme can find the shared libraries.
+                  (substitute* "sockets.ss"
+                    (("(object \")(socket-ffi-values\\.[sd][oy][^\"]*)(\")"
+                      _ pre file post)
+                     (string-append pre chez-site "/" file post))
+                    (("(\")(sockets-stub\\.[sd][oy][^\"]*)(\")"
+                      _ pre file post)
+                     (string-append pre chez-site "/" file post)))
+                  ;; to compile chez-sockets, the .so files must be
+                  ;; installed (because of the absolute path we
+                  ;; inserted above).
+                  (for-each (lambda (f)
+                              (install-file f chez-site))
+                            '("socket-ffi-values.so"
+                              "sockets-stub.so"))
+                  (invoke "bash"
+                          "-c"
+                          (format #f "echo '~s' | scheme -q"
+                                  '(compile-file "sockets.sls"))))))
+            (replace 'install
+              (lambda args
+                (install-file "sockets.so"
+                              (string-append #$output
+                                             "/lib/chez-scheme/arcfide"))
+                (install-file "sockets.pdf"
+                              (string-append #$output
+                                             "/share/doc/"
+                                             #$name "-" #$version)))))))
       (home-page "https://github.com/arcfide/chez-sockets")
       (synopsis "Extensible sockets library for Chez Scheme")
       (description "Chez-sockets is an extensible sockets library for
 Chez Scheme.")
       (license expat))))
 
-;; Help function for Chez Scheme to add the current path to
-;; CHEZSCHEMELIBDIRS.
-(define chez-configure
-  '(lambda _
-     (let ((chez-env (getenv "CHEZSCHEMELIBDIRS")))
-       (setenv "CHEZSCHEMELIBDIRS"
-               (if chez-env
-                   (string-append ".:" chez-env)
-                   "."))
-       #t)))
-
-;; Help function to define make flags for some Chez Scheme custom make
-;; files.
-(define (chez-make-flags name version)
-  `(let ((out (assoc-ref %outputs "out")))
-     (list
-      ;; Set 'chezversion' so that libraries are installed in
-      ;; 'lib/csvX.Y.Z-site' like Chez's 'native-search-paths' expects.
-      (string-append "chezversion=" ,(package-version chez-scheme))
-      (string-append "PREFIX=" out)
-      (string-append "DOCDIR=" out "/share/doc/"
-                     ,name "-" ,version))))
-
 (define-public chez-matchable
   (package
     (name "chez-matchable")
@@ -253,10 +258,11 @@ (define-public chez-matchable
     (native-inputs
      (list chez-scheme))
     (arguments
-     `(#:make-flags ,(chez-make-flags name version)
-       #:test-target "test"
-       #:phases (modify-phases %standard-phases
-                  (replace 'configure ,chez-configure))))