summary refs log tree commit diff
path: root/pkgs/development/beam-modules/elixir-ls
diff options
context:
space:
mode:
authorhappysalada <raphael@megzari.com>2021-08-31 18:03:46 +0900
committerRaphael Megzari <raphael@megzari.com>2021-09-02 10:55:45 +0900
commit070fa4cefc5b7bd0c8f95850adfcb4f0bf4bd09a (patch)
tree0a95143b4d03d97aac57d5fd94144efdb9e27510 /pkgs/development/beam-modules/elixir-ls
parent07978cddabe1ddce172b1376560add398750e2d3 (diff)
downloadnixpkgs-070fa4cefc5b7bd0c8f95850adfcb4f0bf4bd09a.tar
nixpkgs-070fa4cefc5b7bd0c8f95850adfcb4f0bf4bd09a.tar.gz
nixpkgs-070fa4cefc5b7bd0c8f95850adfcb4f0bf4bd09a.tar.bz2
nixpkgs-070fa4cefc5b7bd0c8f95850adfcb4f0bf4bd09a.tar.lz
nixpkgs-070fa4cefc5b7bd0c8f95850adfcb4f0bf4bd09a.tar.xz
nixpkgs-070fa4cefc5b7bd0c8f95850adfcb4f0bf4bd09a.tar.zst
nixpkgs-070fa4cefc5b7bd0c8f95850adfcb4f0bf4bd09a.zip
elixir_ls: add update script
Diffstat (limited to 'pkgs/development/beam-modules/elixir-ls')
-rw-r--r--pkgs/development/beam-modules/elixir-ls/default.nix72
-rwxr-xr-xpkgs/development/beam-modules/elixir-ls/update.sh32
2 files changed, 104 insertions, 0 deletions
diff --git a/pkgs/development/beam-modules/elixir-ls/default.nix b/pkgs/development/beam-modules/elixir-ls/default.nix
new file mode 100644
index 00000000000..56aa47f59f9
--- /dev/null
+++ b/pkgs/development/beam-modules/elixir-ls/default.nix
@@ -0,0 +1,72 @@
+{ lib, elixir, fetchFromGitHub, fetchMixDeps, mixRelease }:
+# Based on the work of Hauleth
+# None of this would have happened without him
+
+mixRelease rec {
+  pname = "elixir-ls";
+  version = "0.8.0";
+
+  src = fetchFromGitHub {
+    owner = "elixir-lsp";
+    repo = "elixir-ls";
+    rev = "v${version}";
+    sha256 = "sha256-pUvONMTYH8atF/p2Ep/K3bwJUDxTzCsxLPbpjP0tQpM=";
+    fetchSubmodules = true;
+  };
+
+  mixFodDeps = fetchMixDeps {
+    pname = "mix-deps-${pname}";
+    inherit src version;
+    sha256 = "sha256-YRzPASpg1K2kZUga5/aQf4Q33d8aHCwhw7KJxSY56k4=";
+  };
+
+  # elixir_ls is an umbrella app
+  # override configurePhase to not skip umbrella children
+  configurePhase = ''
+    runHook preConfigure
+    mix deps.compile --no-deps-check
+    runHook postConfigure
+  '';
+
+  # elixir_ls require a special step for release
+  # compile and release need to be performed together because
+  # of the no-deps-check requirement
+  buildPhase = ''
+    runHook preBuild
+    mix do compile --no-deps-check, elixir_ls.release
+    runHook postBuild
+  '';
+
+  installPhase = ''
+    runHook preInstall
+    mkdir -p $out/bin
+    cp -Rv release $out/lib
+    # Prepare the wrapper script
+    substitute release/language_server.sh $out/bin/elixir-ls \
+      --replace 'exec "''${dir}/launch.sh"' "exec $out/lib/launch.sh"
+    chmod +x $out/bin/elixir-ls
+    # prepare the launcher
+    substituteInPlace $out/lib/launch.sh \
+      --replace "ERL_LIBS=\"\$SCRIPTPATH:\$ERL_LIBS\"" \
+                "ERL_LIBS=$out/lib:\$ERL_LIBS" \
+      --replace "exec elixir" "exec ${elixir}/bin/elixir"
+    runHook postInstall
+  '';
+
+  meta = with lib; {
+    homepage = "https://github.com/elixir-lsp/elixir-ls";
+    description = ''
+      A frontend-independent IDE "smartness" server for Elixir.
+      Implements the "Language Server Protocol" standard and provides debugger support via the "Debug Adapter Protocol"
+    '';
+    longDescription = ''
+      The Elixir Language Server provides a server that runs in the background, providing IDEs, editors, and other tools with information about Elixir Mix projects.
+      It adheres to the Language Server Protocol, a standard for frontend-independent IDE support.
+      Debugger integration is accomplished through the similar VS Code Debug Protocol.
+    '';
+    license = licenses.asl20;
+    platforms = platforms.unix;
+    maintainers = teams.beam.members;
+  };
+  passthru.updateScript = ./update.sh;
+}
diff --git a/pkgs/development/beam-modules/elixir-ls/update.sh b/pkgs/development/beam-modules/elixir-ls/update.sh
new file mode 100755
index 00000000000..8bc1c2b6e96
--- /dev/null
+++ b/pkgs/development/beam-modules/elixir-ls/update.sh
@@ -0,0 +1,32 @@
+#!/usr/bin/env nix-shell
+#! nix-shell -i oil -p jq sd nix-prefetch-github ripgrep
+
+# TODO set to `verbose` or `extdebug` once implemented in oil
+shopt --set xtrace
+
+var directory = $(dirname $0 | xargs realpath)
+var owner = "elixir-lsp"
+var repo = "elixir-ls"
+var latest_rev = $(curl -q https://api.github.com/repos/${owner}/${repo}/releases/latest | \
+  jq -r '.tag_name')
+var latest_version = $(echo $latest_rev | sd 'v' '')
+var current_version = $(nix-instantiate -A elixir_ls.version --eval --json | jq -r)
+if ("$latest_version" == "$current_version") {
+  echo "elixir-ls is already up-to-date"
+  return 0
+} else {
+  var tarball_meta = $(nix-prefetch-github $owner $repo --rev "$latest_rev")
+  var tarball_hash = "sha256-$(echo $tarball_meta | jq -r '.sha256')"
+  var sha256s = $(rg '"sha256-.+"' $directory/default.nix | sd '.+"(.+)";' '$1' )
+  echo $sha256s | read --line :github_sha256
+  echo $sha256s | tail -n 1 | read --line :old_mix_sha256
+  sd 'version = ".+"' "version = \"$latest_version\"" "$directory/default.nix"
+  sd "sha256 = \"$github_sha256\"" "sha256 = \"$tarball_hash\"" "$directory/default.nix"
+  sd "sha256 = \"$old_mix_sha256\"" "sha256 = \"\"" "$directory/default.nix"
+
+  var new_mix_hash = $(nix-build -A elixir_ls.mixFodDeps 2>&1 | \
+    tail -n 1 | \
+    sd '\s+got:\s+' '')
+
+  sd "sha256 = \"\"" "sha256 = \"$new_mix_hash\"" "$directory/default.nix"
+}