default.nix 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. {
  2. fetchurl,
  3. lib,
  4. stdenv,
  5. squashfsTools,
  6. xorg,
  7. alsa-lib,
  8. makeShellWrapper,
  9. wrapGAppsHook,
  10. openssl,
  11. freetype,
  12. glib,
  13. pango,
  14. cairo,
  15. atk,
  16. gdk-pixbuf,
  17. gtk3,
  18. harfbuzz,
  19. cups,
  20. nspr,
  21. nss_latest,
  22. libpng,
  23. libnotify,
  24. libgcrypt,
  25. systemd,
  26. fontconfig,
  27. dbus,
  28. expat,
  29. ffmpeg_4,
  30. curlWithGnuTls,
  31. zlib,
  32. gnome,
  33. at-spi2-atk,
  34. at-spi2-core,
  35. libpulseaudio,
  36. libdrm,
  37. mesa,
  38. libxkbcommon,
  39. # High-DPI support: Spotify's --force-device-scale-factor argument
  40. # not added if `null`, otherwise, should be a number.
  41. deviceScaleFactor ? null,
  42. }: let
  43. # TO UPDATE: just execute the ./update.sh script (won't do anything if there is no update)
  44. # "rev" decides what is actually being downloaded
  45. # If an update breaks things, one of those might have valuable info:
  46. # https://aur.archlinux.org/packages/spotify/
  47. # https://community.spotify.com/t5/Desktop-Linux
  48. version = "1.2.13.661.ga588f749";
  49. # To get the latest stable revision:
  50. # curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/spotify?channel=stable' | jq '.download_url,.version,.last_updated'
  51. # To get general information:
  52. # curl -H 'Snap-Device-Series: 16' 'https://api.snapcraft.io/v2/snaps/info/spotify' | jq '.'
  53. # More examples of api usage:
  54. # https://github.com/canonical-websites/snapcraft.io/blob/master/webapp/publisher/snaps/views.py
  55. rev = "68";
  56. deps = [
  57. alsa-lib
  58. at-spi2-atk
  59. at-spi2-core
  60. atk
  61. cairo
  62. cups
  63. curlWithGnuTls
  64. dbus
  65. expat
  66. ffmpeg_4
  67. fontconfig
  68. freetype
  69. gdk-pixbuf
  70. glib
  71. gtk3
  72. harfbuzz
  73. libdrm
  74. libgcrypt
  75. libnotify
  76. libpng
  77. libpulseaudio
  78. libxkbcommon
  79. mesa
  80. nss_latest
  81. pango
  82. stdenv.cc.cc
  83. systemd
  84. xorg.libICE
  85. xorg.libSM
  86. xorg.libX11
  87. xorg.libxcb
  88. xorg.libXcomposite
  89. xorg.libXcursor
  90. xorg.libXdamage
  91. xorg.libXext
  92. xorg.libXfixes
  93. xorg.libXi
  94. xorg.libXrandr
  95. xorg.libXrender
  96. xorg.libXScrnSaver
  97. xorg.libxshmfence
  98. xorg.libXtst
  99. zlib
  100. ];
  101. in
  102. stdenv.mkDerivation {
  103. pname = "spotify";
  104. inherit version;
  105. # fetch from snapcraft instead of the debian repository most repos fetch from.
  106. # That is a bit more cumbersome. But the debian repository only keeps the last
  107. # two versions, while snapcraft should provide versions indefinitely:
  108. # https://forum.snapcraft.io/t/how-can-a-developer-remove-her-his-app-from-snap-store/512
  109. # This is the next-best thing, since we're not allowed to re-distribute
  110. # spotify ourselves:
  111. # https://community.spotify.com/t5/Desktop-Linux/Redistribute-Spotify-on-Linux-Distributions/td-p/1695334
  112. src = fetchurl {
  113. url = "https://api.snapcraft.io/api/v1/snaps/download/pOBIoZ2LrCB3rDohMxoYGnbN14EHOgD7_${rev}.snap";
  114. hash = "sha256-UbA0HHLCnENO3e3c+wOeuJ9F9d19S5MAQ6zEg2hitwk=";
  115. };
  116. nativeBuildInputs = [wrapGAppsHook makeShellWrapper squashfsTools];
  117. dontStrip = true;
  118. dontPatchELF = true;
  119. unpackPhase = ''
  120. runHook preUnpack
  121. unsquashfs "$src" '/usr/share/spotify' '/usr/bin/spotify' '/meta/snap.yaml'
  122. cd squashfs-root
  123. if ! grep -q 'grade: stable' meta/snap.yaml; then
  124. # Unfortunately this check is not reliable: At the moment (2018-07-26) the
  125. # latest version in the "edge" channel is also marked as stable.
  126. echo "The snap package is marked as unstable:"
  127. grep 'grade: ' meta/snap.yaml
  128. echo "You probably chose the wrong revision."
  129. exit 1
  130. fi
  131. if ! grep -q '${version}' meta/snap.yaml; then
  132. echo "Package version differs from version found in snap metadata:"
  133. grep 'version: ' meta/snap.yaml
  134. echo "While the nix package specifies: ${version}."
  135. echo "You probably chose the wrong revision or forgot to update the nix version."
  136. exit 1
  137. fi
  138. runHook postUnpack
  139. '';
  140. # Prevent double wrapping
  141. dontWrapGApps = true;
  142. installPhase = ''
  143. runHook preInstall
  144. libdir=$out/lib/spotify
  145. mkdir -p $libdir
  146. mv ./usr/* $out/
  147. cp meta/snap.yaml $out
  148. # Work around Spotify referring to a specific minor version of
  149. # OpenSSL.
  150. ln -s ${lib.getLib openssl}/lib/libssl.so $libdir/libssl.so.1.0.0
  151. ln -s ${lib.getLib openssl}/lib/libcrypto.so $libdir/libcrypto.so.1.0.0
  152. ln -s ${nspr.out}/lib/libnspr4.so $libdir/libnspr4.so
  153. ln -s ${nspr.out}/lib/libplc4.so $libdir/libplc4.so
  154. ln -s ${ffmpeg_4.lib}/lib/libavcodec.so* $libdir
  155. ln -s ${ffmpeg_4.lib}/lib/libavformat.so* $libdir
  156. rpath="$out/share/spotify:$libdir"
  157. patchelf \
  158. --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
  159. --set-rpath $rpath $out/share/spotify/spotify
  160. librarypath="${lib.makeLibraryPath deps}:$libdir"
  161. wrapProgramShell $out/share/spotify/spotify \
  162. ''${gappsWrapperArgs[@]} \
  163. ${lib.optionalString (deviceScaleFactor != null) ''
  164. --add-flags "--force-device-scale-factor=${toString deviceScaleFactor}" \
  165. ''} \
  166. --prefix LD_LIBRARY_PATH : "$librarypath" \
  167. --prefix PATH : "${gnome.zenity}/bin" \
  168. --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--enable-features=UseOzonePlatform --ozone-platform=wayland}}"
  169. # fix Icon line in the desktop file (#48062)
  170. sed -i "s:^Icon=.*:Icon=spotify-client:" "$out/share/spotify/spotify.desktop"
  171. # Desktop file
  172. mkdir -p "$out/share/applications/"
  173. cp "$out/share/spotify/spotify.desktop" "$out/share/applications/"
  174. # Icons
  175. for i in 16 22 24 32 48 64 128 256 512; do
  176. ixi="$i"x"$i"
  177. mkdir -p "$out/share/icons/hicolor/$ixi/apps"
  178. ln -s "$out/share/spotify/icons/spotify-linux-$i.png" \
  179. "$out/share/icons/hicolor/$ixi/apps/spotify-client.png"
  180. done
  181. runHook postInstall
  182. '';
  183. meta = with lib; {
  184. homepage = "https://www.spotify.com/";
  185. description = "Play music from the Spotify music service";
  186. sourceProvenance = with sourceTypes; [binaryNativeCode];
  187. # license = licenses.unfree;
  188. maintainers = with maintainers; [eelco ftrvxmtrx sheenobu mudri timokau ma27];
  189. platforms = ["x86_64-linux"];
  190. };
  191. }