nixpkgs/pkgs/development/erlang-modules/build-hex.nix

90 lines
2 KiB
Nix
Raw Normal View History

{ stdenv, erlang, rebar3, openssl, libyaml, fetchHex, fetchFromGitHub,
rebar3-pc }:
2015-12-10 00:12:37 +01:00
{ name, version, sha256
, hexPkg ? name
, buildInputs ? [], erlangDeps ? [], pluginDeps ? []
2015-12-10 00:12:37 +01:00
, postPatch ? ""
, compilePorts ? false
, meta ? {}
2015-12-10 00:12:37 +01:00
, ... }@attrs:
with stdenv.lib;
stdenv.mkDerivation (attrs // {
name = "${name}-${version}";
buildInputs = buildInputs ++ [ erlang rebar3 openssl libyaml ];
src = fetchHex {
pkg = hexPkg;
inherit version;
inherit sha256;
};
postPatch = ''
2015-12-10 00:12:37 +01:00
rm -f rebar rebar3
if [ -e "src/${name}.app.src" ]; then
sed -i -e 's/{ *vsn *,[^}]*}/{vsn, "${version}"}/' "src/${name}.app.src"
fi
${if compilePorts then ''
echo "{plugins, [pc]}." >> rebar.config
'' else ''''}
${rebar3.setupRegistry}
2015-12-10 00:12:37 +01:00
${postPatch}
'';
configurePhase = let
plugins = pluginDeps ++ (if compilePorts then [rebar3-pc] else []);
2015-12-10 00:12:37 +01:00
getDeps = drv: [drv] ++ (map getDeps drv.erlangDeps);
recursiveDeps = unique (flatten (map getDeps erlangDeps));
recursivePluginsDeps = unique (flatten (map getDeps plugins));
2015-12-10 00:12:37 +01:00
in ''
runHook preConfigure
${concatMapStrings (dep: ''
header "linking erlang dependency ${dep}"
ln -s "${dep}" "_build/default/lib/${dep.packageName}"
stopNest
'') recursiveDeps}
${concatMapStrings (dep: ''
header "linking rebar3 plugins ${dep}"
ln -s "${dep}" "_build/default/plugins/${dep.packageName}"
stopNest
'') recursivePluginsDeps}
2015-12-10 00:12:37 +01:00
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
HOME=. rebar3 compile
${if compilePorts then ''
HOME=. rebar3 pc compile
'' else ''''}
2015-12-10 00:12:37 +01:00
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir "$out"
for reldir in src ebin priv include; do
fd="_build/default/lib/${name}/$reldir"
[ -d "$fd" ] || continue
cp -Hrt "$out" "$fd"
success=1
done
runHook postInstall
'';
meta = {
inherit (erlang.meta) platforms;
} // meta;
2015-12-10 00:12:37 +01:00
passthru = {
packageName = name;
inherit erlangDeps;
};
})