| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 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 |
| 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 | |
| 71 | |
| 72 | |
| 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 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 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 | |
| 94 | |
| 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 | |
| 107 | |
| 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 | |
| 120 | (setenv "ERL_COMPILER_OPTIONS" "deterministic")))
|
| 121 | (add-after 'build 'restore-and-recompile
|
| 122 | |
| 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 | |
| 130 | |
| 131 | |
| 132 | |
| 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 | |
| 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 | |
| 148 | |
| 149 | |
| 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
|
| 158 | System.put_env(\"MIX_REBAR3\", System.get_env(\"MIX_REBAR3\", \"~a\"))
|
| 159 | Mix.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
|
| 178 | scalable and maintainable applications. Elixir leverages the Erlang VM, known
|
| 179 | for running low-latency, distributed and fault-tolerant systems, while also
|
| 180 | being 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 | |
| 198 | |
| 199 | |
| 200 | (build-system gnu-build-system)
|
| 201 | (inputs (list elixir))
|
| 202 | (arguments
|
| 203 | (list
|
| 204 | |
| 205 | |
| 206 | #:tests? #f
|
| 207 | #:phases
|
| 208 | #~(modify-phases %standard-phases
|
| 209 | (delete 'bootstrap)
|
| 210 | (delete 'configure)
|
| 211 | (replace 'build
|
| 212 | (lambda _
|
| 213 | |
| 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
|
| 232 | tool.")
|
| 233 | (home-page "https://hexdocs.pm/hex/api-reference.html")
|
| 234 | (license license:bsd-2)))
|