nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 version,
3 hash,
4 minimumOTPVersion,
5 maximumOTPVersion ? null,
6}:
7{
8 bash,
9 config,
10 coreutils,
11 curl,
12 debugInfo ? false,
13 erlang,
14 fetchFromGitHub,
15 lib,
16 makeWrapper,
17 nix-update-script,
18 stdenv,
19}:
20
21let
22 inherit (lib)
23 assertMsg
24 concatStringsSep
25 getVersion
26 optionals
27 optionalString
28 toInt
29 versions
30 versionAtLeast
31 versionOlder
32 ;
33
34 compatibilityMsg = ''
35 Unsupported elixir and erlang OTP combination.
36
37 elixir ${version}
38 erlang OTP ${getVersion erlang} is not >= ${minimumOTPVersion} ${
39 optionalString (maximumOTPVersion != null) "and <= ${maximumOTPVersion}"
40 }
41
42 See https://hexdocs.pm/elixir/${version}/compatibility-and-deprecations.html
43 '';
44
45 maxShiftMajor = toString ((toInt (versions.major maximumOTPVersion)) + 1);
46 maxAssert =
47 if (maximumOTPVersion == null) then
48 true
49 else
50 versionOlder (versions.major (getVersion erlang)) maxShiftMajor;
51 minAssert = versionAtLeast (getVersion erlang) minimumOTPVersion;
52 bothAssert = minAssert && maxAssert;
53
54 elixirShebang =
55 if stdenv.hostPlatform.isDarwin then
56 # Darwin disallows shebang scripts from using other scripts as their
57 # command. Use env as an intermediary instead of calling elixir directly
58 # (another shebang script).
59 # See https://github.com/NixOS/nixpkgs/pull/9671
60 "${coreutils}/bin/env $out/bin/elixir"
61 else
62 "$out/bin/elixir";
63
64 erlc_opts = [ "deterministic" ] ++ optionals debugInfo [ "debug_info" ];
65in
66if !config.allowAliases && !bothAssert then
67 # Don't throw without aliases to not break CI.
68 null
69else
70 assert assertMsg bothAssert compatibilityMsg;
71 stdenv.mkDerivation {
72 pname = "elixir";
73
74 src = fetchFromGitHub {
75 owner = "elixir-lang";
76 repo = "elixir";
77 rev = "v${version}";
78 inherit hash;
79 };
80
81 inherit version debugInfo;
82
83 nativeBuildInputs = [ makeWrapper ];
84 buildInputs = [ erlang ];
85
86 env = {
87 LANG = "C.UTF-8";
88 LC_TYPE = "C.UTF-8";
89 DESTDIR = placeholder "out";
90 PREFIX = "/";
91 ERL_COMPILER_OPTIONS = "[${concatStringsSep "," erlc_opts}]";
92 };
93
94 preBuild = ''
95 patchShebangs lib/elixir/scripts/generate_app.escript || true
96 '';
97
98 # copy stdlib source files for LSP access
99 postInstall = ''
100 for d in lib/*; do
101 cp -R "$d/lib" "$out/lib/elixir/$d"
102 done
103 '';
104
105 postFixup = ''
106 # Elixir binaries are shell scripts which run erl. Add some stuff
107 # to PATH so the scripts can run without problems.
108
109 for f in $out/bin/*; do
110 b=$(basename $f)
111 if [ "$b" = mix ]; then continue; fi
112 wrapProgram $f \
113 --prefix PATH ":" "${
114 lib.makeBinPath [
115 erlang
116 coreutils
117 curl
118 bash
119 ]
120 }"
121 done
122
123 substituteInPlace $out/bin/mix \
124 --replace "/usr/bin/env elixir" "${elixirShebang}"
125 '';
126
127 passthru.updateScript = nix-update-script {
128 extraArgs = [
129 "--version-regex"
130 "v(${lib.versions.major version}\\.${lib.versions.minor version}\\.[0-9\\-rc.]+)"
131 "--override-filename"
132 "pkgs/development/interpreters/elixir/${lib.versions.major version}.${lib.versions.minor version}.nix"
133 ];
134 };
135
136 meta = {
137 homepage = "https://elixir-lang.org/";
138 description = "Functional, meta-programming aware language built on top of the Erlang VM";
139 changelog = "https://github.com/elixir-lang/elixir/releases/tag/v${version}";
140
141 longDescription = ''
142 Elixir is a functional, meta-programming aware language built on
143 top of the Erlang VM. It is a dynamic language with flexible
144 syntax and macro support that leverages Erlang's abilities to
145 build concurrent, distributed and fault-tolerant applications
146 with hot code upgrades.
147 '';
148
149 license = lib.licenses.asl20;
150 platforms = lib.platforms.unix;
151 teams = [ lib.teams.beam ];
152 };
153 }