spotify: set updateScript, support macOS in updateScript and update (#409788)

This commit is contained in:
lassulus 2025-05-26 17:09:48 +02:00 committed by GitHub
commit a720d7224e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 123 additions and 85 deletions

View file

@ -4,24 +4,25 @@
meta, meta,
fetchurl, fetchurl,
undmg, undmg,
updateScript,
lib, lib,
}: }:
stdenv.mkDerivation { stdenv.mkDerivation {
inherit pname; inherit pname;
version = "1.2.40.599.g606b7f29"; version = "1.2.64.408";
src = src =
if stdenv.hostPlatform.isAarch64 then if stdenv.hostPlatform.isAarch64 then
(fetchurl { (fetchurl {
url = "https://web.archive.org/web/20240622065234/https://download.scdn.co/SpotifyARM64.dmg"; url = "https://web.archive.org/web/20250522123639/https://download.scdn.co/SpotifyARM64.dmg";
hash = "sha256-mmjxKYmsX0rFlIU19JOfPbNgOhlcZs5slLUhDhlON1c="; hash = "sha256-28T+AxhnM1K6W50JUu9RdFRKsBRDTQulKK2+kk2RTMQ=";
}) })
else else
(fetchurl { (fetchurl {
url = "https://web.archive.org/web/20240622065548/https://download.scdn.co/Spotify.dmg"; url = "https://web.archive.org/web/20250522130546/https://download.scdn.co/Spotify.dmg";
hash = "sha256-hvS0xnmJQoQfNJRFsLBQk8AJjDOzDy+OGwNOq5Ms/O0="; hash = "sha256-P8itkT2w7xQl0WfMLcNHgi1zcoYMqOdGmNDXdwhZBUs=";
}); });
nativeBuildInputs = [ undmg ]; nativeBuildInputs = [ undmg ];
@ -37,7 +38,12 @@ stdenv.mkDerivation {
runHook postInstall runHook postInstall
''; '';
passthru = { inherit updateScript; };
meta = meta // { meta = meta // {
maintainers = with lib.maintainers; [ matteopacini ]; maintainers = with lib.maintainers; [
matteopacini
Enzime
];
}; };
} }

View file

