nixpkgs-suyu/pkgs/development/beam-modules/build-rebar3.nix

85 lines
1.8 KiB
Nix
Raw Normal View History

2021-05-10 19:30:25 +02:00
{ stdenv, writeText, erlang, rebar3WithPlugins, openssl, libyaml, lib }:
2021-06-03 14:58:02 +02:00
{ name
, version
, src
, setupHook ? null
2021-06-03 14:58:02 +02:00
, buildInputs ? [ ]
, beamDeps ? [ ]
, buildPlugins ? [ ]
, postPatch ? ""
, installPhase ? null
, buildPhase ? null
, configurePhase ? null
2021-06-03 14:58:02 +02:00
, meta ? { }
, enableDebugInfo ? false
2021-06-03 14:58:02 +02:00
, ...
}@attrs:
2021-01-23 18:15:07 +01:00
with lib;
let
debugInfoFlag = lib.optionalString (enableDebugInfo || erlang.debugInfo) "debug-info";
2021-05-08 13:47:27 +02:00
rebar3 = rebar3WithPlugins {
plugins = buildPlugins;
};
shell = drv: stdenv.mkDerivation {
2021-06-03 14:58:02 +02:00
name = "interactive-shell-${drv.name}";
buildInputs = [ drv ];
};
customPhases = filterAttrs
(_: v: v != null)
{ inherit setupHook configurePhase buildPhase installPhase; };
pkg = self: stdenv.mkDerivation (attrs // {
name = "${name}-${version}";
inherit version;
buildInputs = buildInputs ++ [ erlang rebar3 openssl libyaml ];
2021-05-08 13:47:27 +02:00
propagatedBuildInputs = unique beamDeps;
dontStrip = true;
inherit src;
setupHook = writeText "setupHook.sh" ''
2021-06-03 14:58:02 +02:00
addToSearchPath ERL_LIBS "$1/lib/erlang/lib/"
'';
postPatch = ''
rm -f rebar rebar3
'' + postPatch;
buildPhase = ''
runHook preBuild
2021-05-10 19:30:25 +02:00
HOME=. rebar3 bare compile -path ""
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p "$out/lib/erlang/lib/${name}-${version}"
for reldir in src ebin priv include; do
2021-05-10 19:30:25 +02: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"
done
runHook postInstall
'';
meta = {
inherit (erlang.meta) platforms;
} // meta;
passthru = {
packageName = name;
env = shell self;
inherit beamDeps;
};
} // customPhases);
in
2021-06-03 14:58:02 +02:00
fix pkg