3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/development/erlang-modules/build-hex.nix
Eric Merritt 474e417891 erlang support: allow nix-shell to work correctly
This changes build-hex.nix so that the buildHex and related functions
work correctly in a nix-shell.
2016-01-14 14:36:47 -08:00

88 lines
1.9 KiB
Nix

{ stdenv, writeText, erlang, rebar3, openssl, libyaml, fetchHex, fetchFromGitHub,
rebar3-pc, buildEnv }:
{ name, version, sha256 ? false
, src ? null
, setupHook ? null
, hexPkg ? name
, 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;
src = if src == null then 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
fix pkg