diff --git a/gnu/packages/haskell.scm b/gnu/packages/haskell.scm
index 3746b6bd57..0412745506 100644
--- a/gnu/packages/haskell.scm
+++ b/gnu/packages/haskell.scm
@@ -199,8 +199,23 @@ (define-public ghc-4
     (arguments
      `(#:system "i686-linux"
        #:strip-binaries? #f
+       #:modules ((guix build gnu-build-system)
+                  (guix build utils)
+                  (srfi srfi-1)
+                  (ice-9 match))
        #:phases
        (modify-phases %standard-phases
+         (add-after 'unpack 'unpack-generated-c-code
+           (lambda* (#:key inputs #:allow-other-keys)
+             (let ((tarball
+                    (match inputs
+                      (((_ . locations) ...)
+                       (let ((suffix (string-append "ghc-" ,version "-hc-unreg.tar.bz2")))
+                         (find (lambda (location)
+                                 (string-suffix? suffix location))
+                               locations))))))
+               (invoke "tar" "-xvf" tarball
+                       "--strip-components=1"))))
          (replace 'bootstrap
            (lambda* (#:key inputs #:allow-other-keys)
              (delete-file "configure")
@@ -214,6 +229,7 @@ (define-public ghc-4
                (("FPTOOLS_HAPPY") "echo sure\n"))
 
              ;; Set options suggested in ghc/interpreter/README.BUILDING.HUGS.
+             #;
              (with-output-to-file "mk/build.mk"
                (lambda ()
                  (display "
@@ -275,6 +291,9 @@ (define-public ghc-4
              (substitute* "mk/config.mk.in"
                (("-traditional")
                 "-traditional -x c"))
+             (substitute* "mk/config.mk.in"
+               (("^GhcWithNativeCodeGen=.*")
+                "GhcWithNativeCodeGen=NO\n"))
 
              (setenv "CPP" (which "cpp"))
              (invoke "autoreconf" "--verbose" "--force")))
@@ -323,17 +342,27 @@ (define-public ghc-4
                                     (or (getenv "CPATH") "")))
              (invoke "make" "boot")))
          (replace 'build
-           (lambda _
-             ;; TODO: since we don't have a Haskell compiler we cannot build
-             ;; the standard library.  And without the standard library we
-             ;; cannot build a Haskell compiler.
-             ;; make[3]: *** No rule to make target 'Array.o', needed by 'libHSstd.a'.  Stop.
-             ;; make[2]: *** No rule to make target 'utils/Argv.o', needed by 'hsc'.  Stop.
-             (invoke "make" "all")))
+           (lambda* (#:key build inputs outputs #:allow-other-keys)
+             (let ((bash (which "bash"))
+                   (out  (assoc-ref outputs "out")))
+               (substitute* "distrib/hc-build"
+                 (("gmake") "make"))
+               (substitute* "ghc/includes/TailCalls.h"
+                 (("extern void __DISCARD.*") "")
+                 (("__DISCARD__ ?\\(\\);") ""))
+               (substitute* "ghc/compiler/Makefile"
+                 (("parser/hschooks.o" m)
+                  (string-append m " ../lib/std/libHSstd.a")))
+               (invoke "sh" "distrib/hc-build"
+                       (string-append "--prefix=" out)
+                       (string-append "--build=" build)
+                       (string-append "--host=" build)))))
+         #;
          (add-after 'build 'build-hugs
            (lambda _
              (invoke "make" "-C" "ghc/interpreter")
-             (invoke "make" "-C" "ghc/interpreter" "install")))
+         (invoke "make" "-C" "ghc/interpreter" "install")))
+         #;
          (add-after 'install 'install-sources
            (lambda* (#:key outputs #:allow-other-keys)
              (let ((lib (string-append (assoc-ref outputs "out") "/lib")))
@@ -344,6 +373,7 @@ (define-public ghc-4
                (copy-recursively "ghc/compiler"
                                  (string-append lib "/ghc/compiler"))
                (copy-recursively "ghc/interpreter/lib" lib)
+               #;
                (install-file "ghc/interpreter/nHandle.so" lib)))))))
     (native-inputs
      (list autoconf-2.13
@@ -360,7 +390,15 @@ (define-public ghc-4
            ;; TODO: Perl used to allow setting $* to enable multi-line
            ;; matching.  If we want to use a more recent Perl we need to patch
            ;; all expressions that require multi-line matching.  Hard to tell.
-           perl-5.14))
+           perl-5.14
+
+           (origin
+             (method url-fetch)
+             (uri (string-append "http://downloads.haskell.org/~ghc/"
+                                 version "/ghc-" version "-hc-unreg.tar.bz2"))
+             (sha256
+              (base32
+               "0sd6q2hckbj31jalanap00r674129s10s1hizpw84b1cmzrww0qx")))))
     (home-page "https://www.haskell.org/ghc")
     (synopsis "The Glasgow Haskell Compiler")
     (description

Generated by Ricardo Wurmus using scpaste at Fri Oct 14 00:11:59 2022. CEST. (original)