2016-01-10 22:48:44 +00:00
|
|
|
{ stdenv, writeText, erlang, rebar3, openssl, libyaml, fetchHex, fetchFromGitHub,
|
2015-12-18 22:51:51 +00:00
|
|
|
rebar3-pc, buildEnv }:
|
2015-12-09 23:12:37 +00:00
|
|
|
|
2016-01-10 22:48:44 +00:00
|
|
|
{ name, version, sha256 ? false
|
|
|
|
, src ? null
|
|
|
|
, setupHook ? null
|
2015-12-10 20:39:13 +00:00
|
|
|
, hexPkg ? name
|
2015-12-10 22:11:25 +00:00
|
|
|
, buildInputs ? [], erlangDeps ? [], pluginDeps ? []
|
2015-12-09 23:12:37 +00:00
|
|
|
, postPatch ? ""
|
2015-12-10 21:39:42 +00:00
|
|
|
, compilePorts ? false
|
2015-12-12 23:03:42 +00:00
|
|
|
, meta ? {}
|
2015-12-09 23:12:37 +00:00
|
|
|
, ... }@attrs:
|
|
|
|
|
|
|
|
with stdenv.lib;
|
|
|
|
|
2015-12-18 22:51:51 +00:00
|
|
|
let
|
|
|
|
plugins = pluginDeps ++ (if compilePorts then [rebar3-pc] else []);
|
2016-01-10 22:48:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
shell = drv: stdenv.mkDerivation {
|
|
|
|
name = "interactive-shell-${drv.name}";
|
|
|
|
buildInputs = [ drv ];
|
|
|
|
};
|
|
|
|
|
2015-12-18 22:51:51 +00:00
|
|
|
pkg = self: stdenv.mkDerivation (attrs // {
|
2016-01-10 22:48:44 +00:00
|
|
|
|
2015-12-18 22:51:51 +00:00
|
|
|
name = "${name}-${version}";
|
2016-01-10 22:48:44 +00:00
|
|
|
inherit version;
|
2015-12-18 22:51:51 +00:00
|
|
|
|
|
|
|
buildInputs = buildInputs ++ [ erlang rebar3 openssl libyaml ];
|
2016-01-10 22:48:44 +00:00
|
|
|
propagatedBuildInputs = erlangDeps ++ plugins;
|
2015-12-18 22:51:51 +00:00
|
|
|
|
2016-01-10 22:48:44 +00:00
|
|
|
src = if src == null then fetchHex {
|
2015-12-18 22:51:51 +00:00
|
|
|
pkg = hexPkg;
|
|
|
|
inherit version;
|
|
|
|
inherit sha256;
|
2016-01-10 22:48:44 +00:00
|
|
|
} else src;
|
|
|
|
|
|
|
|
setupHook = if setupHook == null
|
|
|
|
then writeText "setupHook.sh" ''
|
|
|
|
addToSearchPath ERL_LIBS "$1/lib/erlang/lib/"
|
|
|
|
''
|
|
|
|
else setupHook;
|
2015-12-18 22:51:51 +00:00
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
rm -f rebar rebar3
|
|
|
|
'';
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
runHook preConfigure
|
2016-01-10 22:48:44 +00:00
|
|
|
rebar3-nix-bootstrap
|
2015-12-18 22:51:51 +00:00
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
HOME=. rebar3 compile
|
|
|
|
${if compilePorts then ''
|
|
|
|
HOME=. rebar3 pc compile
|
|
|
|
'' else ''''}
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
2016-01-10 22:48:44 +00:00
|
|
|
mkdir -p "$out/lib/erlang/lib/${name}-${version}"
|
2015-12-18 22:51:51 +00:00
|
|
|
for reldir in src ebin priv include; do
|
|
|
|
fd="_build/default/lib/${name}/$reldir"
|
|
|
|
[ -d "$fd" ] || continue
|
2016-01-10 22:48:44 +00:00
|
|
|
cp -Hrt "$out/lib/erlang/lib/${name}-${version}" "$fd"
|
2015-12-18 22:51:51 +00:00
|
|
|
success=1
|
|
|
|
done
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
inherit (erlang.meta) platforms;
|
|
|
|
} // meta;
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
packageName = name;
|
|
|
|
env = shell self;
|
|
|
|
inherit erlangDeps;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
in
|
|
|
|
fix pkg
|