erlang support: seperate hex and rebar3 support

Building Hex packages is a superset of building with rebar3. There is no
need to force folks that use rebar3 but not hex to build with hex. This
commit seperates the rebar3 specific bits and the hex specific bits into
seperate functions that can be used independently.
This commit is contained in:
Eric Merritt 2016-01-10 15:25:45 -08:00
parent b509dadbf1
commit d541d0e640
3 changed files with 88 additions and 72 deletions

View file

@ -1,86 +1,18 @@
{ stdenv, writeText, erlang, rebar3, openssl, libyaml, fetchHex, fetchFromGitHub,
rebar3-pc, buildEnv }:
{ stdenv, buildRebar3, fetchHex }:
{ name, version, sha256 ? false
, src ? null
, setupHook ? null
{ name, version, sha256
, hexPkg ? name
, buildInputs ? [], erlangDeps ? [], pluginDeps ? []
, postPatch ? ""
, compilePorts ? false
, meta ? {}
, ... }@attrs:
with stdenv.lib;
let
plugins = pluginDeps ++ (if compilePorts then [rebar3-pc] else []);
pkg = self: buildRebar3 (attrs // {
shell = drv: stdenv.mkDerivation {
name = "interactive-shell-${drv.name}";
buildInputs = [ drv ];
};
pkg = self: stdenv.mkDerivation (attrs // {
name = "${name}-${version}";
inherit version;
buildInputs = buildInputs ++ [ erlang rebar3 openssl libyaml ];
propagatedBuildInputs = erlangDeps ++ plugins;
src = if src == null then fetchHex {
src = fetchHex {
pkg = hexPkg;
inherit version;
inherit sha256;
} else src;
setupHook = if setupHook == null
then writeText "setupHook.sh" ''
addToSearchPath ERL_LIBS "$1/lib/erlang/lib/"
''
else setupHook;
postPatch = ''
rm -f rebar rebar3
'';
configurePhase = ''
runHook preConfigure
rebar3-nix-bootstrap
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
HOME=. rebar3 compile
${if compilePorts then ''
HOME=. rebar3 pc compile
'' else ''''}
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p "$out/lib/erlang/lib/${name}-${version}"
for reldir in src ebin priv include; do
fd="_build/default/lib/${name}/$reldir"
[ -d "$fd" ] || continue
cp -Hrt "$out/lib/erlang/lib/${name}-${version}" "$fd"
success=1
done
runHook postInstall
'';
meta = {
inherit (erlang.meta) platforms;
} // meta;
passthru = {
packageName = name;
env = shell self;
inherit erlangDeps;
};
});
in

View file

@ -0,0 +1,82 @@
{ stdenv, writeText, erlang, rebar3, openssl, libyaml, fetchHex, fetchFromGitHub,
rebar3-pc, buildEnv }:
{ name, version
, src
, setupHook ? null
, buildInputs ? [], erlangDeps ? [], pluginDeps ? []
, postPatch ? ""
, compilePorts ? false
, meta ? {}
, ... }@attrs:
with stdenv.lib;
let
plugins = pluginDeps ++ (if compilePorts then [rebar3-pc] else []);
shell = drv: stdenv.mkDerivation {
name = "interactive-shell-${drv.name}";
buildInputs = [ drv ];
};
pkg = self: stdenv.mkDerivation (attrs // {
name = "${name}-${version}";
inherit version;
buildInputs = buildInputs ++ [ erlang rebar3 openssl libyaml ];
propagatedBuildInputs = erlangDeps ++ plugins;
inherit src;
setupHook = if setupHook == null
then writeText "setupHook.sh" ''
addToSearchPath ERL_LIBS "$1/lib/erlang/lib/"
''
else setupHook;
postPatch = ''
rm -f rebar rebar3
'';
configurePhase = ''
runHook preConfigure
rebar3-nix-bootstrap
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
HOME=. rebar3 compile
${if compilePorts then ''
HOME=. rebar3 pc compile
'' else ''''}
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p "$out/lib/erlang/lib/${name}-${version}"
for reldir in src ebin priv include; do
fd="_build/default/lib/${name}/$reldir"
[ -d "$fd" ] || continue
cp -Hrt "$out/lib/erlang/lib/${name}-${version}" "$fd"
success=1
done
runHook postInstall
'';
meta = {
inherit (erlang.meta) platforms;
} // meta;
passthru = {
packageName = name;
env = shell self;
inherit erlangDeps;
};
});
in
fix pkg

View file

@ -4,6 +4,8 @@ let
self = rec {
hex = import ./hex-packages.nix { callPackage = self.callPackage; };
callPackage = pkgs.lib.callPackageWith (pkgs // self // hex);
buildRebar3 = callPackage ./build-rebar3.nix {};
buildHex = callPackage ./build-hex.nix {};
};
in self // self.hex