nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at 21.05 64 lines 2.4 kB view raw
1#!/usr/bin/env nix-shell 2#!nix-shell -i bash -p curl jq nix-prefetch 3set -euo pipefail 4cd "$(dirname "$0")" 5owner=rust-analyzer 6repo=rust-analyzer 7nixpkgs=../../../../.. 8 9# Update lsp 10 11ver=$( 12 curl -s "https://api.github.com/repos/$owner/$repo/releases" | 13 jq 'map(select(.prerelease | not)) | .[0].tag_name' --raw-output 14) 15old_ver=$(sed -nE 's/.*\bversion = "(.*)".*/\1/p' ./default.nix) 16if grep -q 'cargoSha256 = ""' ./default.nix; then 17 old_ver='broken' 18fi 19if [[ "$ver" == "$old_ver" ]]; then 20 echo "Up to date: $ver" 21 exit 22fi 23echo "$old_ver -> $ver" 24 25sha256=$(nix-prefetch -f "$nixpkgs" rust-analyzer-unwrapped.src --rev "$ver") 26# Clear cargoSha256 to avoid inconsistency. 27sed -e "s#version = \".*\"#version = \"$ver\"#" \ 28 -e "/fetchFromGitHub/,/}/ s#sha256 = \".*\"#sha256 = \"$sha256\"#" \ 29 -e "s#cargoSha256 = \".*\"#cargoSha256 = \"sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\"#" \ 30 --in-place ./default.nix 31node_src="$(nix-build "$nixpkgs" -A rust-analyzer.src --no-out-link)/editors/code" 32 33# Check vscode compatibility 34req_vscode_ver="$(jq '.engines.vscode' "$node_src/package.json" --raw-output)" 35req_vscode_ver="${req_vscode_ver#^}" 36cur_vscode_ver="$(nix-instantiate --eval --strict "$nixpkgs" -A vscode.version | tr -d '"')" 37if [[ "$(nix-instantiate --eval --strict -E "(builtins.compareVersions \"$req_vscode_ver\" \"$cur_vscode_ver\")")" -gt 0 ]]; then 38 echo "vscode $cur_vscode_ver is incompatible with the extension requiring ^$req_vscode_ver" 39 exit 1 40fi 41 42echo "Prebuilding for cargoSha256" 43cargo_sha256=$(nix-prefetch "{ sha256 }: (import $nixpkgs {}).rust-analyzer-unwrapped.cargoDeps.overrideAttrs (_: { outputHash = sha256; })") 44sed "s#cargoSha256 = \".*\"#cargoSha256 = \"$cargo_sha256\"#" \ 45 --in-place ./default.nix 46 47# Update vscode extension 48 49build_deps="../../../../misc/vscode-extensions/rust-analyzer/build-deps" 50# We need devDependencies to build vsix. 51jq '{ name, version, dependencies: (.dependencies + .devDependencies) }' "$node_src/package.json" \ 52 >"$build_deps/package.json.new" 53 54if cmp --quiet "$build_deps"/package.json{.new,}; then 55 echo "package.json not changed, skip updating nodePackages" 56 rm "$build_deps"/package.json.new 57else 58 echo "package.json changed, updating nodePackages" 59 mv "$build_deps"/package.json{.new,} 60 61 pushd "../../../node-packages" 62 ./generate.sh 63 popd 64fi