projects/guix·blob java-team · refs

234 lines · 10.8 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2016 Leo Famulari <[email protected]>
3;;; Copyright © 2016, 2017 Pjotr Prins <[email protected]>
4;;; Copyright © 2016 Ricardo Wurmus <[email protected]>
5;;; Copyright © 2017 nee <[email protected]>
6;;; Copyright © 2018, 2019, 2021 Tobias Geerinckx-Rice <[email protected]>
7;;; Copyright © 2018 Nikita <[email protected]>
8;;; Copyright © 2021 Oskar Köök <[email protected]>
9;;; Copyright © 2021 Cees de Groot <[email protected]>
10;;; Copyright © 2024 Andrew Tropin <[email protected]>
11;;; Copyright © 2024, 2025 Ivan Sokolov <[email protected]>
12;;; Copyright © 2024-2026 Igorj Gorjaĉev <[email protected]>
13;;;
14;;; This file is part of GNU Guix.
15;;;
16;;; GNU Guix is free software; you can redistribute it and/or modify it
17;;; under the terms of the GNU General Public License as published by
18;;; the Free Software Foundation; either version 3 of the License, or (at
19;;; your option) any later version.
20;;;
21;;; GNU Guix is distributed in the hope that it will be useful, but
22;;; WITHOUT ANY WARRANTY; without even the implied warranty of
23;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24;;; GNU General Public License for more details.
25;;;
26;;; You should have received a copy of the GNU General Public License
27;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
28
29(define-module (gnu packages elixir)
30 #:use-module ((guix licenses) #:prefix license:)
31 #:use-module (guix build-system gnu)
32 #:use-module (guix gexp)
33 #:use-module (guix utils)
34 #:use-module (guix git-download)
35 #:use-module (guix packages)
36 #:use-module (gnu packages)
37 #:use-module (gnu packages bash)
38 #:use-module (gnu packages erlang)
39 #:use-module (gnu packages version-control))
40
41(define-public elixir
42 (package
43 (name "elixir")
44 (version "1.19.5")
45 (source
46 (origin
47 (method git-fetch)
48 (uri (git-reference
49 (url "https://github.com/elixir-lang/elixir")
50 (commit (string-append "v" version))))
51 (file-name (git-file-name name version))
52 (sha256
53 (base32 "1i10a5d7mlcrav47k7qirqvrqn2kbl5265fbcp8fzavr86xz67m6"))
54 (patches (search-patches "elixir-path-length.patch"))))
55 (build-system gnu-build-system)
56 (arguments
57 (list
58 #:test-target "test"
59 #:parallel-tests? #f ;see <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=32171#23>
60 #:make-flags #~(list (string-append "PREFIX=" #$output))
61 #:phases
62 #~(let* ((compiler-path "lib/elixir/src/elixir_erl_compiler.erl")
63 (compiler-path-orig (string-append compiler-path ".orig")))
64 (modify-phases %standard-phases
65 (add-after 'unpack 'make-git-checkout-writable
66 (lambda _
67 (for-each make-file-writable (find-files "."))))
68 (add-after 'make-git-checkout-writable 'replace-paths
69 (lambda* (#:key inputs #:allow-other-keys)
70 ;; Note: references end up obfuscated in binary BEAM files
71 ;; where they may be invisible to the GC and graft code:
72 ;; <https://issues.guix.gnu.org/54304#11>.
73 (substitute* '("lib/mix/lib/mix/release.ex"
74 "lib/mix/lib/mix/tasks/release.init.ex")
75 (("#!/bin/sh")
76 (string-append "#!" (search-input-file inputs "/bin/sh"))))
77 (substitute* "bin/elixir"
78 (("ERTS_BIN=\n")
79 (string-append
80 "ERTS_BIN="
81 ;; Elixir Releases will prepend to ERTS_BIN the path of
82 ;; a copy of erl. We detect if a release is being
83 ;; generated by checking the initial ERTS_BIN value: if
84 ;; it's empty, we are not in release mode and can point
85 ;; to the actual erl binary in Guix store.
86 "\nif [ -z \"$ERTS_BIN\" ]; then ERTS_BIN="
87 (string-drop-right
88 (search-input-file inputs "/bin/erl") 3)
89 "; fi\n")))
90 (substitute* "bin/mix"
91 (("#!/usr/bin/env elixir")
92 (string-append "#!" #$output "/bin/elixir")))
93 ;; We should not break the formatting, so we need to patch
94 ;; the following more accurately.
95 (substitute* "lib/mix/test/mix/tasks/cmd_test.exs"
96 (("File\\.mkdir_p!\\(\"priv\"\\)" all)
97 (string-append all "\n sh = \""
98 (search-input-file inputs "/bin/sh") "\""))
99 (("#!/bin/sh") "#!#{sh}"))))
100 (add-after 'replace-paths 'pre-install-source
101 (lambda* (#:key outputs #:allow-other-keys)
102 (copy-recursively
103 "lib"
104 (string-append (assoc-ref outputs "src") "/source/lib"))))
105 (add-after 'pre-install-source 'patch-elixir-compiler
106 ;; Temporarily patch the compiler to place correct source
107 ;; locations into module info instead of build directory.
108 (lambda* (#:key outputs #:allow-other-keys)
109 (copy-recursively compiler-path compiler-path-orig)
110 (let ((source (string-append "/tmp/guix-build-" #$name "-"
111 #$version ".drv-0"))
112 (destination (assoc-ref outputs "src")))
113 (substitute* compiler-path
114 (("source, Source")
115 (string-append "source, string:replace(Source, \""
116 source "\", \"" destination "\")"))))))
117 (add-before 'build 'set-deterministic
118 (lambda _
119 ;; Set deterministic compiler option.
120 (setenv "ERL_COMPILER_OPTIONS" "deterministic")))
121 (add-after 'build 'restore-and-recompile
122 ;; Unpatch the compiler and recompile it.
123 (lambda _
124 (copy-recursively compiler-path-orig compiler-path)
125 (delete-file compiler-path-orig)
126 (invoke "erlc" "-I" "lib/elixir/include"
127 "-o" "lib/elixir/ebin" compiler-path)))
128 (add-after 'restore-and-recompile 'make-current
129 ;; The Elixir compiler checks whether or not to compile files
130 ;; by inspecting their timestamps. When the timestamp is
131 ;; equal to the epoch no compilation will be performed. Some
132 ;; tests fail when files are older than Jan 1, 2000.
133 (lambda _
134 (for-each (lambda (file)
135 (let ((recent 1400000000))
136 (utime file recent recent 0 0)))
137 (find-files "." ".*"))))
138 (add-before 'check 'set-home
139 (lambda _
140 ;; Some tests require access to a home directory.
141 (setenv "HOME" "/tmp")))
142 (delete 'configure)
143 (add-after 'install 'wrap-programs
144 (lambda* (#:key inputs outputs #:allow-other-keys)
145 (let* ((out (assoc-ref outputs "out"))
146 (programs '("elixir" "elixirc" "iex")))
147 ;; mix can be sourced as an elixir script by other elixir
148 ;; program, for example `iex -S mix`, so we should not wrap
149 ;; mix into shell script.
150 (substitute* (string-append out "/bin/mix")
151 (("Mix.CLI.main\\(\\)")
152 (format #f "\
153~~w[GUIX_ELIXIR_LIBS ERL_LIBS]
154|> Enum.map(&System.get_env/1)
155|> Enum.reject(&is_nil/1)
156|> Enum.join(\":\")
157|> case do \"\" -> :ok; erl_libs -> System.put_env(\"ERL_LIBS\", erl_libs) end
158System.put_env(\"MIX_REBAR3\", System.get_env(\"MIX_REBAR3\", \"~a\"))
159Mix.CLI.main()"
160 (search-input-file inputs "/bin/rebar3"))))
161 (for-each
162 (lambda (program)
163 (wrap-program (string-append out "/bin/" program)
164 '("ERL_LIBS" prefix ("${GUIX_ELIXIR_LIBS}"))))
165 programs))))))))
166 (outputs '("out" "src"))
167 (inputs (list bash-minimal erlang rebar3))
168 (native-inputs (list git-minimal/pinned))
169 (native-search-paths
170 (list (search-path-specification
171 (variable "GUIX_ELIXIR_LIBS")
172 (files (list (string-append "lib/elixir/" (version-major+minor
173 version))
174 "lib/erlang/lib")))))
175 (home-page "https://elixir-lang.org/")
176 (synopsis "Functional meta-programming aware language")
177 (description "Elixir is a dynamic, functional language used to build
178scalable and maintainable applications. Elixir leverages the Erlang VM, known
179for running low-latency, distributed and fault-tolerant systems, while also
180being successfully used in web development and the embedded software domain.")
181 (license license:asl2.0)))
182
183(define-public elixir-hex
184 (package
185 (name "elixir-hex")
186 (version "2.1.1")
187 (source
188 (origin
189 (method git-fetch)
190 (uri (git-reference
191 (url "https://github.com/hexpm/hex")
192 (commit (string-append "v" version))))
193 (file-name (git-file-name name version))
194 (sha256
195 (base32
196 "0fmrbl7dj8ndq1z7h13qgx3cv7vw3b1zf6krdrahcmx43bcdsix4"))))
197 ;; The mix-build-system assumes that Hex exists.
198 ;; We build Hex using the gnu-build-system.
199 ;; Other Elixir packages use the mix-build-system.
200 (build-system gnu-build-system)
201 (inputs (list elixir))
202 (arguments
203 (list
204 ;; Hex is needed to build packages used to test Hex.
205 ;; To avoid this circularity, we disable tests.
206 #:tests? #f
207 #:phases
208 #~(modify-phases %standard-phases
209 (delete 'bootstrap)
210 (delete 'configure)
211 (replace 'build
212 (lambda _
213 ;; Set deterministic compiler option.
214 (setenv "ERL_COMPILER_OPTIONS" "deterministic")
215 (setenv "MIX_ENV" "prod")
216 (invoke "mix" "compile")))
217 (replace 'install
218 (lambda _
219 (let* ((X.Y #$(version-major+minor
220 (package-version
221 (lookup-package-input this-package "elixir"))))
222 (out (string-append #$output "/lib/elixir/" X.Y "/hex"))
223 (prod-dir "_build/prod/lib/hex")
224 (prod-dir-mix (string-append prod-dir "/.mix")))
225 (and (directory-exists? prod-dir-mix)
226 (delete-file-recursively prod-dir-mix))
227 (mkdir-p out)
228 (copy-recursively prod-dir out)))))))
229 (synopsis "Package manager for the Erlang VM")
230 (description
231 "This project provides tasks that integrate with Mix, Elixir's build
232tool.")
233 (home-page "https://hexdocs.pm/hex/api-reference.html")
234 (license license:bsd-2)))