summary refs log tree commit diff
path: root/pkgs/development/beam-modules/erlang-ls/default.nix
blob: de7d0497d0760d8e150a38107aec0630d5997429 (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
{ fetchFromGitHub, fetchgit, fetchHex, rebar3Relx, buildRebar3, rebar3-proper
, stdenv, writeScript, lib, erlang }:
let
  version = "0.41.2";
  owner = "erlang-ls";
  repo = "erlang_ls";
  deps = import ./rebar-deps.nix {
    inherit fetchHex fetchFromGitHub fetchgit;
    builder = buildRebar3;
    overrides = (self: super: {
      proper = super.proper.overrideAttrs (_: {
        configurePhase = "true";
      });
      redbug = super.redbug.overrideAttrs (_: {
        patchPhase = ''
          substituteInPlace rebar.config --replace ", warnings_as_errors" ""
          '';
      });
    });
  };
in
rebar3Relx {
  pname = "erlang-ls";
  inherit version;
  src = fetchFromGitHub {
    inherit owner repo;
    sha256 = "sha256-LUgiQtK0OsdTmg1jEdxJ0x+39U3PXoFYsGlOv4l7/Ig=";
    rev = version;
  };
  releaseType = "escript";
  beamDeps = builtins.attrValues deps;

  # Skip "els_hover_SUITE" test for Erlang/OTP 25+ while upstream hasn't fixed it
  # https://github.com/erlang-ls/erlang_ls/pull/1402
  postPatch = lib.optionalString (lib.versionOlder "25" erlang.version) ''
    rm apps/els_lsp/test/els_hover_SUITE.erl
  '';

  buildPlugins = [ rebar3-proper ];
  buildPhase = "HOME=. make";
  # based on https://github.com/erlang-ls/erlang_ls/blob/main/.github/workflows/build.yml
  # these tests are excessively long and we should probably skip them
  checkPhase = ''
    HOME=. epmd -daemon
    HOME=. rebar3 ct
    HOME=. rebar3 proper --constraint_tries 100
  '';
  # tests seem to be a bit flaky on darwin, skip them for now
  doCheck = !stdenv.isDarwin;
  installPhase = ''
    mkdir -p $out/bin
    cp _build/default/bin/erlang_ls $out/bin/
    cp _build/dap/bin/els_dap $out/bin/
  '';
  meta = with lib; {
    homepage = "https://github.com/erlang-ls/erlang_ls";
    description = "The Erlang Language Server";
    platforms = platforms.unix;
    license = licenses.asl20;
  };
  passthru.updateScript = writeScript "update.sh" ''
    #!/usr/bin/env nix-shell
    #! nix-shell -i bash -p common-updater-scripts coreutils git gnused gnutar gzip "rebar3WithPlugins { globalPlugins = [ beamPackages.rebar3-nix ]; }"

    set -ox errexit
    latest=$(list-git-tags | sed -n '/[\d\.]\+/p' | sort -V | tail -1)
    if [[ "$latest" != "${version}" ]]; then
      nixpkgs="$(git rev-parse --show-toplevel)"
      nix_path="$nixpkgs/pkgs/development/beam-modules/erlang-ls"
      update-source-version erlang-ls "$latest" --version-key=version --print-changes --file="$nix_path/default.nix"
      tmpdir=$(mktemp -d)
      cp -R $(nix-build $nixpkgs --no-out-link -A erlang-ls.src)/* "$tmpdir"
      DEBUG=1
      (cd "$tmpdir" && HOME=. rebar3 as test nix lock -o "$nix_path/rebar-deps.nix")
    else
      echo "erlang-ls is already up-to-date"
    fi
  '';
}