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