Merge pull request #260133 from ProminentRetail/tradingview

tradingview: init at 2.6.1
This commit is contained in:
Weijia Wang
2023-10-15 00:37:57 +02:00
committed by GitHub
2 changed files with 161 additions and 0 deletions
+91
View File
@@ -0,0 +1,91 @@
{ lib
, stdenv
, fetchurl
, autoPatchelfHook
, squashfsTools
, makeBinaryWrapper
, alsa-lib
, atk
, at-spi2-atk
, cups
, gtk3
, libdrm
, libsecret
, libxkbcommon
, mesa
, pango
, sqlite
, systemd
, wayland
, xorg
}:
stdenv.mkDerivation rec {
pname = "tradingview";
version = "2.6.1";
revision = "44";
src = fetchurl {
url = "https://api.snapcraft.io/api/v1/snaps/download/nJdITJ6ZJxdvfu8Ch7n5kH5P99ClzBYV_${revision}.snap";
hash = "sha512-Hd00TWjPskd0QDzpOSwQCuMw20nW4n1xxRkT1rA95pzbXtw7XFxrJdMWkzWDbucuokU2qR2b5tovAHAgw9E0tQ==";
};
nativeBuildInputs = [
autoPatchelfHook
makeBinaryWrapper
squashfsTools
];
buildInputs = [
stdenv.cc.cc.lib
alsa-lib
atk
at-spi2-atk
cups
gtk3
libdrm
libsecret
libxkbcommon
mesa
pango
sqlite
systemd
wayland
xorg.libxcb
xorg.libX11
xorg.libXext
];
unpackPhase = ''
runHook preUnpack
unsquashfs $src
runHook postUnpack
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r squashfs-root/* $out
mkdir -p $out/share/applications
mv $out/meta/gui/tradingview.desktop $out/share/applications
substituteInPlace $out/share/applications/tradingview.desktop --replace \$\{SNAP} $out
mkdir $out/bin
makeBinaryWrapper $out/tradingview $out/bin/tradingview --prefix LD_LIBRARY_PATH : ${ lib.makeLibraryPath buildInputs }
runHook postInstall
'';
meta = with lib; {
description = "Charting platform for traders and investors";
homepage = "https://www.tradingview.com/desktop/";
changelog = "https://www.tradingview.com/support/solutions/43000673888/";
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
license = licenses.unfree;
maintainers = with maintainers; [ prominentretail ];
platforms = [ "x86_64-linux" ];
mainProgram = "tradingview";
};
}
+70
View File
@@ -0,0 +1,70 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p curl jq git gnused gnugrep
#
# Get latest version of TradingView from Snapcraft.
#
snap_info=($(
curl -s -H 'X-Ubuntu-Series: 16' \
'https://api.snapcraft.io/api/v1/snaps/details/tradingview' \
| jq --raw-output \
'.revision,.download_sha512,.version,.last_updated'
))
# "revision" is the actual version identifier; "version" is for human consumption.
revision="${snap_info[0]}"
sha512="${snap_info[1]}"
sri=$(nix hash to-sri --type "sha512" $sha512)
upstream_version="${snap_info[2]}"
last_updated="${snap_info[3]}"
echo "Latest release is $upstream_version from $last_updated."
#
# Read the current TradingView version.
#
nixpkgs="$(git rev-parse --show-toplevel)"
tradingview_nix="$nixpkgs/pkgs/applications/finance/tradingview/default.nix"
current_nix_version=$(
grep 'version\s*=' "$tradingview_nix" \
| sed -Ene 's/.*"(.*)".*/\1/p'
)
echo "Current nix version: $current_nix_version"
if [[ "$current_nix_version" = "$upstream_version" ]]; then
echo "TradingView is already up-to-date"
exit 0
fi
#
# Find and replace.
#
echo "Updating from ${current_nix_version} to ${upstream_version}, released ${last_updated}"
sed --regexp-extended \
-e 's/revision\s*=\s*"[0-9]+"\s*;/revision = "'"${revision}"'";/' \
-e 's/hash\s*=\s*"[^"]*"\s*;/hash = "'"${sri}"'";/' \
-e 's/version\s*=\s*".*"\s*;/version = "'"${upstream_version}"'";/' \
-i "$tradingview_nix"
#
# Attempt a build.
#
export NIXPKGS_ALLOW_UNFREE=1
if ! nix-build -A tradingview "$nixpkgs"; then
echo "The updated TradingView failed to build."
exit 1
fi
#
# Commit changes.
#
git add "$tradingview_nix"
git commit -m "tradingview: ${current_nix_version} -> ${upstream_version}"