2021-07-14 22:03:04 +00:00
|
|
|
{ stdenv
|
|
|
|
, erlang
|
|
|
|
, rebar3WithPlugins
|
|
|
|
, openssl
|
|
|
|
, lib
|
|
|
|
}:
|
|
|
|
|
|
|
|
{ pname
|
|
|
|
, version
|
2020-04-24 23:36:52 +00:00
|
|
|
, src
|
2021-07-14 22:03:04 +00:00
|
|
|
, beamDeps ? [ ]
|
|
|
|
, buildPlugins ? [ ]
|
2020-04-24 23:36:52 +00:00
|
|
|
, checkouts ? null
|
|
|
|
, releaseType
|
2021-07-14 22:03:04 +00:00
|
|
|
, buildInputs ? [ ]
|
2020-04-24 23:36:52 +00:00
|
|
|
, setupHook ? null
|
|
|
|
, profile ? "default"
|
|
|
|
, installPhase ? null
|
|
|
|
, buildPhase ? null
|
|
|
|
, configurePhase ? null
|
2021-07-14 22:03:04 +00:00
|
|
|
, meta ? { }
|
|
|
|
, ...
|
|
|
|
}@attrs:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
shell = drv: stdenv.mkDerivation {
|
2021-07-14 22:03:04 +00:00
|
|
|
name = "interactive-shell-${drv.pname}";
|
|
|
|
buildInputs = [ drv ];
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
customPhases = lib.filterAttrs
|
2020-04-24 23:36:52 +00:00
|
|
|
(_: v: v != null)
|
|
|
|
{ inherit setupHook configurePhase buildPhase installPhase; };
|
|
|
|
|
2021-05-28 09:39:13 +00: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 =
|
2021-07-14 22:03:04 +00:00
|
|
|
assert beamDeps != [ ] -> checkouts == null;
|
2021-05-28 09:39:13 +00:00
|
|
|
self: stdenv.mkDerivation (attrs // {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-07-14 22:03:04 +00:00
|
|
|
name = "${pname}-${version}";
|
|
|
|
inherit version pname;
|
|
|
|
|
|
|
|
buildInputs = buildInputs ++ [ erlang rebar3 openssl ] ++ beamDeps;
|
|
|
|
|
|
|
|
# ensure we strip any native binaries (eg. NIFs, ports)
|
|
|
|
stripDebugList = lib.optional (releaseType == "release") "rel";
|
|
|
|
|
|
|
|
inherit src;
|
|
|
|
|
|
|
|
REBAR_IGNORE_DEPS = beamDeps != [ ];
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
runHook preConfigure
|
|
|
|
${lib.optionalString (checkouts != null)
|
|
|
|
"cp --no-preserve=all -R ${checkouts}/_checkouts ."}
|
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
HOME=. DEBUG=1 rebar3 as ${profile} ${if releaseType == "escript"
|
|
|
|
then "escriptize"
|
|
|
|
else "release"}
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
dir=${if releaseType == "escript"
|
|
|
|
then "bin"
|
|
|
|
else "rel"}
|
|
|
|
mkdir -p "$out/$dir" "$out/bin"
|
|
|
|
cp -R --preserve=mode "_build/${profile}/$dir" "$out"
|
|
|
|
${lib.optionalString (releaseType == "release")
|
|
|
|
"find $out/rel/*/bin -type f -executable -exec ln -s -t $out/bin {} \\;"}
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
for dir in $out/rel/*/erts-*; do
|
|
|
|
echo "ERTS found in $dir - removing references to erlang to reduce closure size"
|
|
|
|
for f in $dir/bin/{erl,start}; do
|
|
|
|
substituteInPlace "$f" --replace "${erlang}/lib/erlang" "''${dir/\/erts-*/}"
|
|
|
|
done
|
2021-06-06 07:54:09 +00:00
|
|
|
done
|
2021-07-14 22:03:04 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
inherit (erlang.meta) platforms;
|
|
|
|
} // meta;
|
|
|
|
|
|
|
|
passthru = ({
|
|
|
|
packageName = pname;
|
|
|
|
env = shell self;
|
|
|
|
} // (if attrs ? passthru then attrs.passthru else { }));
|
|
|
|
} // customPhases);
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
2023-02-02 18:25:31 +00:00
|
|
|
lib.fix pkg
|