Subject: [PATCH va3e5ae0f..37252e07 02/32] gnu: erlang updated.

From: Pierre-Henry Fröhring <[email-masked]>
Date: Sun, 29 Oct 2023 15:36:55 +0100

Wrapped Erlang programs (`erl`, `erlc`, `escript`) now prepend ERL_LIBS with
GUIX_ERL_LIBS. Reference: https://www.erlang.org/doc/man/code#code-path. The
`native-search-paths` field in the package specification sets GUIX_ERL_LIBS,
which aggregates all compiled libraries for Erlang and Elixir, akin to the
functionality of GUIX_PYTHONPATH.

Change-Id: I53d0462eb366ebe66422e0b187f4db091a9fe5b5
---
 gnu/packages/erlang.scm | 101 ++++++++++++++++++++++++----------------
 1 file changed, 60 insertions(+), 41 deletions(-)

diff --git a/gnu/packages/erlang.scm b/gnu/packages/erlang.scm
index c53cb72c..dafc0e81 100644
--- a/gnu/packages/erlang.scm
+++ b/gnu/packages/erlang.scm
@@ -28,22 +28,23 @@
 
 (define-module (gnu packages erlang)
   #:use-module ((guix licenses) #:prefix license:)
-  #:use-module (guix gexp)
-  #:use-module (guix build-system gnu)
-  #:use-module (guix build-system emacs)
-  #:use-module (guix build-system rebar)
-  #:use-module (guix download)
-  #:use-module (guix git-download)
-  #:use-module (guix packages)
-  #:use-module (guix utils)
-  #:use-module (gnu packages)
+  #:use-module (gnu packages elixir)
   #:use-module (gnu packages fontutils)
   #:use-module (gnu packages gl)
   #:use-module (gnu packages ncurses)
   #:use-module (gnu packages perl)
-  #:use-module (gnu packages version-control)
   #:use-module (gnu packages tls)
-  #:use-module (gnu packages wxwidgets))
+  #:use-module (gnu packages version-control)
+  #:use-module (gnu packages wxwidgets)
+  #:use-module (gnu packages)
+  #:use-module (guix build-system emacs)
+  #:use-module (guix build-system gnu)
+  #:use-module (guix build-system rebar)
+  #:use-module (guix download)
+  #:use-module (guix gexp)
+  #:use-module (guix git-download)
+  #:use-module (guix packages)
+  #:use-module (guix utils))
 
 (define-public erlang
   (package
@@ -173,7 +174,16 @@ (define-public erlang
                (substitute* (string-append out "/bin/erl")
                  (("basename") (which "basename"))
                  (("dirname") (which "dirname"))))))
-         (add-after 'install 'install-doc
+         (add-after 'patch-erl 'wrap-programs
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (programs '("erl" "erlc" "escript")))
+               (for-each
+                (lambda (program)
+                  (wrap-program (string-append out "/bin/" program)
+                    '("ERL_LIBS" ":" prefix ("${GUIX_ERL_LIBS}"))))
+                programs))))
+         (add-after 'wrap-programs 'install-doc
            (lambda* (#:key inputs outputs #:allow-other-keys)
              (let* ((out (assoc-ref outputs "out"))
                     (manpages (assoc-ref inputs "erlang-manpages"))
@@ -181,6 +191,15 @@ (define-public erlang
                (mkdir-p share)
                (with-directory-excursion share
                  (invoke "tar" "xvf" manpages))))))))
+    (native-search-paths
+     (list (search-path-specification
+            (variable "GUIX_ERL_LIBS")
+            (files
+             (list
+              "lib/erlang/lib"
+              (string-append
+               "lib/elixir/"
+               (version-major+minor (package-version elixir))))))))
     (home-page "https://www.erlang.org/")
     (synopsis "The Erlang programming language")
     (description
@@ -219,12 +238,12 @@ (define-public erlang-bbmustache
     (source
      (origin
        (method url-fetch)
-       (uri (hexpm-uri "bbmustache" version))
+       (uri (hexpm-uri name version))
        (sha256
         (base32 "0fvvaxdpziygxl30j59g98qkh2n47xlb7w5dfpsm2bfcsnj372v8"))))
     (build-system rebar-build-system)
     (inputs
-     (list erlang-getopt rebar3-git-vsn
+     (list erlang-getopt erlang-rebar3-git-vsn
            erlang-edown))  ; for building the docs
     (arguments
      `(#:tests? #f ;; requires mustache specification file
@@ -251,7 +270,7 @@ (define-public erlang-certifi
     (source
      (origin
        (method url-fetch)
-       (uri (hexpm-uri "certifi" version))
+       (uri (hexpm-uri name version))
        (sha256
         (base32 "0ha6vmf5p3xlbf5w1msa89frhvfk535rnyfybz9wdmh6vdms8v96"))))
     (build-system rebar-build-system)
@@ -275,7 +294,7 @@ (define-public erlang-cf
     (source
      (origin
        (method url-fetch)
-       (uri (hexpm-uri "cf" version))
+       (uri (hexpm-uri name version))
        (sha256
         (base32 "0wknz4xkqkhgvlx4vx5619p8m65v7g87lfgsvfy04jrsgm28spii"))))
     (build-system rebar-build-system)
@@ -314,7 +333,7 @@ (define-public erlang-covertool
     (source
      (origin
        (method url-fetch)
-       (uri (hexpm-uri "covertool" version))
+       (uri (hexpm-uri name version))
        (sha256
         (base32 "1p0c1n3nl4063xwi1sv176l1x68xqf07qwvj444a5z888fx6i5aw"))))
     (build-system rebar-build-system)
@@ -335,7 +354,7 @@ (define-public erlang-cth-readable
     (source
      (origin
        (method url-fetch)
-       (uri (hexpm-uri "cth_readable" version))
+       (uri (hexpm-uri name version))
        (sha256
         (base32 "104xgybb6iciy6i28pyyrarqzliddi8kjyq43ajaav7y5si42rb8"))))
     (build-system rebar-build-system)
@@ -356,7 +375,7 @@ (define-public erlang-edown
     (source
       (origin
         (method url-fetch)
-        (uri (hexpm-uri "edown" version))
+        (uri (hexpm-uri name version))
         (sha256
           (base32 "0ij47gvgs6yfqphj0f54qjzj18crj8y1dsjjlzpp3dp8pscqzbqw"))))
     (build-system rebar-build-system)
@@ -373,7 +392,7 @@ (define-public erlang-erlware-commons
     (source
      (origin
        (method url-fetch)
-       (uri (hexpm-uri "erlware_commons" version))
+       (uri (hexpm-uri name version))
        (sha256
         (base32 "18qam9xdzi74wppb0cj4zc8161i0i8djr79z8662m6d276f2jz5m"))))
     (build-system rebar-build-system)
@@ -400,7 +419,7 @@ (define-public erlang-eunit-formatters
     (source
      (origin
        (method url-fetch)
-       (uri (hexpm-uri "eunit_formatters" version))
+       (uri (hexpm-uri name version))
        (sha256
         (base32 "1jb3hzb216r29x2h4pcjwfmx1k81431rgh5v0mp4x5146hhvmj6n"))))
     (build-system rebar-build-system)
@@ -416,7 +435,7 @@ (define-public erlang-getopt
     (source
      (origin
        (method url-fetch)
-       (uri (hexpm-uri "getopt" version))
+       (uri (hexpm-uri name version))
        (sha256
         (base32 "09pasi7ki1rivw9sl7xndj5qgjbdqvcscxk83yk85yr28gm9l0m0"))))
     (build-system rebar-build-system)
@@ -433,7 +452,7 @@ (define-public erlang-hex-core
     (source
      (origin
        (method url-fetch)
-       (uri (hexpm-uri "hex_core" version))
+       (uri (hexpm-uri name version))
        (sha256
         (base32 "06p65hlm29ky03vs3fq3qz6px2ylwp8b0f2y75wdf5cm0kx2332b"))))
     (build-system rebar-build-system)
@@ -445,7 +464,7 @@ (define-public erlang-hex-core
              (when tests?
                (invoke "rebar3" "as" "test" "proper")))))))
     (inputs
-     (list erlang-proper rebar3-proper))
+     (list erlang-proper erlang-rebar3-proper))
     (home-page "https://github.com/hexpm/hex_core")
     (synopsis "Reference implementation of Hex specifications")
     (description "This package provides the reference implementation of Hex
@@ -459,7 +478,7 @@ (define-public erlang-jsone
     (source
       (origin
         (method url-fetch)
-        (uri (hexpm-uri "jsone" version))
+        (uri (hexpm-uri name version))
         (sha256
           (base32 "1gaxiw76syjp3s9rygskm32y9799b917q752rw8bxj3bxq93g8x3"))))
     (build-system rebar-build-system)
@@ -483,7 +502,7 @@ (define-public erlang-parse-trans
     (source
      (origin
        (method url-fetch)
-       (uri (hexpm-uri "parse_trans" version))
+       (uri (hexpm-uri name version))
        (sha256
         (base32 "16p4c2xjrvz16kzpr9pmcvi6nxq6rwckqi9fp0ksibaxwxn402k2"))))
     (build-system rebar-build-system)
@@ -506,7 +525,7 @@ (define-public erlang-proper
     (source
       (origin
         (method url-fetch)
-        (uri (hexpm-uri "proper" version))
+        (uri (hexpm-uri name version))
         (sha256
           (base32 "1fwcas4a9kz3w3z1jqdk9lw8822srfjk9lcpvbxkxlsv3115ha0q"))))
     (build-system rebar-build-system)
@@ -532,7 +551,7 @@ (define-public erlang-jsx
     (version "3.1.0")
     (source (origin
               (method url-fetch)
-              (uri (hexpm-uri "jsx" version))
+              (uri (hexpm-uri name version))
               (sha256
                (base32
                 "1wr7jkxm6nlgvd52xhniav64xr9rml2ngb35rwjwqlqvq7ywhp0c"))))
@@ -550,7 +569,7 @@ (define-public erlang-providers
     (source
      (origin
        (method url-fetch)
-       (uri (hexpm-uri "providers" version))
+       (uri (hexpm-uri name version))
        (sha256
         (base32 "05y0kz3xgx77hzn1l05byaisvmk8bgds7c22hrh0a5ba81sfi1yj"))))
     (build-system rebar-build-system)
@@ -568,7 +587,7 @@ (define-public erlang-relx
     (source
      (origin
        (method url-fetch)
-       (uri (hexpm-uri "relx" version))
+       (uri (hexpm-uri name version))
        (sha256
         (base32 "02gmfx1vxg9m3mq4njsqhs4972l4nb8m5p1pdcf64g09ccf17y1g"))))
     (build-system rebar-build-system)
@@ -590,7 +609,7 @@ (define-public erlang-ssl-verify-fun
     (source
      (origin
        (method url-fetch)
-       (uri (hexpm-uri "ssl_verify_fun" version))
+       (uri (hexpm-uri name version))
        (sha256
         (base32 "1026l1z1jh25z8bfrhaw0ryk5gprhrpnirq877zqhg253x3x5c5x"))))
     (build-system rebar-build-system)
@@ -676,14 +695,14 @@ (define-public rebar3
 of locations (git, hg, etc).")
     (license license:asl2.0)))
 
-(define-public rebar3-raw-deps
+(define-public erlang-rebar3-raw-deps
   (package
-    (name "rebar3-raw-deps")
+    (name "erlang-rebar3-raw-deps")
     (version "2.0.0")
     (source
      (origin
        (method url-fetch)
-       (uri (hexpm-uri "rebar3_raw_deps" version))
+       (uri (hexpm-uri name version))
        (sha256
         (base32 "1pzmm3m8gb2s9jn8fp6shzgfmy4mvh2vdci0z6nsm74ma3ffh1i3"))))
     (build-system rebar-build-system)
@@ -693,14 +712,14 @@ (define-public rebar3-raw-deps
 applications as a dependent libraries.")
     (license license:expat)))
 
-(define-public rebar3-git-vsn
+(define-public erlang-rebar3-git-vsn
   (package
-    (name "rebar3-git-vsn")
+    (name "erlang-rebar3-git-vsn")
     (version "1.1.1")
     (source
       (origin
         (method url-fetch)
-        (uri (hexpm-uri "rebar3_git_vsn" version))
+        (uri (hexpm-uri name version))
         (sha256
           (base32 "1dfz56034pa25axly9vqdzv3phkn8ll0qwrkws96pbgcprhky1hx"))))
     (build-system rebar-build-system)
@@ -724,14 +743,14 @@ (define-public rebar3-git-vsn
 a git checkout.")
     (license license:expat)))
 
-(define-public rebar3-proper
+(define-public erlang-rebar3-proper
   (package
-    (name "rebar3-proper")
+    (name "erlang-rebar3-proper")
     (version "0.12.1")
     (source
       (origin
         (method url-fetch)
-        (uri (hexpm-uri "rebar3_proper" version))
+        (uri (hexpm-uri name version))
         (sha256
           (base32 "1f174fb6h2071wr7qbw9aqqvnglzsjlylmyi8215fhrmi38w94b6"))))
     (build-system rebar-build-system)
@@ -803,7 +822,7 @@ (define-public erlang-lfe
                   (setenv "REBAR_CACHE_DIR" "/tmp")
                   (invoke "make" "-j" (number->string (parallel-job-count))
                           "tests"))))))))
-    (native-inputs (list rebar3 rebar3-proper erlang-proper))
+    (native-inputs (list rebar3 erlang-rebar3-proper erlang-proper))
     (propagated-inputs (list erlang))
     (home-page "https://github.com/lfe/lfe")
     (synopsis "Lisp Flavoured Erlang")
-- 
2.41.0