2021-05-17 16:51:58 +01:00
|
|
|
{ stdenv, erlang, rebar3WithPlugins, openssl,
|
2019-06-16 20:59:06 +01:00
|
|
|
lib }:
|
2019-01-16 21:51:19 +00:00
|
|
|
|
|
|
|
{ name, version
|
|
|
|
, src
|
2021-05-17 16:51:58 +01:00
|
|
|
, beamDeps ? []
|
|
|
|
, buildPlugins ? []
|
2019-01-16 21:51:19 +00:00
|
|
|
, checkouts ? null
|
|
|
|
, releaseType
|
|
|
|
, buildInputs ? []
|
|
|
|
, setupHook ? null
|
|
|
|
, profile ? "default"
|
|
|
|
, installPhase ? null
|
|
|
|
, buildPhase ? null
|
|
|
|
, configurePhase ? null
|
|
|
|
, meta ? {}
|
|
|
|
, ... }@attrs:
|
|
|
|
|
2021-01-23 17:15:07 +00:00
|
|
|
with lib;
|
2019-01-16 21:51:19 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
shell = drv: stdenv.mkDerivation {
|
|
|
|
name = "interactive-shell-${drv.name}";
|
|
|
|
buildInputs = [ drv ];
|
|
|
|
};
|
|
|
|
|
|
|
|
customPhases = filterAttrs
|
|
|
|
(_: v: v != null)
|
|
|
|
{ inherit setupHook configurePhase buildPhase installPhase; };
|
|
|
|
|
2021-05-17 16:51:58 +01:00
|
|
|
# When using the `beamDeps` argument, it is important that we use
|
|
|
|
# `rebar3WithPlugins` here even when there are no plugins. The vanilla
|
|
|
|
# `rebar3` package is an escript archive with bundled dependencies which can
|
|
|
|
# interfere with those in the app we are trying to build. `rebar3WithPlugins`
|
|
|
|
# doesn't have this issue since it puts its own deps last on the code path.
|
|
|
|
rebar3 = rebar3WithPlugins {
|
|
|
|
plugins = buildPlugins;
|
|
|
|
};
|
|
|
|
|
|
|
|
pkg =
|
|
|
|
assert beamDeps != [] -> checkouts == null;
|
|
|
|
self: stdenv.mkDerivation (attrs // {
|
2019-01-16 21:51:19 +00:00
|
|
|
|
|
|
|
name = "${name}-${version}";
|
|
|
|
inherit version;
|
|
|
|
|
2021-05-17 16:51:58 +01:00
|
|
|
buildInputs = buildInputs ++ [ erlang rebar3 openssl ] ++ beamDeps;
|
2019-01-16 21:51:19 +00:00
|
|
|
|
|
|
|
dontStrip = true;
|
|
|
|
|
|
|
|
inherit src;
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
runHook preConfigure
|
2021-05-17 16:51:58 +01:00
|
|
|
${lib.optionalString (checkouts != null)
|
|
|
|
"cp --no-preserve=all -R ${checkouts}/_checkouts ."}
|
|
|
|
${# Prevent rebar3 from trying to manage deps
|
|
|
|
lib.optionalString (beamDeps != [ ]) ''
|
|
|
|
erl -noshell -eval '
|
|
|
|
{ok, Terms0} = file:consult("rebar.config"),
|
|
|
|
Terms = lists:keydelete(deps, 1, Terms0),
|
|
|
|
ok = file:write_file("rebar.config", [io_lib:format("~tp.~n", [T]) || T <- Terms]),
|
|
|
|
init:stop(0)
|
|
|
|
'
|
|
|
|
rm -f rebar.lock
|
|
|
|
''}
|
2019-01-16 21:51:19 +00:00
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
HOME=. DEBUG=1 rebar3 as ${profile} ${if releaseType == "escript"
|
2021-01-24 09:19:10 +00:00
|
|
|
then "escriptize"
|
|
|
|
else "release"}
|
2019-01-16 21:51:19 +00:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
dir=${if releaseType == "escript"
|
2021-01-24 09:19:10 +00:00
|
|
|
then "bin"
|
|
|
|
else "rel"}
|
2019-01-16 21:51:19 +00:00
|
|
|
mkdir -p "$out/$dir"
|
|
|
|
cp -R --preserve=mode "_build/${profile}/$dir" "$out"
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
inherit (erlang.meta) platforms;
|
|
|
|
} // meta;
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
packageName = name;
|
|
|
|
env = shell self;
|
|
|
|
};
|
|
|
|
} // customPhases);
|
|
|
|
in
|
|
|
|
fix pkg
|