diff options
author | ProminentRetail <me@jakepark.me> | 2023-10-12 18:18:31 +1100 |
---|---|---|
committer | ProminentRetail <me@jakepark.me> | 2023-10-12 18:18:31 +1100 |
commit | e0becb4aba2ee450f551b236509a22d762f68e9a (patch) | |
tree | 6b823c08f4acd9f257cdef0060a71383c958b29d /pkgs/by-name/tr | |
parent | 514b109a314498c66dad5c1982423f692253cdd2 (diff) |
tradingview: init at 2.6.1
Diffstat (limited to 'pkgs/by-name/tr')
-rw-r--r-- | pkgs/by-name/tr/tradingview/package.nix | 91 | ||||
-rw-r--r-- | pkgs/by-name/tr/tradingview/update.sh | 70 |
2 files changed, 161 insertions, 0 deletions
diff --git a/pkgs/by-name/tr/tradingview/package.nix b/pkgs/by-name/tr/tradingview/package.nix new file mode 100644 index 0000000000000..7268b43865682 --- /dev/null +++ b/pkgs/by-name/tr/tradingview/package.nix @@ -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"; + }; +} + diff --git a/pkgs/by-name/tr/tradingview/update.sh b/pkgs/by-name/tr/tradingview/update.sh new file mode 100644 index 0000000000000..863521bfde920 --- /dev/null +++ b/pkgs/by-name/tr/tradingview/update.sh @@ -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}" + |