git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #44123 from timokau/spotify-snap

Fetch spotify from snapcraft

commitd4893a74e5bcc6570a670d92896779390bb06cda authorMichael Raskin <7c6f434c@mail.ru> dateSat 4 Aug 2018, 13:33 (8 years ago) parentb79dbfee875678
2 files changed+90−10
pkgs/applications/audio/spotify/default.nix+41−10 pkgs/applications/audio/spotify/update.sh+49
pkgs/applications/audio/spotify/default.nix+41−10
@@ -1,13 +1,18 @@
1−{ fetchurl, stdenv, dpkg, xorg, alsaLib, makeWrapper, openssl, freetype
1+{ fetchurl, stdenv, squashfsTools, xorg, alsaLib, makeWrapper, openssl, freetype
22, glib, pango, cairo, atk, gdk_pixbuf, gtk2, cups, nspr, nss, libpng
33, libgcrypt, systemd, fontconfig, dbus, expat, ffmpeg_0_10, curl, zlib, gnome3 }:
44
55let
6− # Please update the stable branch!
7− # Latest version number can be found at:
8− # http://repository-origin.spotify.com/pool/non-free/s/spotify-client/
9− # Be careful not to pick the testing version.
10− version = "1.0.80.480.g51b03ac3-13";
6+ # "rev" decides what is actually being downloaded
7+ version = "1.0.80.474.gef6b503e-7";
8+ # To get the latest stable revision:
9+ # curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/spotify?channel=stable' | jq '.download_url,.version,.last_updated'
10+ # To get general information:
11+ # curl -H 'Snap-Device-Series: 16' 'https://api.snapcraft.io/v2/snaps/info/spotify' | jq '.'
12+ # More exapmles of api usage:
13+ # https://github.com/canonical-websites/snapcraft.io/blob/master/webapp/publisher/snaps/views.py
14+ rev = "16";
15+
1116
1217 deps = [
1318 alsaLib
@@ -49,12 +54,20 @@ in
4954stdenv.mkDerivation {
5055 name = "spotify-${version}";
5156
57+ # fetch from snapcraft instead of the debian repository most repos fetch from.
58+ # That is a bit more cumbersome. But the debian repository only keeps the last
59+ # two versions, while snapcraft should provide versions indefinately:
60+ # https://forum.snapcraft.io/t/how-can-a-developer-remove-her-his-app-from-snap-store/512
61+
62+ # This is the next-best thing, since we're not allowed to re-distribute
63+ # spotify ourselves:
64+ # https://community.spotify.com/t5/Desktop-Linux/Redistribute-Spotify-on-Linux-Distributions/td-p/1695334
5265 src = fetchurl {
53− url = "https://repository-origin.spotify.com/pool/non-free/s/spotify-client/spotify-client_${version}_amd64.deb";
54− sha256 = "e32f4816ae79dbfa0c14086e76df3bc83d526402aac1dbba534127fc00fe50ea";
66+ url = "https://api.snapcraft.io/api/v1/snaps/download/pOBIoZ2LrCB3rDohMxoYGnbN14EHOgD7_${rev}.snap";
67+ sha512 = "45b7ab574b30fb368e0b6f4dd60addbfd1ddc02173b4f98b31c524eed49073432352a361e75959ce8e2f752231e93c79ca1b538c4bd295c935d1e2e0585d147f";
5568 };
5669
57− buildInputs = [ dpkg makeWrapper ];
70+ buildInputs = [ squashfsTools makeWrapper ];
5871
5972 doConfigure = false;
6073 doBuild = false;
@@ -63,7 +76,23 @@ stdenv.mkDerivation {
6376
6477 unpackPhase = ''
6578 runHook preUnpack
66− dpkg-deb -x $src .
79+ unsquashfs "$src" '/usr/share/spotify' '/usr/bin/spotify' '/meta/snap.yaml'
80+ cd squashfs-root
81+ if ! grep -q 'grade: stable' meta/snap.yaml; then
82+ # Unfortunately this check is not reliable: At the moment (2018-07-26) the
83+ # latest version in the "edge" channel is also marked as stable.
84+ echo "The snap package is marked as unstable:"
85+ grep 'grade: ' meta/snap.yaml
86+ echo "You probably chose the wrong revision."
87+ exit 1
88+ fi
89+ if ! grep -q '${version}' meta/snap.yaml; then
90+ echo "Package version differs from version found in snap metadata:"
91+ grep 'version: ' meta/snap.yaml
92+ echo "While the nix package specifies: ${version}."
93+ echo "You probably chose the wrong revision or forgot to update the nix version."
94+ exit 1
95+ fi
6796 runHook postUnpack
6897 '';
6998
@@ -75,6 +104,8 @@ stdenv.mkDerivation {
75104 mkdir -p $libdir
76105 mv ./usr/* $out/
77106
107+ cp meta/snap.yaml $out
108+
78109 # Work around Spotify referring to a specific minor version of
79110 # OpenSSL.
80111
pkgs/applications/audio/spotify/update.shnew file+49
@@ -0,0 +1,49 @@
1+channel="stable" # stable/candidate/edge
2+nixpkgs="$(git rev-parse --show-toplevel)"
3+spotify_nix="$nixpkgs/pkgs/applications/audio/spotify/default.nix"
4+
5+
6+
7+# create bash array from snap info
8+snap_info=($(
9+ curl -H 'X-Ubuntu-Series: 16' \
10+ "https://api.snapcraft.io/api/v1/snaps/details/spotify?channel=$channel" \
11+ | jq --raw-output \
12+ '.revision,.download_sha512,.version,.last_updated'
13+))
14+
15+revision="${snap_info[0]}"
16+sha512="${snap_info[1]}"
17+version="${snap_info[2]}"
18+last_updated="${snap_info[3]}"
19+
20+# find the last commited version
21+version_pre=$(
22+ git grep 'version\s*=' HEAD "$spotify_nix" \
23+ | sed -Ene 's/.*"(.*)".*/\1/p'
24+)
25+
26+if [[ "$version_pre" = "$version" ]]; then
27+ echo "Spotify is already up ot date"
28+ exit 0
29+fi
30+
31+echo "Updating from ${version_pre} to ${version}, released on ${last_updated}"
32+
33+# search-andreplace revision, hash and version
34+sed --regexp-extended \
35+ -e 's/rev\s*=\s*"[0-9]+"\s*;/rev = "'"${revision}"'";/' \
36+ -e 's/sha512\s*=\s*".{128}"\s*;/sha512 = "'"${sha512}"'";/' \
37+ -e 's/version\s*=\s*".*"\s*;/version = "'"${version}"'";/' \
38+ -i "$spotify_nix"
39+
40+if ! nix-build -A spotify "$nixpkgs"; then
41+ echo "The updated spotify failed to build."
42+ exit 1
43+fi
44+
45+git add "$spotify_nix"
46+# show diff for review
47+git diff HEAD
48+# prepare commit message, but allow edit
49+git commit --edit --message "spotify: $version_pre -> $version"