at v192 93 lines 3.4 kB view raw
1{ stdenv, fetchurl, libspotify, alsaLib, readline, pkgconfig, apiKey, unzip, gnused }: 2 3let 4 version = "12.1.51"; 5 isLinux = (stdenv.system == "x86_64-linux" || stdenv.system == "i686-linux"); 6in 7 8if (stdenv.system != "x86_64-linux" && stdenv.system != "x86_64-darwin" && stdenv.system != "i686-linux") 9then throw "Check https://developer.spotify.com/technologies/libspotify/ for a tarball for your system and add it here" 10else stdenv.mkDerivation { 11 name = "libspotify-${version}"; 12 13 src = 14 if stdenv.system == "x86_64-linux" then 15 fetchurl { 16 url = "https://developer.spotify.com/download/libspotify/libspotify-${version}-Linux-x86_64-release.tar.gz"; 17 sha256 = "0n0h94i4xg46hfba95n3ypah93crwb80bhgsg00f6sms683lx8a3"; 18 } 19 else if stdenv.system == "x86_64-darwin" then 20 fetchurl { 21 url = "https://developer.spotify.com/download/libspotify/libspotify-${version}-Darwin-universal.zip"; 22 sha256 = "1gcgrc8arim3hnszcc886lmcdb4iigc08abkaa02l6gng43ky1c0"; 23 } 24 else if stdenv.system == "i686-linux" then 25 fetchurl { 26 url = "https://developer.spotify.com/download/libspotify/libspotify-${version}-Linux-i686-release.tar.gz"; 27 sha256 = "1bjmn64gbr4p9irq426yap4ipq9rb84zsyhjjr7frmmw22xb86ll"; 28 } 29 else 30 null; 31 32 # common 33 buildPhase = "true"; 34 # no patch or build phase for darwin 35 phases = 36 [ "unpackPhase" ] ++ 37 (stdenv.lib.optionals (isLinux) [ "patchPhase" "buildPhase" ]) ++ 38 [ "installPhase" ]; 39 installPhase = if (isLinux) 40 then "installPhase" 41 else '' 42 mkdir -p "$out"/include/libspotify 43 mv -v libspotify.framework/Versions/Current/Headers/api.h \ 44 "$out"/include/libspotify 45 mkdir -p "$out"/lib 46 mv -v libspotify.framework/Versions/Current/libspotify \ 47 "$out"/lib/libspotify.dylib 48 mkdir -p "$out"/share/man 49 mv -v man3 "$out"/share/man 50 ''; 51 52 53 # darwin-specific 54 buildInputs = stdenv.lib.optional (stdenv.system == "x86_64-darwin") unzip; 55 56 # linux-specific 57 installFlags = stdenv.lib.optionalString (isLinux) 58 "prefix=$(out)"; 59 patchPhase = stdenv.lib.optionalString (isLinux) 60 "${gnused}/bin/sed -i 's/ldconfig//' Makefile"; 61 postInstall = stdenv.lib.optionalString (isLinux) 62 "mv -v share $out"; 63 64 passthru = { 65 samples = if apiKey == null 66 then throw '' 67 Please visit ${libspotify.meta.homepage} to get an api key then set config.libspotify.apiKey accordingly 68 '' else stdenv.mkDerivation { 69 name = "libspotify-samples-${version}"; 70 src = libspotify.src; 71 buildInputs = [ pkgconfig libspotify readline ] 72 ++ stdenv.lib.optional (!stdenv.isDarwin) alsaLib; 73 postUnpack = "sourceRoot=$sourceRoot/share/doc/libspotify/examples"; 74 patchPhase = "cp ${apiKey} appkey.c"; 75 installPhase = '' 76 mkdir -p $out/bin 77 install -m 755 jukebox/jukebox $out/bin 78 install -m 755 spshell/spshell $out/bin 79 install -m 755 localfiles/posix_stu $out/bin 80 ''; 81 meta = libspotify.meta // { description = "Spotify API library samples"; }; 82 }; 83 84 inherit apiKey; 85 }; 86 87 meta = with stdenv.lib; { 88 description = "Spotify API library"; 89 homepage = https://developer.spotify.com/technologies/libspotify; 90 maintainers = with maintainers; [ lovek323 ]; 91 license = licenses.unfree; 92 }; 93}