diff --git a/pkgs/by-name/pg/pgsql-tools/package.nix b/pkgs/by-name/pg/pgsql-tools/package.nix new file mode 100644 index 000000000000..ab9d06f47d11 --- /dev/null +++ b/pkgs/by-name/pg/pgsql-tools/package.nix @@ -0,0 +1,89 @@ +{ + stdenv, + lib, + fetchurl, + autoPatchelfHook, + libxcrypt-legacy, + makeBinaryWrapper, + pgsql-tools, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "pgsql-tools"; + version = "2.1.0"; + + src = fetchurl ( + let + sources = { + x86_64-linux = { + url = "https://github.com/microsoft/pgsql-tools/releases/download/v${finalAttrs.version}/pgsqltoolsservice-linux-x64.tar.gz"; + hash = "sha256-dN7+LJCUwb39ypuJV4p3jUHNGAPaObN4aZvsOHIpmkQ="; + }; + aarch64-linux = { + url = "https://github.com/microsoft/pgsql-tools/releases/download/v${finalAttrs.version}/pgsqltoolsservice-linux-arm64.tar.gz"; + hash = "sha256-rD8jymGdM1RDGDbrKu6E7xoWtSMRNuc2ngCmR+sHgQI="; + }; + x86_64-darwin = { + url = "https://github.com/microsoft/pgsql-tools/releases/download/v${finalAttrs.version}/pgsqltoolsservice-osx-x86.tar.gz"; + hash = "sha256-KLl7HPChurzB6QYV6AqAP3g1J3VKl61+we3opzJQwG0="; + }; + aarch64-darwin = { + url = "https://github.com/microsoft/pgsql-tools/releases/download/v${finalAttrs.version}/pgsqltoolsservice-osx-arm64.tar.gz"; + hash = "sha256-tpabEKB1kqse7D58FsP/9jywk+vgAAvptL9MadwxWg8="; + }; + }; + in + sources.${stdenv.hostPlatform.system} + ); + + nativeBuildInputs = [ + makeBinaryWrapper + ] + ++ lib.optionals stdenv.isLinux [ + autoPatchelfHook + ]; + + buildInputs = lib.optionals stdenv.isLinux [ + libxcrypt-legacy + (lib.getLib stdenv.cc.cc) + ]; + + dontBuild = true; + dontStrip = true; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin $out/lib/pgsql-tools + install -Dm755 ossdbtoolsservice_main $out/lib/pgsql-tools/ossdbtoolsservice_main + cp -r _internal $out/lib/pgsql-tools/ + + makeBinaryWrapper $out/lib/pgsql-tools/ossdbtoolsservice_main $out/bin/ossdbtoolsservice_main \ + ${lib.optionalString stdenv.isLinux ''--prefix LD_LIBRARY_PATH : "${ + lib.makeLibraryPath [ + libxcrypt-legacy + (lib.getLib stdenv.cc.cc) + ] + }"''} \ + --chdir $out/lib/pgsql-tools + + runHook postInstall + ''; + + doInstallCheck = true; + + passthru = { + updateScript = ./update.sh; + }; + + meta = { + homepage = "https://github.com/microsoft/pgsql-tools"; + description = "Backend service for PostgreSQL server tools, offering features such as connection management, query execution with result set handling, and language service support via the VS Code protocol"; + changelog = "https://github.com/microsoft/pgsql-tools/releases/tag/v${finalAttrs.version}"; + license = lib.licenses.mit; + platforms = lib.platforms.linux ++ lib.platforms.darwin; + maintainers = with lib.maintainers; [ liberodark ]; + mainProgram = "ossdbtoolsservice_main"; + sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; + }; +}) diff --git a/pkgs/by-name/pg/pgsql-tools/update.sh b/pkgs/by-name/pg/pgsql-tools/update.sh new file mode 100644 index 000000000000..ddd35c318e8a --- /dev/null +++ b/pkgs/by-name/pg/pgsql-tools/update.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p bash curl jq nix nix-prefetch common-updater-scripts + +set -euo pipefail + +latestVersion=$(curl --fail --silent https://api.github.com/repos/microsoft/pgsql-tools/releases/latest | jq --raw-output '.tag_name | ltrimstr("v")') +currentVersion=$(nix eval --raw -f . pgsql-tools.version 2>/dev/null || echo "unknown") + +echo "latest version: $latestVersion" +echo "current version: $currentVersion" + +if [[ "$latestVersion" == "$currentVersion" ]]; then + echo "package is up-to-date" + exit 0 +fi + +update-source-version pgsql-tools "$latestVersion" --file=pkgs/by-name/pg/pgsql-tools/package.nix + +declare -A platforms=( + ["x86_64-linux"]="pgsqltoolsservice-linux-x64.tar.gz" + ["aarch64-linux"]="pgsqltoolsservice-linux-arm64.tar.gz" + ["x86_64-darwin"]="pgsqltoolsservice-osx-x86.tar.gz" + ["aarch64-darwin"]="pgsqltoolsservice-osx-arm64.tar.gz" +) + +for system in "${!platforms[@]}"; do + filename="${platforms[$system]}" + url="https://github.com/microsoft/pgsql-tools/releases/download/v${latestVersion}/${filename}" + + echo "Updating hash for $system..." + hash=$(nix --extra-experimental-features nix-command hash convert --to sri --hash-algo sha256 $(nix-prefetch-url "$url")) + update-source-version pgsql-tools "$latestVersion" "$hash" --system="$system" --ignore-same-version --ignore-same-hash +done