2016-03-28 23:14:13 +02:00
|
|
|
{ stdenv, writeText, erlang, rebar3, openssl, libyaml,
|
2017-04-16 10:25:07 +02:00
|
|
|
pc, lib }:
|
2016-01-11 00:25:45 +01:00
|
|
|
|
|
|
|
{ name, version
|
|
|
|
, src
|
|
|
|
, setupHook ? null
|
2016-03-28 23:14:13 +02:00
|
|
|
, buildInputs ? [], beamDeps ? [], buildPlugins ? []
|
2016-01-11 00:25:45 +01:00
|
|
|
, postPatch ? ""
|
|
|
|
, compilePorts ? false
|
2016-01-11 03:39:37 +01:00
|
|
|
, installPhase ? null
|
2016-06-15 16:19:44 +02:00
|
|
|
, buildPhase ? null
|
|
|
|
, configurePhase ? null
|
2016-01-11 00:25:45 +01:00
|
|
|
, meta ? {}
|
2016-06-15 16:15:06 +02:00
|
|
|
, enableDebugInfo ? false
|
2016-01-11 00:25:45 +01:00
|
|
|
, ... }@attrs:
|
|
|
|
|
|
|
|
with stdenv.lib;
|
|
|
|
|
|
|
|
let
|
2016-06-15 16:15:06 +02:00
|
|
|
debugInfoFlag = lib.optionalString (enableDebugInfo || erlang.debugInfo) "debug-info";
|
|
|
|
|
2016-01-17 21:00:12 +01:00
|
|
|
ownPlugins = buildPlugins ++ (if compilePorts then [pc] else []);
|
2016-01-11 00:25:45 +01:00
|
|
|
|
|
|
|
shell = drv: stdenv.mkDerivation {
|
|
|
|
name = "interactive-shell-${drv.name}";
|
|
|
|
buildInputs = [ drv ];
|
|
|
|
};
|
|
|
|
|
2017-02-18 14:25:24 +01:00
|
|
|
customPhases = filterAttrs
|
|
|
|
(_: v: v != null)
|
|
|
|
{ inherit setupHook configurePhase buildPhase installPhase; };
|
|
|
|
|
2016-01-11 00:25:45 +01:00
|
|
|
pkg = self: stdenv.mkDerivation (attrs // {
|
|
|
|
|
|
|
|
name = "${name}-${version}";
|
|
|
|
inherit version;
|
|
|
|
|
|
|
|
buildInputs = buildInputs ++ [ erlang rebar3 openssl libyaml ];
|
2016-03-28 23:14:13 +02:00
|
|
|
propagatedBuildInputs = unique (beamDeps ++ ownPlugins);
|
2016-01-17 21:00:12 +01:00
|
|
|
|
2016-03-28 23:14:13 +02:00
|
|
|
dontStrip = true;
|
2016-01-17 21:00:12 +01:00
|
|
|
# The following are used by rebar3-nix-bootstrap
|
|
|
|
inherit compilePorts;
|
|
|
|
buildPlugins = ownPlugins;
|
2016-01-11 00:25:45 +01:00
|
|
|
|
|
|
|
inherit src;
|
|
|
|
|
2017-02-18 14:25:24 +01:00
|
|
|
setupHook = writeText "setupHook.sh" ''
|
2016-01-11 00:25:45 +01:00
|
|
|
addToSearchPath ERL_LIBS "$1/lib/erlang/lib/"
|
2017-02-18 14:25:24 +01:00
|
|
|
'';
|
2016-01-11 00:25:45 +01:00
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
rm -f rebar rebar3
|
2016-08-29 23:20:59 +02:00
|
|
|
'' + postPatch;
|
2016-01-11 00:25:45 +01:00
|
|
|
|
2017-02-18 14:25:24 +01:00
|
|
|
configurePhase = ''
|
2016-01-11 00:25:45 +01:00
|
|
|
runHook preConfigure
|
2016-06-15 16:15:06 +02:00
|
|
|
${erlang}/bin/escript ${rebar3.bootstrapper} ${debugInfoFlag}
|
2016-01-11 00:25:45 +01:00
|
|
|
runHook postConfigure
|
2017-02-18 14:25:24 +01:00
|
|
|
'';
|
2016-01-11 00:25:45 +01:00
|
|
|
|
2017-02-18 14:25:24 +01:00
|
|
|
buildPhase = ''
|
2016-01-11 00:25:45 +01:00
|
|
|
runHook preBuild
|
|
|
|
HOME=. rebar3 compile
|
|
|
|
${if compilePorts then ''
|
|
|
|
HOME=. rebar3 pc compile
|
|
|
|
'' else ''''}
|
|
|
|
runHook postBuild
|
2017-02-18 14:25:24 +01:00
|
|
|
'';
|
2016-01-11 00:25:45 +01:00
|
|
|
|
2017-02-18 14:25:24 +01:00
|
|
|
installPhase = ''
|
2016-01-11 00:25:45 +01:00
|
|
|
runHook preInstall
|
|
|
|
mkdir -p "$out/lib/erlang/lib/${name}-${version}"
|
|
|
|
for reldir in src ebin priv include; do
|
|
|
|
fd="_build/default/lib/${name}/$reldir"
|
|
|
|
[ -d "$fd" ] || continue
|
|
|
|
cp -Hrt "$out/lib/erlang/lib/${name}-${version}" "$fd"
|
|
|
|
success=1
|
|
|
|
done
|
|
|
|
runHook postInstall
|
2017-02-18 14:25:24 +01:00
|
|
|
'';
|
2016-01-11 00:25:45 +01:00
|
|
|
|
|
|
|
meta = {
|
|
|
|
inherit (erlang.meta) platforms;
|
|
|
|
} // meta;
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
packageName = name;
|
|
|
|
env = shell self;
|
2016-03-28 23:14:13 +02:00
|
|
|
inherit beamDeps;
|
2016-01-11 00:25:45 +01:00
|
|
|
};
|
2017-02-18 14:25:24 +01:00
|
|
|
} // customPhases);
|
2016-01-11 00:25:45 +01:00
|
|
|
in
|
|
|
|
fix pkg
|