summaryrefslogtreecommitdiffstats
path: root/pkgs/development/interpreters/erlang/generic-builder.nix
blob: 646bf961f0385a352098dd56aec716889121e7ad (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
{
  # options set through beam-packages
  # systemd support for epmd only
  systemdSupport ? null,
  wxSupport ? true,

  # options set by version specific files, e.g. 28.nix
  version,
  hash ? null,

}:
{
  # overridable options
  enableDebugInfo ? false,
  enableHipe ? true,
  enableKernelPoll ? true,
  enableSmpSupport ? true,
  enableThreads ? true,
  javacSupport ? false,
  odbcSupport ? false,
  parallelBuild ? true,

  fetchFromGitHub,
  gawk,
  gnum4,
  gnused,
  lib,
  libGL,
  libGLU,
  libxml2,
  libxslt,
  makeWrapper,
  ncurses,
  nix-update-script,
  openjdk11,
  openssl,
  perl,
  runtimeShell,
  stdenv,
  systemd,
  unixodbc,
  wrapGAppsHook3,
  wxwidgets_3_2,
  libx11,
  zlib,
}:
let
  inherit (lib)
    optional
    optionals
    optionalString
    ;

  wxPackages2 =
    if stdenv.hostPlatform.isDarwin then
      [ wxwidgets_3_2 ]
    else
      [
        libGL
        libGLU
        wxwidgets_3_2
        libx11
        wrapGAppsHook3
      ];

  major = builtins.head (builtins.splitVersion version);

  enableSystemd =
    if (systemdSupport == null) then
      lib.meta.availableOn stdenv.hostPlatform systemd
    else
      systemdSupport;

  runtimePath = lib.makeBinPath [
    gawk
    gnused
  ];
in
stdenv.mkDerivation {
  pname = "erlang" + optionalString javacSupport "_javac" + optionalString odbcSupport "_odbc";
  inherit version;

  src = fetchFromGitHub {
    owner = "erlang";
    repo = "otp";
    tag = "OTP-${version}";
    inherit hash;
  };

  env = {
    # only build man pages and shell/IDE docs
    DOC_TARGETS = "man chunks";
    LANG = "C.UTF-8";
  };

  nativeBuildInputs = [
    makeWrapper
    perl
    gnum4
    libxslt
    libxml2
  ];

  buildInputs = [
    ncurses
    openssl
    zlib
  ]
  ++ optionals wxSupport wxPackages2
  ++ optionals odbcSupport [ unixodbc ]
  ++ optionals javacSupport [ openjdk11 ]
  ++ optionals enableSystemd [ systemd ];

  # disksup requires a shell
  postPatch = ''
    substituteInPlace lib/os_mon/src/disksup.erl --replace-fail '"sh ' '"${runtimeShell} '
  '';

  debugInfo = enableDebugInfo;

  # On some machines, parallel build reliably crashes on `GEN    asn1ct_eval_ext.erl` step
  enableParallelBuilding = parallelBuild;

  configureFlags = [
    "--with-ssl=${lib.getOutput "out" openssl}"
    "--with-ssl-incl=${lib.getDev openssl}"
  ]
  ++ optional enableThreads "--enable-threads"
  ++ optional enableSmpSupport "--enable-smp-support"
  ++ optional enableKernelPoll "--enable-kernel-poll"
  ++ optional enableHipe "--enable-hipe"
  ++ optional javacSupport "--with-javac"
  ++ optional odbcSupport "--with-odbc=${unixodbc}"
  ++ optional wxSupport "--enable-wx"
  ++ optional enableSystemd "--enable-systemd"
  ++ optional stdenv.hostPlatform.isDarwin "--enable-darwin-64bit"
  # make[3]: *** [yecc.beam] Segmentation fault: 11
  ++ optional (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) "--disable-jit";

  installTargets = [
    "install"
    "install-docs"
  ];

  postInstall = ''
    ln -sv $out/lib/erlang/lib/erl_interface*/bin/erl_call $out/bin/erl_call

    wrapProgram $out/lib/erlang/bin/erl --prefix PATH ":" "${runtimePath}"
    wrapProgram $out/lib/erlang/bin/start_erl --prefix PATH ":" "${runtimePath}"
  '';

  passthru = {
    updateScript = nix-update-script {
      extraArgs = [
        "--version-regex"
        "OTP-(${major}.*)"
        "--override-filename"
        "pkgs/development/interpreters/erlang/${major}.nix"
      ];
    };
  };

  meta = {
    homepage = "https://www.erlang.org/";
    downloadPage = "https://www.erlang.org/download.html";
    description = "Programming language used for massively scalable soft real-time systems";
    changelog = "https://github.com/erlang/otp/releases/tag/OTP-${version}";

    longDescription = ''
      Erlang is a programming language used to build massively scalable
      soft real-time systems with requirements on high availability.
      Some of its uses are in telecoms, banking, e-commerce, computer
      telephony and instant messaging. Erlang's runtime system has
      built-in support for concurrency, distribution and fault
      tolerance.
    '';

    platforms = lib.platforms.unix;
    teams = [ lib.teams.beam ];
    license = lib.licenses.asl20;
  };
}