···23232424 pkg = self: stdenv.mkDerivation (attrs // {
2525 name = "${name}-${version}";
2626- inherit version;
2727- inherit src;
2626+ inherit version src buildInputs;
28272928 MIX_ENV = mixEnv;
3029 MIX_DEBUG = if enableDebugInfo then 1 else 0;
3130 HEX_OFFLINE = 1;
32313333- # stripping does not have any effect on beam files
3434- dontStrip = true;
3535-3632 # add to ERL_LIBS so other modules can find at runtime.
3733 # http://erlang.org/doc/man/code.html#code-path
3834 # Mix also searches the code path when compiling with the --no-deps-check flag
···4137 addToSearchPath ERL_LIBS "$1/lib/erlang/lib"
4238 '';
43394444- buildInputs = buildInputs ++ [ elixir hex ];
4040+ nativeBuildInputs = [ elixir hex ];
4541 propagatedBuildInputs = propagatedBuildInputs ++ beamDeps;
46424743 buildPhase = attrs.buildPhase or ''
···72687369 runHook postInstall
7470 '';
7171+7272+ # stripping does not have any effect on beam files
7373+ # it is however needed for dependencies with NIFs like bcrypt for example
7474+ dontStrip = false;
75757676 passthru = {
7777 packageName = name;
+5-1
pkgs/development/beam-modules/build-rebar3.nix
···4242 buildInputs = buildInputs ++ [ erlang rebar3 openssl libyaml ];
4343 propagatedBuildInputs = unique beamDeps;
44444545- dontStrip = true;
4645 inherit src;
4646+4747+ # stripping does not have any effect on beam files
4848+ # it is however needed for dependencies with NIFs
4949+ # false is the default but we keep this for readability
5050+ dontStrip = false;
47514852 setupHook = writeText "setupHook.sh" ''
4953 addToSearchPath ERL_LIBS "$1/lib/erlang/lib/"
+20-19
pkgs/development/beam-modules/mix-release.nix
···11-{ stdenv, lib, elixir, erlang, findutils, hex, rebar, rebar3, fetchMixDeps, makeWrapper, git }:
11+{ stdenv, lib, elixir, erlang, findutils, hex, rebar3, fetchMixDeps, makeWrapper, git, ripgrep }:
2233{ pname
44, version
···2323in
2424assert mixNixDeps != { } -> mixFodDeps == null;
2525stdenv.mkDerivation (overridable // {
2626- nativeBuildInputs = nativeBuildInputs ++ [ erlang hex elixir makeWrapper git ];
2626+ # rg is used as a better grep to search for erlang references in the final release
2727+ nativeBuildInputs = nativeBuildInputs ++ [ erlang hex elixir makeWrapper git ripgrep ];
2728 buildInputs = builtins.attrValues mixNixDeps;
28292930 MIX_ENV = mixEnv;
···3132 HEX_OFFLINE = 1;
3233 DEBUG = if enableDebugInfo then 1 else 0; # for Rebar3 compilation
3334 # the api with `mix local.rebar rebar path` makes a copy of the binary
3434- MIX_REBAR = "${rebar}/bin/rebar";
3535 MIX_REBAR3 = "${rebar3}/bin/rebar3";
36363737 postUnpack = ''
···8282 runHook postInstall
8383 '';
84848585- fixupPhase = ''
8686- runHook preFixup
8585+ # Stripping of the binary is intentional
8686+ # even though it does not affect beam files
8787+ # it is necessary for NIFs binaries
8888+ postFixup = ''
8789 if [ -e "$out/bin/${pname}.bat" ]; then # absent in special cases, i.e. elixir-ls
8890 rm "$out/bin/${pname}.bat" # windows file
8991 fi
···9496 if [ -e $out/releases/COOKIE ]; then # absent in special cases, i.e. elixir-ls
9597 rm $out/releases/COOKIE
9698 fi
9797- # TODO remove the uneeded reference too erlang
9898- # one possible way would be
9999- # for f in $(${findutils}/bin/find $out -name start); do
100100- # substituteInPlace $f \
101101- # --replace 'ROOTDIR=${erlang}/lib/erlang' 'ROOTDIR=""'
102102- # done
103103- # What is left to do is to check that erlang is not required on
104104- # the host
105105-106106- patchShebangs $out
107107- runHook postFixup
9999+ # removing unused erlang reference from resulting derivation to reduce
100100+ # closure size
101101+ if [ -e $out/erts-* ]; then
102102+ echo "ERTS found in $out - removing references to erlang to reduce closure size"
103103+ # there is a link in $out/erts-*/bin/start always
104104+ # sometimes there are links in dependencies like bcrypt compiled binaries
105105+ for file in $(rg "${erlang}/lib/erlang" "$out" --text --files-with-matches); do
106106+ substituteInPlace "$file" --replace "${erlang}/lib/erlang" "$out"
107107+ done
108108+ fi
108109 '';
109109- # TODO figure out how to do a Fixed Output Derivation and add the output hash
110110- # This doesn't play well at the moment with Phoenix projects
111111- # for example that have frontend dependencies
112110111111+ # TODO investigate why the resulting closure still has
112112+ # a reference to erlang.
113113+ # uncommenting the following will fail the build
113114 # disallowedReferences = [ erlang ];
114115})