2021-05-16 23:05:40 +00:00
|
|
|
{ stdenv, writeText, elixir, erlang, hex, lib }:
|
|
|
|
|
|
|
|
{ name
|
|
|
|
, version
|
|
|
|
, src
|
|
|
|
, buildInputs ? [ ]
|
2021-06-07 12:21:15 +00:00
|
|
|
, nativeBuildInputs ? [ ]
|
2021-05-16 23:05:40 +00:00
|
|
|
, beamDeps ? [ ]
|
|
|
|
, propagatedBuildInputs ? [ ]
|
|
|
|
, postPatch ? ""
|
|
|
|
, compilePorts ? false
|
|
|
|
, meta ? { }
|
|
|
|
, enableDebugInfo ? false
|
|
|
|
, mixEnv ? "prod"
|
|
|
|
, ...
|
|
|
|
}@attrs:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
shell = drv: stdenv.mkDerivation {
|
|
|
|
name = "interactive-shell-${drv.name}";
|
|
|
|
buildInputs = [ drv ];
|
|
|
|
};
|
|
|
|
|
|
|
|
pkg = self: stdenv.mkDerivation (attrs // {
|
|
|
|
name = "${name}-${version}";
|
2021-06-07 12:21:15 +00:00
|
|
|
inherit version src;
|
2021-05-16 23:05:40 +00:00
|
|
|
|
|
|
|
MIX_ENV = mixEnv;
|
|
|
|
MIX_DEBUG = if enableDebugInfo then 1 else 0;
|
|
|
|
HEX_OFFLINE = 1;
|
|
|
|
|
|
|
|
# add to ERL_LIBS so other modules can find at runtime.
|
|
|
|
# http://erlang.org/doc/man/code.html#code-path
|
2021-06-03 12:58:02 +00:00
|
|
|
# Mix also searches the code path when compiling with the --no-deps-check flag
|
2021-05-16 23:05:40 +00:00
|
|
|
setupHook = attrs.setupHook or
|
|
|
|
writeText "setupHook.sh" ''
|
|
|
|
addToSearchPath ERL_LIBS "$1/lib/erlang/lib"
|
|
|
|
'';
|
|
|
|
|
2021-06-07 12:21:15 +00:00
|
|
|
buildInputs = buildInputs ++ [ ];
|
|
|
|
nativeBuildInputs = nativeBuildInputs ++ [ elixir hex ];
|
2021-05-16 23:05:40 +00:00
|
|
|
propagatedBuildInputs = propagatedBuildInputs ++ beamDeps;
|
|
|
|
|
|
|
|
buildPhase = attrs.buildPhase or ''
|
|
|
|
runHook preBuild
|
|
|
|
export HEX_HOME="$TEMPDIR/hex"
|
|
|
|
export MIX_HOME="$TEMPDIR/mix"
|
|
|
|
mix compile --no-deps-check
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = attrs.installPhase or ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
# This uses the install path convention established by nixpkgs maintainers
|
|
|
|
# for all beam packages. Changing this will break compatibility with other
|
|
|
|
# builder functions like buildRebar3 and buildErlangMk.
|
|
|
|
mkdir -p "$out/lib/erlang/lib/${name}-${version}"
|
|
|
|
|
|
|
|
# Some packages like db_connection will use _build/shared instead of
|
|
|
|
# honoring the $MIX_ENV variable.
|
|
|
|
for reldir in _build/{$MIX_ENV,shared}/lib/${name}/{src,ebin,priv,include} ; do
|
|
|
|
if test -d $reldir ; then
|
|
|
|
# Some builds produce symlinks (eg: phoenix priv dircetory). They must
|
|
|
|
# be followed with -H flag.
|
|
|
|
cp -Hrt "$out/lib/erlang/lib/${name}-${version}" "$reldir"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
2021-06-06 10:56:33 +00:00
|
|
|
# stripping does not have any effect on beam files
|
|
|
|
# it is however needed for dependencies with NIFs like bcrypt for example
|
|
|
|
dontStrip = false;
|
|
|
|
|
2021-05-16 23:05:40 +00:00
|
|
|
passthru = {
|
|
|
|
packageName = name;
|
|
|
|
env = shell self;
|
|
|
|
inherit beamDeps;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
in
|
|
|
|
fix pkg
|