The documentation got a bit stale compared to actual contents of nixpkgs. This commit focuses on updating existing docs, not on making sure all details of beam packages are covered.
···2 xmlns:xlink="http://www.w3.org/1999/xlink"
3 xml:id="sec-beam">
45- <title>Beam Languages (Erlang & Elixir)</title>
6 <section xml:id="beam-introduction">
7 <title>Introduction</title>
8 <para>
9 In this document and related Nix expressions we use the term
10- <emphasis>Beam</emphasis> to describe the environment. Beam is
11 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
13 interchangable. The things that do change, like the build
14 system, are transperant to the users of the package. So we make
15 no distinction.
16 </para>
17 </section>
18-<section xml:id="build-tools">
0000000000000000000000000000000000000000000000000019 <title>Build Tools</title>
20 <section xml:id="build-tools-rebar3">
21 <title>Rebar3</title>
22 <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,
26 <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.
35 </para>
36 </section>
37 <section xml:id="build-tools-other">
···43 <literal>buildMix</literal> and <literal>buildErlangMk</literal> derivations.
44 </para>
45 </section>
46-47</section>
4849<section xml:id="how-to-install-beam-packages">
50 <title>How to install Beam packages</title>
51 <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.
005657 You can list the avialable packages in the
58 <literal>beamPackages</literal> with the following command:
···87 <section xml:id="rebar3-packages">
88 <title>Rebar3 Packages</title>
89 <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
094 xlink:href="https://github.com/erlang-nix/hex2nix">hex2nix</link>
95 project follows.
96 </para>
···112 }
113 </programlisting>
114 <para>
00000000115 The only visible difference between this derivation and
116 something like <literal>stdenv.mkDerivation</literal> is that we
117- have added <literal>erlangDeps</literal> to the derivation. If
118 you add your Beam dependencies here they will be correctly
119 handled by the system.
120 </para>
···171 sha256 =
172 "08459823fe1fd4f0325a8bf0c937a4520583a5a26d73b193040ab30a1dfc0b33";
173 };
000000000000000000000174 beamDeps = [ plug absinthe];
175176 meta = {
···264 name = "hex2nix";
265 version = "0.1.0";
266 src = ./.;
267- erlangDeps = [ ibrowse jsx erlware_commons ];
268 };
269 drv = beamPackages.callPackage f {};
270···272 drv
273 </programlisting>
274 <section xml:id="building-in-a-shell">
275- <title>Building in a shell</title>
276 <para>
277- We can leveral the support of the Derivation, regardless of
278- which build Derivation is called by calling the commands themselv.s
279 </para>
280 <programlisting>
281# =============================================================================
···351 <literal>hex2nix</literal> tool. Given the path to the Erlang
352 modules (usually
353 <literal>pkgs/development/erlang-modules</literal>). It will
354- happily dump a file called
355 <literal>hex-packages.nix</literal>. That file will contain all
356 the packages that use a recognized build system in Hex. However,
357 it can't know whether or not all those packages are buildable.
···2 xmlns:xlink="http://www.w3.org/1999/xlink"
3 xml:id="sec-beam">
45+ <title>Beam Languages (Erlang, Elixir & LFE)</title>
6 <section xml:id="beam-introduction">
7 <title>Introduction</title>
8 <para>
9 In this document and related Nix expressions we use the term
10+ <emphasis>Beam</emphasis> to describe the environment. BEAM is
11 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
13 interchangable. The things that do change, like the build
14 system, are transperant to the users of the package. So we make
15 no distinction.
16 </para>
17 </section>
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">
69 <title>Build Tools</title>
70 <section xml:id="build-tools-rebar3">
71 <title>Rebar3</title>
72 <para>
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,
76 <literal>rebar3</literal> and <literal>rebar3-open</literal>. The
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.
084 </para>
85 </section>
86 <section xml:id="build-tools-other">
···92 <literal>buildMix</literal> and <literal>buildErlangMk</literal> derivations.
93 </para>
94 </section>
095</section>
9697<section xml:id="how-to-install-beam-packages">
98 <title>How to install Beam packages</title>
99 <para>
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>.
106107 You can list the avialable packages in the
108 <literal>beamPackages</literal> with the following command:
···137 <section xml:id="rebar3-packages">
138 <title>Rebar3 Packages</title>
139 <para>
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
145 xlink:href="https://github.com/erlang-nix/hex2nix">hex2nix</link>
146 project follows.
147 </para>
···163 }
164 </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>
173+ <para>
174 The only visible difference between this derivation and
175 something like <literal>stdenv.mkDerivation</literal> is that we
176+ have added <literal>beamDeps</literal> to the derivation. If
177 you add your Beam dependencies here they will be correctly
178 handled by the system.
179 </para>
···230 sha256 =
231 "08459823fe1fd4f0325a8bf0c937a4520583a5a26d73b193040ab30a1dfc0b33";
232 };
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;
254 beamDeps = [ plug absinthe];
255256 meta = {
···344 name = "hex2nix";
345 version = "0.1.0";
346 src = ./.;
347+ beamDeps = [ ibrowse jsx erlware_commons ];
348 };
349 drv = beamPackages.callPackage f {};
350···352 drv
353 </programlisting>
354 <section xml:id="building-in-a-shell">
355+ <title>Building in a shell (for mix projects)</title>
356 <para>
357+ We can leverage the support of the Derivation, regardless of
358+ which build Derivation is called by calling the commands themselves.
359 </para>
360 <programlisting>
361# =============================================================================
···431 <literal>hex2nix</literal> tool. Given the path to the Erlang
432 modules (usually
433 <literal>pkgs/development/erlang-modules</literal>). It will
434+ dump a file called
435 <literal>hex-packages.nix</literal>. That file will contain all
436 the packages that use a recognized build system in Hex. However,
437 it can't know whether or not all those packages are buildable.
+9-11
pkgs/development/beam-modules/mix-bootstrap
···3%%! -smp enable
4%%% ---------------------------------------------------------------------------
5%%% @doc
6-%%% The purpose of this command is to prepare a rebar3 project so that
7-%%% rebar3 understands that the dependencies are all already
8-%%% installed. If you want a hygienic build on nix then you must run
9-%%% this command before running rebar3. I suggest that you add a
10-%%% `Makefile` to your project and have the bootstrap command be a
11-%%% dependency of the build commands. See the nix documentation for
12%%% more information.
13%%%
14-%%% This command designed to have as few dependencies as possible so
15-%%% that it can be a dependency of root level packages like rebar3. To
16-%%% that end it does many things in a fairly simplistic way. That is
17-%%% by design.
18%%%
19%%% ### Assumptions
20%%%
···3738%% @doc
39%% This takes an app name in the standard OTP <name>-<version> format
40-%% and returns just the app name. Why? because rebar is doesn't
41%% respect OTP conventions in some cases.
42-spec fixup_app_name(file:name()) -> string().
43fixup_app_name(Path) ->
···3%%! -smp enable
4%%% ---------------------------------------------------------------------------
5%%% @doc
6+%%% The purpose of this command is to prepare a mix project so that mix
7+%%% understands that the dependencies are all already installed. If you want a
8+%%% hygienic build on nix then you must run this command before running mix. I
9+%%% suggest that you add a `Makefile` to your project and have the bootstrap
10+%%% command be a dependency of the build commands. See the nix documentation for
011%%% more information.
12%%%
13+%%% This command designed to have as few dependencies as possible so that it can
14+%%% be a dependency of root level packages like mix. To that end it does many
15+%%% things in a fairly simplistic way. That is by design.
016%%%
17%%% ### Assumptions
18%%%
···3536%% @doc
37%% This takes an app name in the standard OTP <name>-<version> format
38+%% and returns just the app name. Why? Because rebar doesn't
39%% respect OTP conventions in some cases.
40-spec fixup_app_name(file:name()) -> string().
41fixup_app_name(Path) ->
···146147%% @doc
148%% This takes an app name in the standard OTP <name>-<version> format
149-%% and returns just the app name. Why? because rebar doesn't
150%% respect OTP conventions in some cases.
151-spec fixup_app_name(string()) -> string().
152fixup_app_name(FileName) ->
···146147%% @doc
148%% This takes an app name in the standard OTP <name>-<version> format
149+%% and returns just the app name. Why? Because rebar doesn't
150%% respect OTP conventions in some cases.
151-spec fixup_app_name(string()) -> string().
152fixup_app_name(FileName) ->