nixpkgs/doc/languages-frameworks/beam.xml

160 lines
5.9 KiB
XML
Raw Normal View History

2016-05-22 10:05:37 +01:00
<section xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
2016-05-22 10:05:37 +01:00
xml:id="sec-beam">
2018-05-02 00:54:21 +01:00
<title>BEAM Languages (Erlang, Elixir &amp; LFE)</title>
2018-05-02 00:54:21 +01:00
<section xml:id="beam-introduction">
<title>Introduction</title>
<para>
2019-09-18 21:12:54 +01:00
In this document and related Nix expressions, we use the term, <emphasis>BEAM</emphasis>, to describe the environment. BEAM is the name of the Erlang Virtual Machine and, as far as we're concerned, from a packaging perspective, all languages that run on the BEAM are interchangeable. That which varies, like the build system, is transparent to users of any given BEAM package, so we make no distinction.
2018-05-02 00:54:21 +01:00
</para>
</section>
<section xml:id="beam-structure">
<title>Structure</title>
<para>
2019-09-18 21:12:54 +01:00
All BEAM-related expressions are available via the top-level <literal>beam</literal> attribute, which includes:
2018-05-02 00:54:21 +01:00
</para>
<itemizedlist>
<listitem>
<para>
2019-09-18 21:12:54 +01:00
<literal>interpreters</literal>: a set of compilers running on the BEAM, including multiple Erlang/OTP versions (<literal>beam.interpreters.erlangR19</literal>, etc), Elixir (<literal>beam.interpreters.elixir</literal>) and LFE (<literal>beam.interpreters.lfe</literal>).
</para>
2018-05-02 00:54:21 +01:00
</listitem>
<listitem>
<para>
<literal>packages</literal>: a set of package builders (Mix and rebar3), each compiled with a specific Erlang/OTP version, e.g. <literal>beam.packages.erlangR19</literal>.
</para>
2018-05-02 00:54:21 +01:00
</listitem>
</itemizedlist>
<para>
2019-09-18 21:12:54 +01:00
The default Erlang compiler, defined by <literal>beam.interpreters.erlang</literal>, is aliased as <literal>erlang</literal>. The default BEAM package set is defined by <literal>beam.packages.erlang</literal> and aliased at the top level as <literal>beamPackages</literal>.
2018-05-02 00:54:21 +01:00
</para>
<para>
To create a package builder built with a custom Erlang version, use the lambda, <literal>beam.packagesWith</literal>, which accepts an Erlang/OTP derivation and produces a package builder similar to <literal>beam.packages.erlang</literal>.
2018-05-02 00:54:21 +01:00
</para>
<para>
Many Erlang/OTP distributions available in <literal>beam.interpreters</literal> have versions with ODBC and/or Java enabled or without wx (no observer support). For example, there's <literal>beam.interpreters.erlangR22_odbc_javac</literal>, which corresponds to <literal>beam.interpreters.erlangR22</literal> and <literal>beam.interpreters.erlangR22_nox</literal>, which corresponds to <literal>beam.interpreters.erlangR22</literal>.
2018-05-02 00:54:21 +01:00
</para>
</section>
<section xml:id="build-tools">
<title>Build Tools</title>
2018-05-02 00:54:21 +01:00
<section xml:id="build-tools-rebar3">
2018-05-02 00:54:21 +01:00
<title>Rebar3</title>
<para>
We provide a version of Rebar3, under <literal>rebar3</literal>. We also provide a helper to fetch Rebar3 dependencies from a lockfile under <literal>fetchRebar3Deps</literal>.
2018-05-02 00:54:21 +01:00
</para>
</section>
2018-05-02 00:54:21 +01:00
<section xml:id="build-tools-other">
2018-05-02 00:54:21 +01:00
<title>Mix &amp; Erlang.mk</title>
<para>
2019-09-18 21:12:54 +01:00
Both Mix and Erlang.mk work exactly as expected. There is a bootstrap process that needs to be run for both, however, which is supported by the <literal>buildMix</literal> and <literal>buildErlangMk</literal> derivations, respectively.
2018-05-02 00:54:21 +01:00
</para>
</section>
2018-05-02 00:54:21 +01:00
</section>
2018-05-02 00:54:21 +01:00
<section xml:id="how-to-install-beam-packages">
<title>How to Install BEAM Packages</title>
2018-05-02 00:54:21 +01:00
<para>
BEAM builders are not registered at the top level, simply because they are not relevant to the vast majority of Nix users.
To install any of those builders into your profile, refer to them by their attribute path <literal>beamPackages.rebar3</literal>:
</para>
2018-05-02 00:54:21 +01:00
<screen>
<prompt>$ </prompt>nix-env -f &quot;&lt;nixpkgs&gt;&quot; -iA beamPackages.rebar3
</screen>
</section>
2018-05-02 00:54:21 +01:00
<section xml:id="packaging-beam-applications">
<title>Packaging BEAM Applications</title>
2018-05-02 00:54:21 +01:00
<section xml:id="packaging-erlang-applications">
2018-05-02 00:54:21 +01:00
<title>Erlang Applications</title>
<section xml:id="rebar3-packages">
<title>Rebar3 Packages</title>
<para>
The Nix function, <literal>buildRebar3</literal>, defined in <literal>beam.packages.erlang.buildRebar3</literal> and aliased at the top level, can be used to build a derivation that understands how to build a Rebar3 project.
2018-05-02 00:54:21 +01:00
</para>
<para>
2019-09-18 21:12:54 +01:00
If a package needs to compile native code via Rebar3's port compilation mechanism, add <literal>compilePort = true;</literal> to the derivation.
2018-05-02 00:54:21 +01:00
</para>
</section>
<section xml:id="erlang-mk-packages">
<title>Erlang.mk Packages</title>
<para>
2019-09-18 21:12:54 +01:00
Erlang.mk functions similarly to Rebar3, except we use <literal>buildErlangMk</literal> instead of <literal>buildRebar3</literal>.
2018-05-02 00:54:21 +01:00
</para>
</section>
<section xml:id="mix-packages">
<title>Mix Packages</title>
<para>
2019-09-18 21:12:54 +01:00
Mix functions similarly to Rebar3, except we use <literal>buildMix</literal> instead of <literal>buildRebar3</literal>.
2018-05-02 00:54:21 +01:00
</para>
<para>
Alternatively, we can use <literal>buildHex</literal> as a shortcut:
</para>
</section>
</section>
2018-05-02 00:54:21 +01:00
</section>
<section xml:id="how-to-develop">
<title>How to Develop</title>
2018-05-02 00:54:21 +01:00
<section xml:id="creating-a-shell">
2018-05-02 00:54:21 +01:00
<title>Creating a Shell</title>
<para>
Usually, we need to create a <literal>shell.nix</literal> file and do our development inside of the environment specified therein. Just install your version of erlang and other interpreter, and then user your normal build tools.
As an example with elixir:
</para>
2018-05-02 00:54:21 +01:00
<programlisting>
{ pkgs ? import &quot;&lt;nixpkgs&quot;&gt; {} }:
with pkgs;
let
elixir = beam.packages.erlangR22.elixir_1_9;
in
mkShell {
buildInputs = [ elixir ];
ERL_INCLUDE_PATH="${erlang}/lib/erlang/usr/include";
}
2019-06-17 11:17:16 +01:00
</programlisting>
2018-05-02 00:54:21 +01:00
<section xml:id="building-in-a-shell">
<title>Building in a Shell (for Mix Projects)</title>
2018-05-02 00:54:21 +01:00
<para>
2019-09-18 21:12:54 +01:00
Using a <literal>shell.nix</literal> as described (see <xref
linkend="creating-a-shell"/>) should just work.
</para>
2018-05-02 00:54:21 +01:00
</section>
</section>
2018-05-02 00:54:21 +01:00
</section>
2016-05-22 10:05:37 +01:00
</section>