summary refs log tree commit diff
path: root/pkgs/development/interpreters/lfe/generic-builder.nix
blob: ba42c2d59d56b6aa69df7686a3156e12d1de2dfa (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
{ stdenv, fetchFromGitHub, erlang, makeWrapper, coreutils, bash, buildRebar3, buildHex }:

{ baseName ? "lfe"
, version
, maximumOTPVersion
, sha256 ? null
, rev ? version
, src ? fetchFromGitHub { inherit rev sha256; owner = "rvirding"; repo = "lfe"; }
, patches ? []
}:

let
  inherit (stdenv.lib)
    assertMsg makeBinPath optionalString
    getVersion versionAtLeast versionOlder versions;

  mainVersion = versions.major (getVersion erlang);

  proper = buildHex {
    name = "proper";
    version = "1.1.1-beta";

    sha256  = "0hnkhs761yjynw9382w8wm4j3x0r7lllzavaq2kh9n7qy3zc1rdx";

    configurePhase = ''
      ${erlang}/bin/escript write_compile_flags include/compile_flags.hrl
    '';
  };

in
assert (assertMsg (versionAtLeast maximumOTPVersion mainVersion)) ''
  LFE ${version} is supported on OTP <=${maximumOTPVersion}, not ${mainVersion}.
'';

buildRebar3 {
  name = baseName;

  inherit src version;

  buildInputs = [ erlang makeWrapper ];
  beamDeps    = [ proper ];
  patches     = [ ./no-test-deps.patch ./dedup-ebins.patch ] ++ patches;
  doCheck     = true;
  checkTarget = "travis";

  makeFlags = [ "-e" "MANDB=''" "PREFIX=$$out"];

  # These installPhase tricks are based on Elixir's Makefile.
  # TODO: Make, upload, and apply a patch.
  installPhase = optionalString (versionOlder version "1.3") ''
    local libdir=$out/lib/lfe
    local ebindir=$libdir/ebin
    local bindir=$libdir/bin

    rm -Rf $ebindir
    install -m755 -d $ebindir
    install -m644 _build/default/lib/lfe/ebin/* $ebindir

    install -m755 -d $bindir

    for bin in bin/lfe{,c,doc,script}; do install -m755 $bin $bindir; done

    install -m755 -d $out/bin
    for file in $bindir/*; do ln -sf $file $out/bin/; done
  '';

  # Thanks again, Elixir.
  postFixup = ''
    # LFE binaries are shell scripts which run erl and lfe.
    # Add some stuff to PATH so the scripts can run without problems.
    for f in $out/bin/*; do
      wrapProgram $f \
        --prefix PATH ":" "${makeBinPath [ erlang coreutils bash ]}:$out/bin"
      substituteInPlace $f --replace "/usr/bin/env" "${coreutils}/bin/env"
    done
  '';

  meta = with stdenv.lib; {
    description     = "The best of Erlang and of Lisp; at the same time!";
    longDescription = ''
      LFE, Lisp Flavoured Erlang, is a lisp syntax front-end to the Erlang
      compiler. Code produced with it is compatible with "normal" Erlang
      code. An LFE evaluator and shell is also included.
    '';

    homepage     = "http://lfe.io";
    downloadPage = "https://github.com/rvirding/lfe/releases";

    license      = licenses.asl20;
    maintainers  = with maintainers; [ yurrriq ankhers ];
    platforms    = platforms.unix;
  };
}