From 070fa4cefc5b7bd0c8f95850adfcb4f0bf4bd09a Mon Sep 17 00:00:00 2001 From: happysalada Date: Tue, 31 Aug 2021 18:03:46 +0900 Subject: [PATCH] elixir_ls: add update script --- pkgs/development/beam-modules/default.nix | 2 +- .../{elixir_ls.nix => elixir-ls/default.nix} | 1 + .../beam-modules/elixir-ls/update.sh | 32 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) rename pkgs/development/beam-modules/{elixir_ls.nix => elixir-ls/default.nix} (98%) create mode 100755 pkgs/development/beam-modules/elixir-ls/update.sh diff --git a/pkgs/development/beam-modules/default.nix b/pkgs/development/beam-modules/default.nix index b6be8c3e7fbd..1c9d5099b44f 100644 --- a/pkgs/development/beam-modules/default.nix +++ b/pkgs/development/beam-modules/default.nix @@ -76,7 +76,7 @@ let debugInfo = true; }; - elixir_ls = callPackage ./elixir_ls.nix { inherit elixir fetchMixDeps mixRelease; }; + elixir_ls = callPackage ./elixir-ls { inherit elixir fetchMixDeps mixRelease; }; lfe = lfe_1_3; lfe_1_3 = lib'.callLFE ../interpreters/lfe/1.3.nix { inherit erlang buildRebar3 buildHex; }; diff --git a/pkgs/development/beam-modules/elixir_ls.nix b/pkgs/development/beam-modules/elixir-ls/default.nix similarity index 98% rename from pkgs/development/beam-modules/elixir_ls.nix rename to pkgs/development/beam-modules/elixir-ls/default.nix index 2b6cc4f56810..56aa47f59f9f 100644 --- a/pkgs/development/beam-modules/elixir_ls.nix +++ b/pkgs/development/beam-modules/elixir-ls/default.nix @@ -68,4 +68,5 @@ mixRelease rec { 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 000000000000..8bc1c2b6e966 --- /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" +}