@ -44,23 +44,10 @@
# High-DPI support: Spotify's --force-device-scale-factor argument # High-DPI support: Spotify's --force-device-scale-factor argument
# not added if `null`, otherwise, should be a number. # not added if `null`, otherwise, should be a number.
deviceScaleFactor ? null, deviceScaleFactor ? null,
updateScript,
}: }:
let let
# TO UPDATE: just execute the ./update.sh script (won't do anything if there is no update)
# "rev" decides what is actually being downloaded
# If an update breaks things, one of those might have valuable info:
# https://aur.archlinux.org/packages/spotify/
# https://community.spotify.com/t5/Desktop-Linux
version = "1.2.59.514.g834e17d4";
# To get the latest stable revision:
# curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/spotify?channel=stable' | jq '.download_url,.version,.last_updated'
# To get general information:
# curl -H 'Snap-Device-Series: 16' 'https://api.snapcraft.io/v2/snaps/info/spotify' | jq '.'
# More examples of api usage:
# https://github.com/canonical-websites/snapcraft.io/blob/master/webapp/publisher/snaps/views.py
rev = "86";
deps = [ deps = [
alsa-lib alsa-lib
at-spi2-atk at-spi2-atk
@ -109,11 +96,24 @@ let
xorg.libXtst xorg.libXtst
zlib zlib
]; ];
in in
stdenv.mkDerivation (finalAttrs: {
inherit pname;
stdenv.mkDerivation { # TO UPDATE: just execute the ./update.sh script (won't do anything if there is no update)
inherit pname version; # "rev" decides what is actually being downloaded
# If an update breaks things, one of those might have valuable info:
# https://aur.archlinux.org/packages/spotify/
# https://community.spotify.com/t5/Desktop-Linux
version = "1.2.60.564.gcc6305cb";
# To get the latest stable revision:
# curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/spotify?channel=stable' | jq '.download_url,.version,.last_updated'
# To get general information:
# curl -H 'Snap-Device-Series: 16' 'https://api.snapcraft.io/v2/snaps/info/spotify' | jq '.'
# More examples of api usage:
# https://github.com/canonical-websites/snapcraft.io/blob/master/webapp/publisher/snaps/views.py
rev = "87";
# fetch from snapcraft instead of the debian repository most repos fetch from. # fetch from snapcraft instead of the debian repository most repos fetch from.
# That is a bit more cumbersome. But the debian repository only keeps the last # That is a bit more cumbersome. But the debian repository only keeps the last
@ -124,9 +124,9 @@ stdenv.mkDerivation {
# spotify ourselves: # spotify ourselves:
# https://community.spotify.com/t5/Desktop-Linux/Redistribute-Spotify-on-Linux-Distributions/td-p/1695334 # https://community.spotify.com/t5/Desktop-Linux/Redistribute-Spotify-on-Linux-Distributions/td-p/1695334
src = fetchurl { src = fetchurl {
name = "spotify-${version}-${rev}.snap"; name = "spotify-${finalAttrs.version}-${finalAttrs.rev}.snap";
url = "https://api.snapcraft.io/api/v1/snaps/download/pOBIoZ2LrCB3rDohMxoYGnbN14EHOgD7_${rev}.snap"; url = "https://api.snapcraft.io/api/v1/snaps/download/pOBIoZ2LrCB3rDohMxoYGnbN14EHOgD7_${finalAttrs.rev}.snap";
hash = "sha512-b9VlPwZ6JJ7Kt2p0ji1qtTJQHZE9d4KBO3iqQwsYh6k+ljtV/mSdinZi+B//Yb+KXhMErd0oaVzIpCCMqft6FQ=="; hash = "sha512-hdJOko/0EHkPiNgWO+WB3nP+0MO9D2fxgM/X/Ri6fM1ODJxz3XYY84Xf2Ru6iGqdA9XUNRcd/qi+Gfaj9Ez0Ug==";
}; };
nativeBuildInputs = [ nativeBuildInputs = [
@ -150,10 +150,10 @@ stdenv.mkDerivation {
echo "You probably chose the wrong revision." echo "You probably chose the wrong revision."
exit 1 exit 1
fi fi
if ! grep -q '${version}' meta/snap.yaml; then if ! grep -q '${finalAttrs.version}' meta/snap.yaml; then
echo "Package version differs from version found in snap metadata:" echo "Package version differs from version found in snap metadata:"
grep 'version: ' meta/snap.yaml grep 'version: ' meta/snap.yaml
echo "While the nix package specifies: ${version}." echo "While the nix package specifies: ${finalAttrs.version}."
echo "You probably chose the wrong revision or forgot to update the nix version." echo "You probably chose the wrong revision or forgot to update the nix version."
exit 1 exit 1
fi fi
@ -227,6 +227,8 @@ stdenv.mkDerivation {
runHook postFixup runHook postFixup
''; '';
passthru = { inherit updateScript; };
meta = meta // { meta = meta // {
maintainers = with lib.maintainers; [ maintainers = with lib.maintainers; [
ftrvxmtrx ftrvxmtrx
@ -235,4 +237,4 @@ stdenv.mkDerivation {
ma27 ma27
]; ];
}; };
} })

View file

@ -10,6 +10,8 @@ let
pname = "spotify"; pname = "spotify";
updateScript = ./update.sh;
meta = with lib; { meta = with lib; {
homepage = "https://www.spotify.com/"; homepage = "https://www.spotify.com/";
description = "Play music from the Spotify music service"; description = "Play music from the Spotify music service";
@ -25,6 +27,6 @@ let
in in
if stdenv.hostPlatform.isDarwin then if stdenv.hostPlatform.isDarwin then
callPackage ./darwin.nix (extraArgs // { inherit pname meta; }) callPackage ./darwin.nix (extraArgs // { inherit pname updateScript meta; })
else else
callPackage ./linux.nix (extraArgs // { inherit pname meta; }) callPackage ./linux.nix (extraArgs // { inherit pname updateScript meta; })

View file

@ -1,5 +1,6 @@
#!/usr/bin/env nix-shell #!/usr/bin/env nix-shell
#! nix-shell -i bash -p curl jq git gnused gnugrep #! nix-shell -i bash -p common-updater-scripts curl jq git gnused gnugrep libplist undmg
set -euo pipefail
# executing this script without arguments will # executing this script without arguments will
@ -20,69 +21,96 @@
channel="${1:-stable}" # stable/candidate/edge channel="${1:-stable}" # stable/candidate/edge
nixpkgs="$(git rev-parse --show-toplevel)" nixpkgs="$(git rev-parse --show-toplevel)"
spotify_nix="$nixpkgs/pkgs/by-name/sp/spotify/linux.nix"
update_linux() {
nix_file="$nixpkgs/pkgs/by-name/sp/spotify/linux.nix"
#
# find the newest stable spotify version available on snapcraft
#
# # create bash array from snap info
# find the newest stable spotify version avaiable on snapcraft snap_info=($(
# curl -s -H 'X-Ubuntu-Series: 16' \
"https://api.snapcraft.io/api/v1/snaps/details/spotify?channel=$channel" \
| jq --raw-output \
'.revision,.download_sha512,.version,.last_updated'
))
# create bash array from snap info # "revision" is the actual version identifier on snapcraft, the "version" is
snap_info=($( # just for human consumption. Revision is just an integer that gets increased
curl -s -H 'X-Ubuntu-Series: 16' \ # by one every (stable or unstable) release.
"https://api.snapcraft.io/api/v1/snaps/details/spotify?channel=$channel" \ revision="${snap_info[0]}"
| jq --raw-output \ # We need to escape the slashes
'.revision,.download_sha512,.version,.last_updated' hash="$(nix-hash --to-sri --type sha512 ${snap_info[1]} | sed 's|/|\\/|g')"
)) upstream_version="${snap_info[2]}"
last_updated="${snap_info[3]}"
echo "Latest $channel release for Spotify on Linux is $upstream_version from $last_updated."
#
# read the current spotify version from the currently *committed* nix expression
#
# "revision" is the actual version identifier on snapcraft, the "version" is current_nix_version=$(
# just for human consumption. Revision is just an integer that gets increased grep 'version\s*=' "$nix_file" \
# by one every (stable or unstable) release. | sed -Ene 's/.*"(.*)".*/\1/p'
revision="${snap_info[0]}" )
# We need to escape the slashes
hash="$(nix-hash --to-sri --type sha512 ${snap_info[1]} | sed 's|/|\\/|g')"
upstream_version="${snap_info[2]}"
last_updated="${snap_info[3]}"
echo "Latest $channel release is $upstream_version from $last_updated."
#
# read the current spotify version from the currently *committed* nix expression
#
current_nix_version=$( echo "Current Spotify for Linux version in Nixpkgs: $current_nix_version"
grep 'version\s*=' "$spotify_nix" \
| sed -Ene 's/.*"(.*)".*/\1/p'
)
echo "Current nix version: $current_nix_version" #
# update the nix expression if the versions differ
#
# if [[ "$current_nix_version" = "$upstream_version" ]]; then
# update the nix expression if the versions differ echo "Spotify on Linux is already up-to-date"
# return
fi
if [[ "$current_nix_version" = "$upstream_version" ]]; then echo "Updating Spotify on Linux from ${current_nix_version} to ${upstream_version}, released on ${last_updated}"
echo "Spotify is already up-to-date"
exit 0
fi
echo "Updating from ${current_nix_version} to ${upstream_version}, released on ${last_updated}" # search-and-replace revision, hash and version
sed --regexp-extended \
-e 's/rev\s*=\s*"[0-9]+"\s*;/rev = "'"${revision}"'";/' \
-e 's/hash\s*=\s*"[^"]*"\s*;/hash = "'"${hash}"'";/' \
-e 's/version\s*=\s*".*"\s*;/version = "'"${upstream_version}"'";/' \
-i "$nix_file"
}
# search-and-replace revision, hash and version update_macos() {
sed --regexp-extended \ nix_file="$nixpkgs/pkgs/by-name/sp/spotify/darwin.nix"
-e 's/rev\s*=\s*"[0-9]+"\s*;/rev = "'"${revision}"'";/' \
-e 's/hash\s*=\s*"[^"]*"\s*;/hash = "'"${hash}"'";/' \
-e 's/version\s*=\s*".*"\s*;/version = "'"${upstream_version}"'";/' \
-i "$spotify_nix"
# tmp_dir=$(mktemp -d)
# try to build the updated version trap 'rm -rf "$tmp_dir"' EXIT
#
export NIXPKGS_ALLOW_UNFREE=1 pushd $tmp_dir
if ! nix-build -A spotify "$nixpkgs"; then
echo "The updated spotify failed to build."
exit 1
fi
# Commit changes x86_64_url="https://download.scdn.co/Spotify.dmg"
git add "$spotify_nix" aarch64_url="https://download.scdn.co/SpotifyARM64.dmg"
git commit -m "spotify: ${current_nix_version} -> ${upstream_version}"
curl -OL $aarch64_url
undmg SpotifyARM64.dmg
upstream_version=$(plistutil -i Spotify.app/Contents/Info.plist -f json -o - | jq -r '.CFBundleVersion')
popd
current_nix_version=$(
grep 'version\s*=' "$nix_file" \
| sed -Ene 's/.*"(.*)".*/\1/p'
)
if [[ "$current_nix_version" != "$upstream_version" ]]; then
archive_url="https://web.archive.org/save"
archived_x86_64_url=$(curl -s -I -L -o /dev/null "$archive_url/$x86_64_url" -w '%{url_effective}')
archived_aarch64_url=$(curl -s -I -L -o /dev/null "$archive_url/$aarch64_url" -w '%{url_effective}')
update-source-version "pkgsCross.x86_64-darwin.spotify" "$upstream_version" "" "$archived_x86_64_url" \
--file=$nix_file \
--ignore-same-version
update-source-version "pkgsCross.aarch64-darwin.spotify" "$upstream_version" "" "$archived_aarch64_url" \
--file=$nix_file \
--ignore-same-version
fi
}
update_linux
update_macos