summary refs log tree commit diff
path: root/pkgs/development/beam-modules/build-rebar3.nix
diff options
context:
space:
mode:
authorEric Merritt <eric@merritt.tech>2016-03-28 14:14:13 -0700
committerEric Merritt <eric@merritt.tech>2016-04-23 19:03:24 -0700
commit8dbcb4e35ecc2513dab1ed8cb6052f68ab0a6537 (patch)
tree7c59313015440aa0adeed1acf01e9445081b308d /pkgs/development/beam-modules/build-rebar3.nix
parent3b7aee2e5a87b256aaff903a33106d974a25dbef (diff)
downloadnixpkgs-8dbcb4e35ecc2513dab1ed8cb6052f68ab0a6537.tar
nixpkgs-8dbcb4e35ecc2513dab1ed8cb6052f68ab0a6537.tar.gz
nixpkgs-8dbcb4e35ecc2513dab1ed8cb6052f68ab0a6537.tar.bz2
nixpkgs-8dbcb4e35ecc2513dab1ed8cb6052f68ab0a6537.tar.lz
nixpkgs-8dbcb4e35ecc2513dab1ed8cb6052f68ab0a6537.tar.xz
nixpkgs-8dbcb4e35ecc2513dab1ed8cb6052f68ab0a6537.tar.zst
nixpkgs-8dbcb4e35ecc2513dab1ed8cb6052f68ab0a6537.zip
beamPackages: Add support for Mix and Erlang.mk
Diffstat (limited to 'pkgs/development/beam-modules/build-rebar3.nix')
-rw-r--r--pkgs/development/beam-modules/build-rebar3.nix89
1 files changed, 89 insertions, 0 deletions
diff --git a/pkgs/development/beam-modules/build-rebar3.nix b/pkgs/development/beam-modules/build-rebar3.nix
new file mode 100644
index 00000000000..2627ddf99a6
--- /dev/null
+++ b/pkgs/development/beam-modules/build-rebar3.nix
@@ -0,0 +1,89 @@
+{ stdenv, writeText, erlang, rebar3, openssl, libyaml,
+  pc, buildEnv }:
+
+{ name, version
+, src
+, setupHook ? null
+, buildInputs ? [], beamDeps ? [], buildPlugins ? []
+, postPatch ? ""
+, compilePorts ? false
+, installPhase ? null
+, meta ? {}
+, ... }@attrs:
+
+with stdenv.lib;
+
+let
+  ownPlugins = buildPlugins ++ (if compilePorts then [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 = unique (beamDeps ++ ownPlugins);
+
+    dontStrip = true;
+    # The following are used by rebar3-nix-bootstrap
+    inherit compilePorts;
+    buildPlugins = ownPlugins;
+
+    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 = if installPhase == null
+    then ''
+      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
+    ''
+    else installPhase;
+
+    meta = {
+      inherit (erlang.meta) platforms;
+    } // meta;
+
+    passthru = {
+      packageName = name;
+      env = shell self;
+      inherit beamDeps;
+    };
+  });
+in
+  fix pkg