Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add erlang modules #11651

Merged
merged 17 commits into from
Dec 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/maintainers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
gebner = "Gabriel Ebner <gebner@gebner.org>";
gfxmonk = "Tim Cuthbertson <tim@gfxmonk.net>";
giogadi = "Luis G. Torres <lgtorres42@gmail.com>";
gleber = "Gleb Peregud <gleber.p@gmail.com>";
globin = "Robin Gloster <robin@glob.in>";
goibhniu = "Cillian de Róiste <cillian.deroiste@gmail.com>";
gridaphobe = "Eric Seidel <eric@seidel.io>";
Expand Down
65 changes: 65 additions & 0 deletions pkgs/development/erlang-modules/build-erlang.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{ stdenv, erlang, rebar, openssl, libyaml }:

{ name, version
, buildInputs ? [], erlangDeps ? []
, postPatch ? ""
, meta ? {}
, ... }@attrs:

with stdenv.lib;

stdenv.mkDerivation (attrs // {
name = "${name}-${version}";

buildInputs = buildInputs ++ [ erlang rebar openssl libyaml ];

postPatch = ''
rm -f rebar
if [ -e "src/${name}.app.src" ]; then
sed -i -e 's/{ *vsn *,[^}]*}/{vsn, "${version}"}/' "src/${name}.app.src"
fi
${postPatch}
'';

configurePhase = let
getDeps = drv: [drv] ++ (map getDeps drv.erlangDeps);
recursiveDeps = uniqList {
inputList = flatten (map getDeps erlangDeps);
};
in ''
runHook preConfigure
${concatMapStrings (dep: ''
header "linking erlang dependency ${dep}"
mkdir deps
ln -s "${dep}" "deps/${dep.packageName}"
stopNest
'') recursiveDeps}
runHook postConfigure
'';

buildPhase = ''
runHook preBuild
rebar compile
runHook postBuild
'';

installPhase = ''
runHook preInstall
for reldir in src ebin priv include; do
[ -e "$reldir" ] || continue
mkdir "$out"
cp -rt "$out" "$reldir"
success=1
done
runHook postInstall
'';

meta = {
inherit (erlang.meta) platforms;
} // meta;

passthru = {
packageName = name;
inherit erlangDeps;
};
})
89 changes: 89 additions & 0 deletions pkgs/development/erlang-modules/build-hex.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{ stdenv, erlang, rebar3, openssl, libyaml, fetchHex, fetchFromGitHub,
rebar3-pc }:

{ name, version, sha256
, hexPkg ? name
, buildInputs ? [], erlangDeps ? [], pluginDeps ? []
, postPatch ? ""
, compilePorts ? false
, meta ? {}
, ... }@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 = ''
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 = 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));
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}
runHook postConfigure
'';

