2021-05-10 18:30:25 +01:00
|
|
|
{ stdenv, writeText, erlang, rebar3WithPlugins, openssl, libyaml, lib }:
|
2016-01-10 23:25:45 +00:00
|
|
|
|
2021-06-03 13:58:02 +01:00
|
|
|
{ name
|
|
|
|
, version
|
2016-01-10 23:25:45 +00:00
|
|
|
, src
|
|
|
|
, setupHook ? null
|
2021-06-03 13:58:02 +01:00
|
|
|
, buildInputs ? [ ]
|
|
|
|
, beamDeps ? [ ]
|
|
|
|
, buildPlugins ? [ ]
|
2016-01-10 23:25:45 +00:00
|
|
|
, postPatch ? ""
|
2016-01-11 02:39:37 +00:00
|
|
|
, installPhase ? null
|
2016-06-15 15:19:44 +01:00
|
|
|
, buildPhase ? null
|
|
|
|
, configurePhase ? null
|
2021-06-03 13:58:02 +01:00
|
|
|
, meta ? { }
|
2016-06-15 15:15:06 +01:00
|
|
|
, enableDebugInfo ? false
|
2021-06-03 13:58:02 +01:00
|
|
|
, ...
|
|
|
|
}@attrs:
|
2016-01-10 23:25:45 +00:00
|
|
|
|
2021-01-23 17:15:07 +00:00
|
|
|
with lib;
|
2016-01-10 23:25:45 +00:00
|
|
|
|
|
|
|
let
|
2016-06-15 15:15:06 +01:00
|
|
|
debugInfoFlag = lib.optionalString (enableDebugInfo || erlang.debugInfo) "debug-info";
|
|
|
|
|
2021-05-08 12:47:27 +01:00
|
|
|
rebar3 = rebar3WithPlugins {
|
|
|
|
plugins = buildPlugins;
|
|
|
|
};
|
2016-01-10 23:25:45 +00:00
|
|
|
|
|
|
|
shell = drv: stdenv.mkDerivation {
|
2021-06-03 13:58:02 +01:00
|
|
|
name = "interactive-shell-${drv.name}";
|
|
|
|
buildInputs = [ drv ];
|
|
|
|
};
|
2016-01-10 23:25:45 +00:00
|
|
|
|
2017-02-18 13:25:24 +00:00
|
|
|
customPhases = filterAttrs
|
|
|
|
(_: v: v != null)
|
|
|
|
{ inherit setupHook configurePhase buildPhase installPhase; };
|
|
|
|
|
2016-01-10 23:25:45 +00:00
|
|
|
pkg = self: stdenv.mkDerivation (attrs // {
|
|
|
|
|
|
|
|
name = "${name}-${version}";
|
|
|
|
inherit version;
|
|
|
|
|
|
|
|
buildInputs = buildInputs ++ [ erlang rebar3 openssl libyaml ];
|
2021-05-08 12:47:27 +01:00
|
|
|
propagatedBuildInputs = unique beamDeps;
|
2016-01-17 20:00:12 +00:00
|
|
|
|
2016-01-10 23:25:45 +00:00
|
|
|
inherit src;
|
|
|
|
|
2021-06-06 11:56:33 +01:00
|
|
|
# stripping does not have any effect on beam files
|
|
|
|
# it is however needed for dependencies with NIFs
|
|
|
|
# false is the default but we keep this for readability
|
|
|
|
dontStrip = false;
|
|
|
|
|
2017-02-18 13:25:24 +00:00
|
|
|
setupHook = writeText "setupHook.sh" ''
|
2021-06-03 13:58:02 +01:00
|
|
|
addToSearchPath ERL_LIBS "$1/lib/erlang/lib/"
|
2017-02-18 13:25:24 +00:00
|
|
|
'';
|
2016-01-10 23:25:45 +00:00
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
rm -f rebar rebar3
|
2016-08-29 22:20:59 +01:00
|
|
|
'' + postPatch;
|
2016-01-10 23:25:45 +00:00
|
|
|
|
2017-02-18 13:25:24 +00:00
|
|
|
buildPhase = ''
|
2016-01-10 23:25:45 +00:00
|
|
|
runHook preBuild
|
2021-05-10 18:30:25 +01:00
|
|
|
HOME=. rebar3 bare compile -path ""
|
2016-01-10 23:25:45 +00:00
|
|
|
runHook postBuild
|
2017-02-18 13:25:24 +00:00
|
|
|
'';
|
2016-01-10 23:25:45 +00:00
|
|
|
|
2017-02-18 13:25:24 +00:00
|
|
|
installPhase = ''
|
2016-01-10 23:25:45 +00:00
|
|
|
runHook preInstall
|
|
|
|
mkdir -p "$out/lib/erlang/lib/${name}-${version}"
|
|
|
|
for reldir in src ebin priv include; do
|
2021-05-10 18:30:25 +01:00
|
|
|
[ -d "$reldir" ] || continue
|
|
|
|
# $out/lib/erlang/lib is a convention used in nixpkgs for compiled BEAM packages
|
|
|
|
cp -Hrt "$out/lib/erlang/lib/${name}-${version}" "$reldir"
|
2016-01-10 23:25:45 +00:00
|
|
|
done
|
|
|
|
runHook postInstall
|
2017-02-18 13:25:24 +00:00
|
|
|
'';
|
2016-01-10 23:25:45 +00:00
|
|
|
|
|
|
|
meta = {
|
|
|
|
inherit (erlang.meta) platforms;
|
|
|
|
} // meta;
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
packageName = name;
|
|
|
|
env = shell self;
|
2016-03-28 22:14:13 +01:00
|
|
|
inherit beamDeps;
|
2016-01-10 23:25:45 +00:00
|
|
|
};
|
2017-02-18 13:25:24 +00:00
|
|
|
} // customPhases);
|
2016-01-10 23:25:45 +00:00
|
|
|
in
|
2021-06-03 13:58:02 +01:00
|
|
|
fix pkg
|