1{
2 erlang,
3 fetchFromGitHub,
4 fetchgit,
5 fetchHex,
6 rebar3Relx,
7 buildRebar3,
8 rebar3-proper,
9 stdenv,
10 writeScript,
11 lib,
12}:
13let
14 version = "1.1.0";
15 owner = "erlang-ls";
16 repo = "erlang_ls";
17
18 deps = import ./rebar-deps.nix {
19 inherit fetchHex fetchFromGitHub fetchgit;
20 builder = buildRebar3;
21 overrides = (
22 self: super: {
23 proper = super.proper.overrideAttrs (_: {
24 configurePhase = "true";
25 });
26 redbug = super.redbug.overrideAttrs (_: {
27 patchPhase = ''
28 substituteInPlace rebar.config --replace ", warnings_as_errors" ""
29 '';
30 });
31 json_polyfill = super.json_polyfill.overrideAttrs (_: {
32 # When compiling with erlang >= 27, the json_polyfill rebar script will
33 # delete the json.beam file as it's not needed. However, we need to
34 # adjust this path as the nix build will put the beam file under `ebin`
35 # instead of `$REBAR_DEPS_DIR/json_polyfill/ebin`.
36 postPatch = ''
37 substituteInPlace rebar.config.script --replace "{erlc_compile, \"rm \\\"\$REBAR_DEPS_DIR/json_polyfill/ebin/json.beam\\\"\"}" "{erlc_compile, \"rm \\\"ebin/json.beam\\\"\"}"
38 '';
39 });
40 }
41 );
42 };
43in
44rebar3Relx {
45 pname = "erlang-ls";
46
47 inherit version;
48
49 src = fetchFromGitHub {
50 inherit owner repo;
51 hash = "sha256-MSDBU+blsAdeixaHMMXmeMJ+9Yrzn3HekE8KbIc/Guo=";
52 rev = version;
53 };
54
55 # remove when fixed upstream https://github.com/erlang-ls/erlang_ls/pull/1576
56 patches = lib.optionals (lib.versionAtLeast erlang.version "27") [ ./1576.diff ];
57
58 releaseType = "escript";
59 beamDeps = builtins.attrValues deps;
60
61 buildPlugins = [ rebar3-proper ];
62 buildPhase = "HOME=. make";
63 # based on https://github.com/erlang-ls/erlang_ls/blob/main/.github/workflows/build.yml
64 # these tests are excessively long and we should probably skip them
65 checkPhase = ''
66 HOME=. epmd -daemon
67 HOME=. rebar3 ct
68 HOME=. rebar3 proper --constraint_tries 100
69 '';
70 installFlags = [ "PREFIX=$(out)" ];
71
72 # tests seem to be a bit flaky on darwin, skip them for now
73 doCheck = !stdenv.hostPlatform.isDarwin;
74
75 passthru.updateScript = writeScript "update.sh" ''
76 #!/usr/bin/env nix-shell
77 #! nix-shell -i bash -p common-updater-scripts coreutils git gnused gnutar gzip "rebar3WithPlugins { globalPlugins = [ beamPackages.rebar3-nix ]; }"
78
79 set -ox errexit
80 latest=$(list-git-tags | sed -n '/[\d\.]\+/p' | sort -V | tail -1)
81 if [[ "$latest" != "${version}" ]]; then
82 nixpkgs="$(git rev-parse --show-toplevel)"
83 nix_path="$nixpkgs/pkgs/development/beam-modules/erlang-ls"
84 update-source-version erlang-ls "$latest" --version-key=version --print-changes --file="$nix_path/default.nix"
85 tmpdir=$(mktemp -d)
86 cp -R $(nix-build $nixpkgs --no-out-link -A erlang-ls.src)/* "$tmpdir"
87 DEBUG=1
88 (cd "$tmpdir" && HOME=. rebar3 as test nix lock -o "$nix_path/rebar-deps.nix")
89 nixfmt "$nix_path/rebar-deps.nix"
90 else
91 echo "erlang-ls is already up-to-date"
92 fi
93 '';
94
95 meta = with lib; {
96 homepage = "https://github.com/erlang-ls/erlang_ls";
97 description = "Erlang Language Server";
98 platforms = platforms.unix;
99 license = licenses.asl20;
100 mainProgram = "erlang_ls";
101 };
102}