1 { stdenv, writeText, elixir, erlang, hex, lib }:
7 , nativeBuildInputs ? [ ]
8 , erlangCompilerOptions ? [ ]
9 # Deterministic Erlang builds remove full system paths from debug information
10 # among other things to keep builds more reproducible. See their docs for more:
11 # https://www.erlang.org/doc/man/compile
12 , erlangDeterministicBuilds ? true
14 , propagatedBuildInputs ? [ ]
16 , compilePorts ? false
18 , enableDebugInfo ? false
20 # A config directory that is considered for all the dependencies of an app, typically in $src/config/
21 # This was initially added, as some of Mobilizon's dependencies need to access the config at build time.
22 , appConfigPath ? null
27 shell = drv: stdenv.mkDerivation {
28 name = "interactive-shell-${drv.name}";
29 buildInputs = [ drv ];
32 pkg = self: stdenv.mkDerivation (attrs // {
33 name = "${name}-${version}";
37 MIX_DEBUG = if enableDebugInfo then 1 else 0;
40 ERL_COMPILER_OPTIONS =
42 options = erlangCompilerOptions ++ lib.optionals erlangDeterministicBuilds [ "deterministic" ];
44 "[${lib.concatStringsSep "," options}]";
48 # add to ERL_LIBS so other modules can find at runtime.
49 # http://erlang.org/doc/man/code.html#code-path
50 # Mix also searches the code path when compiling with the --no-deps-check flag
51 setupHook = attrs.setupHook or
52 writeText "setupHook.sh" ''
53 addToSearchPath ERL_LIBS "$1/lib/erlang/lib"
56 buildInputs = buildInputs ++ [ ];
57 nativeBuildInputs = nativeBuildInputs ++ [ elixir hex ];
58 propagatedBuildInputs = propagatedBuildInputs ++ beamDeps;
60 configurePhase = attrs.configurePhase or ''
63 ${./mix-configure-hook.sh}
64 ${lib.optionalString (!isNull appConfigPath)
65 # Due to https://hexdocs.pm/elixir/main/Config.html the config directory
66 # of a library seems to be not considered, as config is always
67 # application specific. So we can safely delete it.
70 cp -r ${appConfigPath} config
76 buildPhase = attrs.buildPhase or ''
78 export HEX_HOME="$TEMPDIR/hex"
79 export MIX_HOME="$TEMPDIR/mix"
80 mix compile --no-deps-check
84 installPhase = attrs.installPhase or ''
87 # This uses the install path convention established by nixpkgs maintainers
88 # for all beam packages. Changing this will break compatibility with other
89 # builder functions like buildRebar3 and buildErlangMk.
90 mkdir -p "$out/lib/erlang/lib/${name}-${version}"
92 # Some packages like db_connection will use _build/shared instead of
93 # honoring the $MIX_ENV variable.
94 for reldir in _build/{$MIX_ENV,shared}/lib/${name}/{src,ebin,priv,include} ; do
95 if test -d $reldir ; then
96 # Some builds produce symlinks (eg: phoenix priv dircetory). They must
97 # be followed with -H flag.
98 cp -Hrt "$out/lib/erlang/lib/${name}-${version}" "$reldir"
102 # Copy the source so it can be used by dependent packages. For example,
103 # phoenix applications need the source of phoenix and phoenix_html to
104 # build javascript and css assets.
106 cp -r $src/* "$out/src"
111 # stripping does not have any effect on beam files
112 # it is however needed for dependencies with NIFs like bcrypt for example