@@ -2,36 +2,85 @@
22 xmlns:xlink="http://www.w3.org/1999/xlink"
33 xml:id="sec-beam">
44
5− <title>Beam Languages (Erlang & Elixir)</title>
5+ <title>Beam Languages (Erlang, Elixir & LFE)</title>
66 <section xml:id="beam-introduction">
77 <title>Introduction</title>
88 <para>
99 In this document and related Nix expressions we use the term
10− <emphasis>Beam</emphasis> to describe the environment. Beam is
10+ <emphasis>Beam</emphasis> to describe the environment. BEAM is
1111 the name of the Erlang Virtial Machine and, as far as we know,
12− from a packaging perspective all languages that run on Beam are
12+ from a packaging perspective all languages that run on BEAM are
1313 interchangable. The things that do change, like the build
1414 system, are transperant to the users of the package. So we make
1515 no distinction.
1616 </para>
1717 </section>
18−<section xml:id="build-tools">
18+ <section xml:id="beam-structure">
19+ <title>Structure</title>
20+ <para>
21+ All Beam-related things are available via top-level
22+ <literal>beam</literal> attribute, which includes:
23+ </para>
24+ <itemizedlist>
25+ <listitem>
26+ <para>
27+ <literal>interpreters</literal>: contains a set of compilers running
28+ on Beam, including multiple Erlang/OTP versions
29+ (<literal>beam.interpreters.erlangR19</literal>, etc), Elixir
30+ (<literal>beam.interpreters.elixir</literal>) and LFE
31+ (<literal>beam.interpreters.lfe</literal>).
32+ </para>
33+ </listitem>
34+ <listitem>
35+ <para>
36+ <literal>packages</literal>: contains a set of package sets, each
37+ compiled with a specific Erlang/OTP version, e.g.
38+ <literal>beam.packages.erlangR19</literal>.
39+ </para>
40+ </listitem>
41+ </itemizedlist>
42+ <para>
43+ Default Erlang compiler is defined by
44+ <literal>beam.interpreters.erlang</literal> and aliased as
45+ <literal>erlang</literal>. Default package set with Beam packages is
46+ defined by <literal>beam.packages.erlang</literal> and aliased at
47+ top-level as <literal>beamPackages</literal>.
48+ </para>
49+ <para>
50+ If you want to create a package set built with a custom Erlang version,
51+ use lambda <literal>beam.packagesWith</literal>, which accepts an
52+ Erlang/OTP derivative and produces a package set similar to
53+ <literal>beam.packages.erlang</literal>.
54+ </para>
55+ <para>
56+ Many Erlang/OTP distributions available in
57+ <literal>beam.interpreters</literal> have their versions with ODBC and/or
58+ Java enabled. For example there's
59+ <literal>beam.interpreters.erlangR19_odbc_javac</literal> which
60+ corresponds to <literal>beam.interpreters.erlangR19</literal>.
61+ </para>
62+ <para>
63+ We also provide <literal>beam.packages.erlang.callPackage</literal>, which
64+ simplifies writing Beam package definitions, by injecting all packages from
65+ <literal>beam.packages.erlang</literal> into top-level context.
66+ </para>
67+ </section>
68+ <section xml:id="build-tools">
1969 <title>Build Tools</title>
2070 <section xml:id="build-tools-rebar3">
2171 <title>Rebar3</title>
2272 <para>
23− By default Rebar3 wants to manage it's own dependencies. In the
24− normal non-Nix, this is perfectly acceptable. In the Nix world it
25− is not. To support this we have created two versions of rebar3,
73+ By default Rebar3 wants to manage it's own dependencies. This is perfectly
74+ acceptable in the normal non-Nix setup. In the Nix world it is not. To
75+ support this we have created two versions of rebar3,
2676 <literal>rebar3</literal> and <literal>rebar3-open</literal>. The
27− <literal>rebar3</literal> version has been patched to remove the
28− ability to download anything from it. If you are not running it a
29− nix-shell or a nix-build then its probably not going to work for
30− you. <literal>rebar3-open</literal> is the normal, un-modified
31− rebar3. It should work exactly as would any other version of
32− rebar3. Any Erlang package should rely on
33− <literal>rebar3</literal> and thats really what you should be
34− using too.
77+ <literal>rebar3</literal> version has been patched to remove the ability
78+ to download anything from it. If you are not running it a nix-shell or a
79+ nix-build then its probably not going to work for you.
80+ <literal>rebar3-open</literal> is the normal, un-modified rebar3. It
81+ should work exactly as would any other version of rebar3. Any Erlang
82+ package should rely on <literal>rebar3</literal> and thats really what you
83+ should be using too. See <literal>buildRebar3</literal> below.
3584 </para>
3685 </section>
3786 <section xml:id="build-tools-other">
@@ -43,16 +92,17 @@
4392 <literal>buildMix</literal> and <literal>buildErlangMk</literal> derivations.
4493 </para>
4594 </section>
46−
4795</section>
4896
4997<section xml:id="how-to-install-beam-packages">
5098 <title>How to install Beam packages</title>
5199 <para>
52− Beam packages are not registered in the top level simply because
53− they are not relevant to the vast majority of Nix users. They are
54− installable using the <literal>beamPackages</literal> attribute
55− set.
100+ Beam packages are not registered in the top level simply because they are
101+ not relevant to the vast majority of Nix users. They are installable using
102+ the <literal>beam.packages.erlang</literal> attribute set and aliased as
103+ <literal>beamPackages</literal>. This attribute points at packages built by
104+ the default Erlang/OTP version in Nixpkgs as defined by
105+ <literal>beam.interpreters.erlang</literal>.
56106
57107 You can list the avialable packages in the
58108 <literal>beamPackages</literal> with the following command:
@@ -87,10 +137,11 @@ $ nix-env -f "<nixpkgs>" -iA beamPackages.ibrowse
87137 <section xml:id="rebar3-packages">
88138 <title>Rebar3 Packages</title>
89139 <para>
90− There is a Nix functional called
91− <literal>buildRebar3</literal>. We use this function to make a
92− derivation that understands how to build the rebar3 project. For
93− example, the epression we use to build the <link
140+ There is a Nix function called <literal>buildRebar3</literal> (defined
141+ in <literal>beam.packages.erlang.buildRebar3</literal> and aliased at
142+ top-level). We use this function to make a derivation that understands
143+ how to build the rebar3 project. For example, the expression we use to
144+ build the <link
94145 xlink:href="https://github.com/erlang-nix/hex2nix">hex2nix</link>
95146 project follows.
96147 </para>
@@ -111,10 +162,18 @@ $ nix-env -f "<nixpkgs>" -iA beamPackages.ibrowse
111162 beamDeps = [ ibrowse jsx erlware_commons ];
112163 }
113164 </programlisting>
165+ <para>
166+ This derivation is callable with
167+ <literal>beam.packages.erlang.callPackage</literal> (see above). If you
168+ want to call this package using normal <literal>callPackage</literal>,
169+ you should refer to dependency packages via
170+ <literal>beamPackages</literal>, e.g.
171+ <literal>beamPackages.ibrowse</literal>.
172+ </para>
114173 <para>
115174 The only visible difference between this derivation and
116175 something like <literal>stdenv.mkDerivation</literal> is that we
117− have added <literal>erlangDeps</literal> to the derivation. If
176+ have added <literal>beamDeps</literal> to the derivation. If
118177 you add your Beam dependencies here they will be correctly
119178 handled by the system.
120179 </para>
@@ -171,6 +230,27 @@ $ nix-env -f "<nixpkgs>" -iA beamPackages.ibrowse
171230 sha256 =
172231 "08459823fe1fd4f0325a8bf0c937a4520583a5a26d73b193040ab30a1dfc0b33";
173232 };
233+ beamDeps = [ plug absinthe ];
234+
235+ meta = {
236+ description = ''A plug for Absinthe, an experimental GraphQL
237+ toolkit'';
238+ license = stdenv.lib.licenses.bsd3;
239+ homepage = "https://github.com/CargoSense/absinthe_plug";
240+ };
241+ }
242+ </programlisting>
243+ <para>
244+ Alternatively one can use <literal>buildHex</literal> as a shortcut for the above:
245+ </para>
246+ <programlisting>
247+ { buildHex, buildMix, plug, absinthe }:
248+ buildHex {
249+ name = "absinthe_plug";
250+ version = "1.0.0";
251+ sha256 =
252+ "08459823fe1fd4f0325a8bf0c937a4520583a5a26d73b193040ab30a1dfc0b33";
253+ builder = buildMix;
174254 beamDeps = [ plug absinthe];
175255
176256 meta = {
@@ -264,7 +344,7 @@ let
264344 name = "hex2nix";
265345 version = "0.1.0";
266346 src = ./.;
267− erlangDeps = [ ibrowse jsx erlware_commons ];
347+ beamDeps = [ ibrowse jsx erlware_commons ];
268348 };
269349 drv = beamPackages.callPackage f {};
270350
@@ -272,10 +352,10 @@ in
272352 drv
273353 </programlisting>
274354 <section xml:id="building-in-a-shell">
275− <title>Building in a shell</title>
355+ <title>Building in a shell (for mix projects)</title>
276356 <para>
277− We can leveral the support of the Derivation, regardless of
278− which build Derivation is called by calling the commands themselv.s
357+ We can leverage the support of the Derivation, regardless of
358+ which build Derivation is called by calling the commands themselves.
279359 </para>
280360 <programlisting>
281361# =============================================================================
@@ -351,7 +431,7 @@ analyze: build plt
351431 <literal>hex2nix</literal> tool. Given the path to the Erlang
352432 modules (usually
353433 <literal>pkgs/development/erlang-modules</literal>). It will
354− happily dump a file called
434+ dump a file called
355435 <literal>hex-packages.nix</literal>. That file will contain all
356436 the packages that use a recognized build system in Hex. However,
357437 it can't know whether or not all those packages are buildable.