diff options
author | ydlr <58453832+ydlr@users.noreply.github.com> | 2021-05-16 23:05:40 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-17 08:05:40 +0900 |
commit | a2f3a63953b6fc0812cca363accbc5d4176f1f02 (patch) | |
tree | 1be258de93e729c84544f86eaf666f39a8dc2437 /pkgs/development/beam-modules | |
parent | 5e9437ef57565b80d2f446de0e1fbd566d6868cc (diff) | |
download | nixpkgs-a2f3a63953b6fc0812cca363accbc5d4176f1f02.tar nixpkgs-a2f3a63953b6fc0812cca363accbc5d4176f1f02.tar.gz nixpkgs-a2f3a63953b6fc0812cca363accbc5d4176f1f02.tar.bz2 nixpkgs-a2f3a63953b6fc0812cca363accbc5d4176f1f02.tar.lz nixpkgs-a2f3a63953b6fc0812cca363accbc5d4176f1f02.tar.xz nixpkgs-a2f3a63953b6fc0812cca363accbc5d4176f1f02.tar.zst nixpkgs-a2f3a63953b6fc0812cca363accbc5d4176f1f02.zip |
restore buildMix and its bootstrapper (#122374)
* restore mixBuild remove bootstrapper by going through ERL_LIBS mix will use ERL_LIBS to find compiled dependencies Co-authored-by: Zach <zach@hipcreativeinc.com>
Diffstat (limited to 'pkgs/development/beam-modules')
-rw-r--r-- | pkgs/development/beam-modules/build-mix.nix | 85 | ||||
-rw-r--r-- | pkgs/development/beam-modules/default.nix | 1 |
2 files changed, 86 insertions, 0 deletions
diff --git a/pkgs/development/beam-modules/build-mix.nix b/pkgs/development/beam-modules/build-mix.nix new file mode 100644 index 00000000000..7e19f19a093 --- /dev/null +++ b/pkgs/development/beam-modules/build-mix.nix @@ -0,0 +1,85 @@ +{ stdenv, writeText, elixir, erlang, hex, lib }: + +{ name +, version +, src +, buildInputs ? [ ] +, beamDeps ? [ ] +, propagatedBuildInputs ? [ ] +, postPatch ? "" +, compilePorts ? false +, meta ? { } +, enableDebugInfo ? false +, mixEnv ? "prod" +, ... +}@attrs: + +with lib; +let + shell = drv: stdenv.mkDerivation { + name = "interactive-shell-${drv.name}"; + buildInputs = [ drv ]; + }; + + pkg = self: stdenv.mkDerivation (attrs // { + name = "${name}-${version}"; + inherit version; + inherit src; + + MIX_ENV = mixEnv; + MIX_DEBUG = if enableDebugInfo then 1 else 0; + HEX_OFFLINE = 1; + + # stripping does not have any effect on beam files + dontStrip = true; + + # add to ERL_LIBS so other modules can find at runtime. + # http://erlang.org/doc/man/code.html#code-path + # Mix also searches the code path when compiling with the --no-deps-check + # flag, which is why there is no complicated booterstrapper like the one + # used by buildRebar3. + setupHook = attrs.setupHook or + writeText "setupHook.sh" '' + addToSearchPath ERL_LIBS "$1/lib/erlang/lib" + ''; + + buildInputs = buildInputs ++ [ elixir hex ]; + propagatedBuildInputs = propagatedBuildInputs ++ beamDeps; + + buildPhase = attrs.buildPhase or '' + runHook preBuild + export HEX_HOME="$TEMPDIR/hex" + export MIX_HOME="$TEMPDIR/mix" + mix compile --no-deps-check + runHook postBuild + ''; + + installPhase = attrs.installPhase or '' + runHook preInstall + + # This uses the install path convention established by nixpkgs maintainers + # for all beam packages. Changing this will break compatibility with other + # builder functions like buildRebar3 and buildErlangMk. + mkdir -p "$out/lib/erlang/lib/${name}-${version}" + + # Some packages like db_connection will use _build/shared instead of + # honoring the $MIX_ENV variable. + for reldir in _build/{$MIX_ENV,shared}/lib/${name}/{src,ebin,priv,include} ; do + if test -d $reldir ; then + # Some builds produce symlinks (eg: phoenix priv dircetory). They must + # be followed with -H flag. + cp -Hrt "$out/lib/erlang/lib/${name}-${version}" "$reldir" + fi + done + + runHook postInstall + ''; + + passthru = { + packageName = name; + env = shell self; + inherit beamDeps; + }; + }); +in +fix pkg diff --git a/pkgs/development/beam-modules/default.nix b/pkgs/development/beam-modules/default.nix index f63ecd95083..3375fd61260 100644 --- a/pkgs/development/beam-modules/default.nix +++ b/pkgs/development/beam-modules/default.nix @@ -32,6 +32,7 @@ let buildRebar3 = callPackage ./build-rebar3.nix { }; buildHex = callPackage ./build-hex.nix { }; buildErlangMk = callPackage ./build-erlang-mk.nix { }; + buildMix = callPackage ./build-mix.nix { }; fetchMixDeps = callPackage ./fetch-mix-deps.nix { }; mixRelease = callPackage ./mix-release.nix { }; |