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

Consider including .mix directory into buildMix output #2

Open
lukateras opened this issue Aug 7, 2019 · 1 comment
Open

Consider including .mix directory into buildMix output #2

lukateras opened this issue Aug 7, 2019 · 1 comment

Comments

@lukateras
Copy link
Member

Reported by @goodsoft. It seems that unless .mix is persisted, Dialyzer cannot be used during check phase. Which would mean it has to be preserved in the output.

One way to do it could be:

{ pkgs ? import ./pkgs.nix {} }: with pkgs;

let
  inherit (callPackage ./. {}) mixToNix;

  exposeDotMix = drv: drv.overrideAttrs (super: {
    postInstall = ''
      mv .mix $out || true
    '';
  });
in

mixToNix {
  src = ./tests/01-poison;
  overlay = final: lib.mapAttrs (lib.const exposeDotMix);
}
@lukateras
Copy link
Member Author

@goodsoft wrote on Apr 18, 2019 7:19pm UTC:

The ultimate list of things required to make Mix work correctly with Hex-based dependencies:

  1. deps/<name>/.hex file
  2. _build/$MIX_ENV/lib/<name>/.mix directory
  3. Hex.SCM instead of Mix.SCM.Path in _build/$MIX_ENV/lib/<name>/.mix/compile.elixir_scm file, which is :erlang.term_to_binary/1-encoded

Note that mix-bootstrap used by buildMix puts dependencies in the hardcoded location only for prod environment.

Currently I use the following workaround:

 fixHexDep = drv: drv.overrideAttrs (super: {
   postInstall = ''
     MIXDIR="_build/$MIXENV/lib/${drv.pname}/.mix"
     OUTDIR="$out/lib/erlang/lib"

     [ -e .hex ] && {
       ${elixir}/bin/elixir -e ":ok = :file.write_file(\"$MIXDIR/compile.elixir_scm\", \"$MIXDIR/compile.elixir_scm\" |> :file.read_file() |> elem(1) |> :erlang.binary_to_term() |> put_elem(2, Hex.SCM) |> :erlang.term_to_binary())"
       cp -Hrt "$OUTDIR/${super.name}/" "$MIXDIR" .hex
     } || true
   '';
 });

 (mixToNix {
   src = gitIgnore ./. [];
   overlay = final: lib.mapAttrs (lib.const fixHexDep);
 }).overrideAttrs (super: {
   postConfigure = ''
     mkdir -p _build/test/lib deps
     cp -Rv _build/prod/lib/* _build/test/lib/
     cp -Rv _build/prod/lib/* deps/
   '';
 });

By the way, with this --no-deps-check is not needed for any mix command anymore, as its checks succeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant