summary refs log tree commit diff
path: root/pkgs/development/beam-modules/build-mix.nix
blob: 9aebad2dabf79e8421a753538a55308bfd44f53d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{ stdenv, writeText, elixir, erlang, hex, lib }:

{ name
, version
, src
, setupHook ? null
, buildInputs ? []
, beamDeps ? []
, postPatch ? ""
, compilePorts ? false
, installPhase ? null
, buildPhase ? null
, configurePhase ? null
, meta ? {}
, enableDebugInfo ? false
, ... }@attrs:

with stdenv.lib;

let

  debugInfoFlag = lib.optionalString (enableDebugInfo || elixir.debugInfo) "--debug-info";

  shell = drv: stdenv.mkDerivation {
          name = "interactive-shell-${drv.name}";
          buildInputs = [ drv ];
    };

  bootstrapper = ./mix-bootstrap;

  pkg = self: stdenv.mkDerivation ( attrs // {
    name = "${name}-${version}";
    inherit version;

    dontStrip = true;

    inherit src;

    setupHook = if setupHook == null
    then writeText "setupHook.sh" ''
       addToSearchPath ERL_LIBS "$1/lib/erlang/lib"
    ''
    else setupHook;

    inherit buildInputs;
    propagatedBuildInputs = [ hex elixir ] ++ beamDeps;

    configurePhase = if configurePhase == null
    then ''
      runHook preConfigure
      ${erlang}/bin/escript ${bootstrapper}
      runHook postConfigure
    ''
    else configurePhase ;


    buildPhase = if buildPhase == null
    then ''
        runHook preBuild

        export HEX_OFFLINE=1
        export HEX_HOME=`pwd`
        export MIX_ENV=prod
        export MIX_NO_DEPS=1

        mix compile ${debugInfoFlag} --no-deps-check

        runHook postBuild
    ''
    else buildPhase;

    installPhase = if installPhase == null
    then ''
        runHook preInstall

        MIXENV=prod

        if [ -d "_build/shared" ]; then
          MIXENV=shared
        fi

        mkdir -p "$out/lib/erlang/lib/${name}-${version}"
        for reldir in src ebin priv include; do
          fd="_build/$MIXENV/lib/${name}/$reldir"
          [ -d "$fd" ] || continue
          cp -Hrt "$out/lib/erlang/lib/${name}-${version}" "$fd"
          success=1
        done

        runHook postInstall
    ''
    else installPhase;

    passthru = {
      packageName = name;
      env = shell self;
      inherit beamDeps;
    };
});
in fix pkg