1 #!/usr/bin/env nix-shell
2 #! nix-shell -i bash -p curl jq git gnused gnugrep
5 # executing this script without arguments will
6 # - find the newest stable spotify version avaiable on snapcraft (https://snapcraft.io/spotify)
7 # - read the current spotify version from the current nix expression
8 # - update the nix expression if the versions differ
9 # - try to build the updated version, exit if that fails
10 # - give instructions for upstreaming
12 # Please test the update manually before pushing. There have been errors before
13 # and because the service is proprietary and a paid account is necessary to do
14 # anything with spotify automatic testing is not possible.
16 # As an optional argument you can specify the snapcraft channel to update to.
17 # Default is `stable` and only stable updates should be pushed to nixpkgs. For
18 # testing you may specify `candidate` or `edge`.
21 channel
="${1:-stable}" # stable/candidate/edge
22 nixpkgs
="$(git rev-parse --show-toplevel)"
23 spotify_nix
="$nixpkgs/pkgs/applications/audio/spotify/linux.nix"
27 # find the newest stable spotify version avaiable on snapcraft
30 # create bash array from snap info
32 curl
-s -H 'X-Ubuntu-Series: 16' \
33 "https://api.snapcraft.io/api/v1/snaps/details/spotify?channel=$channel" \
35 '.revision,.download_sha512,.version,.last_updated'
38 # "revision" is the actual version identifier on snapcraft, the "version" is
39 # just for human consumption. Revision is just an integer that gets increased
40 # by one every (stable or unstable) release.
41 revision
="${snap_info[0]}"
42 # We need to escape the slashes
43 hash="$(nix-hash --to-sri --type sha512 ${snap_info[1]} | sed 's|/|\\/|g')"
44 upstream_version
="${snap_info[2]}"
45 last_updated
="${snap_info[3]}"
46 echo "Latest $channel release is $upstream_version from $last_updated."
48 # read the current spotify version from the currently *committed* nix expression
51 current_nix_version
=$
(
52 grep 'version\s*=' "$spotify_nix" \
53 |
sed -Ene 's/.*"(.*)".*/\1/p'
56 echo "Current nix version: $current_nix_version"
59 # update the nix expression if the versions differ
62 if [[ "$current_nix_version" = "$upstream_version" ]]; then
63 echo "Spotify is already up-to-date"
67 echo "Updating from ${current_nix_version} to ${upstream_version}, released on ${last_updated}"
69 # search-and-replace revision, hash and version
70 sed --regexp-extended \
71 -e 's/rev\s*=\s*"[0-9]+"\s*;/rev = "'"${revision}"'";/' \
72 -e 's/hash\s*=\s*"[^"]*"\s*;/hash = "'"${hash}"'";/' \
73 -e 's/version\s*=\s*".*"\s*;/version = "'"${upstream_version}"'";/' \
77 # try to build the updated version
80 export NIXPKGS_ALLOW_UNFREE
=1
81 if ! nix-build
-A spotify
"$nixpkgs"; then
82 echo "The updated spotify failed to build."
87 git add
"$spotify_nix"
88 git commit
-m "spotify: ${current_nix_version} -> ${upstream_version}"