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.
This commit is contained in:
parent
a0309d871c
commit
474e417891
@ -1,7 +1,9 @@
|
||||
{ stdenv, erlang, rebar3, openssl, libyaml, fetchHex, fetchFromGitHub,
|
||||
{ stdenv, writeText, erlang, rebar3, openssl, libyaml, fetchHex, fetchFromGitHub,
|
||||
rebar3-pc, buildEnv }:
|
||||
|
||||
{ name, version, sha256
|
||||
{ name, version, sha256 ? false
|
||||
, src ? null
|
||||
, setupHook ? null
|
||||
, hexPkg ? name
|
||||
, buildInputs ? [], erlangDeps ? [], pluginDeps ? []
|
||||
, postPatch ? ""
|
||||
@ -13,64 +15,40 @@ with stdenv.lib;
|
||||
|
||||
let
|
||||
plugins = pluginDeps ++ (if compilePorts then [rebar3-pc] else []);
|
||||
getDeps = drv: [drv] ++ (map getDeps drv.erlangDeps);
|
||||
recursiveDeps = unique (flatten (map getDeps erlangDeps));
|
||||
recursivePluginsDeps = unique (flatten (map getDeps plugins));
|
||||
|
||||
erlEnv = drv: buildEnv {
|
||||
name = "erlang-env-${drv.name}";
|
||||
paths = [ drv ] ++ recursiveDeps;
|
||||
ignoreCollisions = false;
|
||||
meta = drv.meta;
|
||||
};
|
||||
|
||||
shell = drv: let
|
||||
drvEnv = erlEnv drv;
|
||||
in stdenv.mkDerivation {
|
||||
name = "interactive-shell-${drv.name}";
|
||||
nativeBuildInputs = [ erlang drvEnv ];
|
||||
shellHook = ''
|
||||
export ERL_LIBS="${drvEnv}";
|
||||
'';
|
||||
};
|
||||
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 = fetchHex {
|
||||
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
|
||||
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}
|
||||
|
||||
${postPatch}
|
||||
'';
|
||||
|
||||
configurePhase = ''
|
||||
runHook preConfigure
|
||||
${concatMapStrings (dep: ''
|
||||
header "linking erlang dependency ${dep}"
|
||||
ln -s "${dep}/${dep.name}" "_build/default/lib/${dep.name}"
|
||||
stopNest
|
||||
'') recursiveDeps}
|
||||
${concatMapStrings (dep: ''
|
||||
header "linking rebar3 plugins ${dep}"
|
||||
ln -s "${dep}/${dep.name}" "_build/default/plugins/${dep.name}"
|
||||
stopNest
|
||||
'') recursivePluginsDeps}
|
||||
rebar3-nix-bootstrap
|
||||
runHook postConfigure
|
||||
'';
|
||||
|
||||
@ -85,11 +63,11 @@ let
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
mkdir -p "$out/${name}"
|
||||
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/${name}" "$fd"
|
||||
cp -Hrt "$out/lib/erlang/lib/${name}-${version}" "$fd"
|
||||
success=1
|
||||
done
|
||||
runHook postInstall
|
||||
|
@ -1,13 +1,11 @@
|
||||
{ stdenv, fetchurl, fetchHex, erlang, tree, fetchFromGitHub }:
|
||||
{ stdenv, writeText, callPackage, fetchurl,
|
||||
fetchHex, erlang, rebar3-nix-bootstrap, tree, fetchFromGitHub }:
|
||||
|
||||
|
||||
let
|
||||
version = "3.0.0-beta.4";
|
||||
registrySnapshot = import ./registrySnapshot.nix { inherit fetchFromGitHub; };
|
||||
setupRegistry = ''
|
||||
mkdir -p _build/default/{lib,plugins,packages}/ ./.cache/rebar3/hex/default/
|
||||
zcat ${registrySnapshot}/registry.ets.gz > .cache/rebar3/hex/default/registry
|
||||
'';
|
||||
registrySnapshot = callPackage ./registrySnapshot.nix { };
|
||||
|
||||
# TODO: all these below probably should go into nixpkgs.erlangModules.sources.*
|
||||
# {erlware_commons, "0.16.0"},
|
||||
erlware_commons = fetchHex {
|
||||
@ -73,6 +71,7 @@ let
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
name = "rebar3-${version}";
|
||||
inherit version;
|
||||
|
||||
src = fetchurl {
|
||||
url = "https://github.com/rebar/rebar3/archive/${version}.tar.gz";
|
||||
@ -81,14 +80,14 @@ stdenv.mkDerivation {
|
||||
|
||||
patches = [ ./hermetic-bootstrap.patch ];
|
||||
|
||||
buildInputs = [ erlang
|
||||
tree
|
||||
];
|
||||
inherit setupRegistry;
|
||||
buildInputs = [ erlang tree ];
|
||||
propagatedBuildInputs = [ registrySnapshot rebar3-nix-bootstrap ];
|
||||
|
||||
|
||||
postPatch = ''
|
||||
echo postPatch
|
||||
${setupRegistry}
|
||||
rebar3-nix-bootstrap registry-only
|
||||
echo "$ERL_LIBS"
|
||||
mkdir -p _build/default/lib/
|
||||
cp --no-preserve=mode -R ${erlware_commons} _build/default/lib/erlware_commons
|
||||
cp --no-preserve=mode -R ${providers} _build/default/lib/providers
|
||||
|
@ -1,8 +1,23 @@
|
||||
{ fetchFromGitHub }:
|
||||
{stdenv, writeText, fetchFromGitHub }:
|
||||
|
||||
fetchFromGitHub {
|
||||
owner = "gleber";
|
||||
repo = "hex-pm-registry-snapshots";
|
||||
rev = "329ae2b";
|
||||
sha256 = "1rs3z8psfvy10mzlfvkdzbflgikcnq08r38kfi0f8p5wvi8f8hmh";
|
||||
stdenv.mkDerivation rec {
|
||||
name = "hex-registry";
|
||||
rev = "329ae2b";
|
||||
version = "0.0.0+build.${rev}";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "gleber";
|
||||
repo = "hex-pm-registry-snapshots";
|
||||
inherit rev;
|
||||
sha256 = "1rs3z8psfvy10mzlfvkdzbflgikcnq08r38kfi0f8p5wvi8f8hmh";
|
||||
};
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p "$out/var/hex"
|
||||
zcat "registry.ets.gz" > "$out/var/hex/registry.ets"
|
||||
'';
|
||||
|
||||
setupHook = writeText "setupHook.sh" ''
|
||||
export HEX_REGISTRY_SNAPSHOT="$1/var/hex/registry.ets"
|
||||
'';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user