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