summaryrefslogtreecommitdiffstats
path: root/pkgs/development/beam-modules/build-rebar3.nix
blob: a202f9a0303b76e9278ee1dc269a035d2160e6cc (plain)
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
{
  erlang,
  beamCopySourceHook,
  beamModuleInstallHook,
  rebar3CompileHook,
  rebar3WithPlugins,
  rebarDevendorPatchHook,

  libyaml,
  openssl,

  lib,
  stdenv,
  writeText,
}:

lib.extendMkDerivation {
  constructDrv = stdenv.mkDerivation;
  excludeDrvArgNames = [
    "beamDeps"
    "buildPlugins"
  ];
  extendDrvArgs =
    finalAttrs:
    {
      beamDeps ? [ ],
      buildPlugins ? [ ],

      enableDebugInfo ? false,
      erlangCompilerOptions ? [ ],
      # Deterministic Erlang builds remove full system paths from debug information
      # among other things to keep builds more reproducible. See their docs for more:
      # https://www.erlang.org/doc/man/compile
      erlangDeterministicBuilds ? true,
      ...
    }@args:
    let
      rebar3Custom = rebar3WithPlugins {
        plugins = buildPlugins;
      };
    in
    {
      pname = args.name;
      name = "erlang${erlang.version}-${args.name}-${finalAttrs.version}";

      nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
        erlang
        rebar3Custom

        rebarDevendorPatchHook
        beamCopySourceHook
        beamModuleInstallHook
        rebar3CompileHook
      ];

      buildInputs = (args.buildInputs or [ ]) ++ [
        openssl
        libyaml
      ];

      propagatedBuildInputs = lib.unique beamDeps;

      __structuredAttrs = true;
      strictDeps = true;

      env = {
        ERL_COMPILER_OPTIONS =
          let
            options = erlangCompilerOptions ++ lib.optionals erlangDeterministicBuilds [ "deterministic" ];
          in
          "[${lib.concatStringsSep "," options}]";

        beamModuleName = args.name;
      }
      // (args.env or { });

      setupHook = writeText "setupHook.sh" ''
        addToSearchPath ERL_LIBS "$1/lib/erlang/lib/"
      '';

      meta = {
        inherit (erlang.meta) platforms;
      }
      // (args.meta or { });

      passthru = {
        inherit beamDeps;
      };
    };
}