2016-06-15 15:15:06 +01:00
|
|
|
{ stdenv, writeText, elixir, erlang, hexRegistrySnapshot, hex, lib }:
|
2016-03-28 22:14:13 +01:00
|
|
|
|
|
|
|
{ name
|
|
|
|
, version
|
|
|
|
, src
|
|
|
|
, setupHook ? null
|
|
|
|
, buildInputs ? []
|
|
|
|
, beamDeps ? []
|
|
|
|
, postPatch ? ""
|
|
|
|
, compilePorts ? false
|
2016-06-15 15:19:44 +01:00
|
|
|
, installPhase ? null
|
|
|
|
, buildPhase ? null
|
|
|
|
, configurePhase ? null
|
2016-03-28 22:14:13 +01:00
|
|
|
, meta ? {}
|
2016-06-15 15:15:06 +01:00
|
|
|
, enableDebugInfo ? false
|
2016-03-28 22:14:13 +01:00
|
|
|
, ... }@attrs:
|
|
|
|
|
|
|
|
with stdenv.lib;
|
|
|
|
|
|
|
|
let
|
2016-06-15 15:15:06 +01:00
|
|
|
|
|
|
|
debugInfoFlag = lib.optionalString (enableDebugInfo || elixir.debugInfo) "--debug-info";
|
|
|
|
|
2016-03-28 22:14:13 +01:00
|
|
|
shell = drv: stdenv.mkDerivation {
|
|
|
|
name = "interactive-shell-${drv.name}";
|
|
|
|
buildInputs = [ drv ];
|
|
|
|
};
|
|
|
|
|
|
|
|
bootstrapper = ./mix-bootstrap;
|
|
|
|
|
|
|
|
pkg = self: stdenv.mkDerivation ( attrs // {
|
|
|
|
name = "${name}-${version}";
|
|
|
|
inherit version;
|
|
|
|
|
|
|
|
dontStrip = true;
|
|
|
|
|
|
|
|
inherit src;
|
|
|
|
|
|
|
|
setupHook = if setupHook == null
|
|
|
|
then writeText "setupHook.sh" ''
|
|
|
|
addToSearchPath ERL_LIBS "$1/lib/erlang/lib"
|
|
|
|
''
|
|
|
|
else setupHook;
|
|
|
|
|
|
|
|
inherit buildInputs;
|
|
|
|
propagatedBuildInputs = [ hexRegistrySnapshot hex elixir ] ++ beamDeps;
|
|
|
|
|
2016-06-15 15:19:44 +01:00
|
|
|
configurePhase = if configurePhase == null
|
|
|
|
then ''
|
2016-03-28 22:14:13 +01:00
|
|
|
runHook preConfigure
|
|
|
|
${erlang}/bin/escript ${bootstrapper}
|
|
|
|
runHook postConfigure
|
2016-06-15 15:19:44 +01:00
|
|
|
''
|
|
|
|
else configurePhase ;
|
|
|
|
|
2016-03-28 22:14:13 +01:00
|
|
|
|
2016-06-15 15:19:44 +01:00
|
|
|
buildPhase = if buildPhase == null
|
|
|
|
then ''
|
2016-03-28 22:14:13 +01:00
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
export HEX_OFFLINE=1
|
|
|
|
export HEX_HOME=`pwd`
|
|
|
|
export MIX_ENV=prod
|
|
|
|
|
2016-06-15 15:15:06 +01:00
|
|
|
MIX_ENV=prod mix compile ${debugInfoFlag} --no-deps-check
|
2016-03-28 22:14:13 +01:00
|
|
|
|
|
|
|
runHook postBuild
|
2016-06-15 15:19:44 +01:00
|
|
|
''
|
|
|
|
else buildPhase;
|
2016-03-28 22:14:13 +01:00
|
|
|
|
2016-06-15 15:19:44 +01:00
|
|
|
installPhase = if installPhase == null
|
|
|
|
then ''
|
2016-03-28 22:14:13 +01:00
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
MIXENV=prod
|
|
|
|
|
|
|
|
if [ -d "_build/shared" ]; then
|
|
|
|
MIXENV=shared
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p "$out/lib/erlang/lib/${name}-${version}"
|
|
|
|
for reldir in src ebin priv include; do
|
|
|
|
fd="_build/$MIXENV/lib/${name}/$reldir"
|
|
|
|
[ -d "$fd" ] || continue
|
|
|
|
cp -Hrt "$out/lib/erlang/lib/${name}-${version}" "$fd"
|
|
|
|
success=1
|
|
|
|
done
|
|
|
|
|
|
|
|
runHook postInstall
|
2016-06-15 15:19:44 +01:00
|
|
|
''
|
|
|
|
else installPhase;
|
2016-03-28 22:14:13 +01:00
|
|
|
|
|
|
|
passthru = {
|
|
|
|
packageName = name;
|
|
|
|
env = shell self;
|
|
|
|
inherit beamDeps;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
in fix pkg
|