buildPhase = ''
runHook preBuild
HOME=. rebar3 compile
${if compilePorts then ''
HOME=. rebar3 pc compile
'' else ''''}
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;

passthru = {
packageName = name;
inherit erlangDeps;
};
})
18 changes: 18 additions & 0 deletions pkgs/development/erlang-modules/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ pkgs }: #? import <nixpkgs> {} }:

let
callPackage = pkgs.lib.callPackageWith (pkgs // self);

self = rec {
buildErlang = callPackage ./build-erlang.nix {};
buildHex = callPackage ./build-hex.nix {};

rebar3-pc = callPackage ./hex/rebar3-pc.nix {};
esqlite = callPackage ./hex/esqlite.nix {};
goldrush = callPackage ./hex/goldrush.nix {};
ibrowse = callPackage ./hex/ibrowse.nix {};
jiffy = callPackage ./hex/jiffy.nix {};
lager = callPackage ./hex/lager.nix {};
meck = callPackage ./hex/meck.nix {};
};
in self
8 changes: 8 additions & 0 deletions pkgs/development/erlang-modules/hex/esqlite.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ buildHex, rebar3-pc }:

buildHex {
name = "esqlite";
version = "0.2.1";
sha256 = "1296fn1lz4lz4zqzn4dwc3flgkh0i6n4sydg501faabfbv8d3wkr";
compilePorts = true;
}
7 changes: 7 additions & 0 deletions pkgs/development/erlang-modules/hex/goldrush.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ buildHex, fetchurl }:

buildHex {
name = "goldrush";
version = "0.1.7";
sha256 = "1zjgbarclhh10cpgvfxikn9p2ay63rajq96q1sbz9r9w6v6p8jm9";
}
8 changes: 8 additions & 0 deletions pkgs/development/erlang-modules/hex/ibrowse.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ buildHex }:

buildHex {
name = "ibrowse";
version = "4.2.2";
sha256 = "1bn0645n95j5zypdsns1w4kgd3q9lz8fj898hg355j5w89scn05q";
}

8 changes: 8 additions & 0 deletions pkgs/development/erlang-modules/hex/jiffy.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ buildHex }:

buildHex {
name = "jiffy";
version = "0.14.5";
hexPkg = "barrel_jiffy";
sha256 = "0iqz8bp0f672c5rfy5dpw9agv2708wzldd00ngbsffglpinlr1wa";
}
8 changes: 8 additions & 0 deletions pkgs/development/erlang-modules/hex/lager.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ buildHex, goldrush }:

buildHex {
name = "lager";
version = "3.0.2";
sha256 = "0051zj6wfmmvxjn9q0nw8wic13nhbrkyy50cg1lcpdh17qiknzsj";
erlangDeps = [ goldrush ];
}
13 changes: 13 additions & 0 deletions pkgs/development/erlang-modules/hex/meck.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ stdenv, buildHex }:

buildHex {
name = "meck";
version = "0.8.3";
sha256 = "1dh2rhks1xly4f49x89vbhsk8fgwkx5zqp0n98mnng8rs1rkigak";

meta = {
description = "A mocking framework for Erlang";
homepage = "https://github.com/eproxus/meck";
license = stdenv.lib.licenses.apsl20;
};
}
7 changes: 7 additions & 0 deletions pkgs/development/erlang-modules/hex/rebar3-pc.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ buildHex, goldrush }:

buildHex {
name = "pc";
version = "1.1.0";
sha256 = "1br5xfl4b2z70b6a2ccxppn64jvkqgpmy4y9v81kxzb91z0ss9ma";
}
129 changes: 129 additions & 0 deletions pkgs/development/tools/build-managers/rebar3/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{ stdenv, fetchurl, fetchHex, erlang, 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
'';
# TODO: all these below probably should go into nixpkgs.erlangModules.sources.*
# {erlware_commons, "0.16.0"},
erlware_commons = fetchHex {
pkg = "erlware_commons";
version = "0.16.0";
sha256 = "0kh24d0001390wfx28d0xa874vrsfvjgj41g315vg4hac632krxx";
};
# {ssl_verify_hostname, "1.0.5"},
ssl_verify_hostname = fetchHex {
pkg = "ssl_verify_hostname";
version = "1.0.5";
sha256 = "1gzavzqzljywx4l59gvhkjbr1dip4kxzjjz1s4wsn42f2kk13jzj";
};
# {certifi, "0.1.1"},
certifi = fetchHex {
pkg = "certifi";
version = "0.1.1";
sha256 = "0afylwqg74gprbg116asz0my2nipmki0512c8mdiq6xdiyjdvlg6";
};
# {providers, "1.5.0"},
providers = fetchHex {
pkg = "providers";
version = "1.5.0";
sha256 = "1hc8sp2l1mmx9dfpmh1f8j9hayfg7541rmx05wb9cmvxvih7zyvf";
};
# {getopt, "0.8.2"},
getopt = fetchHex {
pkg = "getopt";
version = "0.8.2";
sha256 = "1xw30h59zbw957cyjd8n50hf9y09jnv9dyry6x3avfwzcyrnsvkk";
};
# {bbmustache, "1.0.4"},
bbmustache = fetchHex {
pkg = "bbmustache";
version = "1.0.4";
sha256 = "04lvwm7f78x8bys0js33higswjkyimbygp4n72cxz1kfnryx9c03";
};
# {relx, "3.8.0"},
relx = fetchHex {
pkg = "relx";
version = "3.8.0";
sha256 = "0y89iirjz3kc1rzkdvc6p3ssmwcm2hqgkklhgm4pkbc14fcz57hq";
};
# {cf, "0.2.1"},
cf = fetchHex {
pkg = "cf";
version = "0.2.1";
sha256 = "19d0yvg8wwa57cqhn3vqfvw978nafw8j2rvb92s3ryidxjkrmvms";
};
# {cth_readable, "1.1.0"},
cth_readable = fetchHex {
pkg = "cth_readable";
version = "1.0.1";
sha256 = "1cnc4fbypckqllfi5h73rdb24dz576k3177gzvp1kbymwkp1xcz1";
};
# {eunit_formatters, "0.2.0"}
eunit_formatters = fetchHex {
pkg = "eunit_formatters";
version = "0.2.0";
sha256 = "03kiszlbgzscfd2ns7na6bzbfzmcqdb5cx3p6qy3657jk2fai332";
};

in
stdenv.mkDerivation {
name = "rebar3-${version}";

src = fetchurl {
url = "https://github.com/rebar/rebar3/archive/${version}.tar.gz";
sha256 = "0px66scjdia9aaa5z36qzxb848r56m0k98g0bxw065a2narsh4xy";
};

patches = [ ./hermetic-bootstrap.patch ];

buildInputs = [ erlang
tree
];
inherit setupRegistry;

postPatch = ''
echo postPatch
${setupRegistry}
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
cp --no-preserve=mode -R ${getopt} _build/default/lib/getopt
cp --no-preserve=mode -R ${bbmustache} _build/default/lib/bbmustache
cp --no-preserve=mode -R ${certifi} _build/default/lib/certifi
cp --no-preserve=mode -R ${cf} _build/default/lib/cf
cp --no-preserve=mode -R ${cth_readable} _build/default/lib/cth_readable
cp --no-preserve=mode -R ${eunit_formatters} _build/default/lib/eunit_formatters
cp --no-preserve=mode -R ${relx} _build/default/lib/relx
cp --no-preserve=mode -R ${ssl_verify_hostname} _build/default/lib/ssl_verify_hostname
'';

buildPhase = ''
HOME=. escript bootstrap
'';
installPhase = ''
mkdir -p $out/bin
cp rebar3 $out/bin/rebar3
'';

meta = {
homepage = "https://github.com/rebar/rebar3";
description = "rebar 3.0 is an Erlang build tool that makes it easy to compile and test Erlang applications, port drivers and releases.";

longDescription = ''
rebar is a self-contained Erlang script, so it's easy to distribute or
even embed directly in a project. Where possible, rebar uses standard
Erlang/OTP conventions for project structures, thus minimizing the amount
of build configuration work. rebar also provides dependency management,
enabling application writers to easily re-use common libraries from a
variety of locations (hex.pm, git, hg, and so on).
'';

platforms = stdenv.lib.platforms.unix;
maintainers = [ stdenv.lib.maintainers.gleber ];
};
}