1{
2 lib,
3 rustPlatform,
4 fetchFromGitHub,
5 makeWrapper,
6 pkg-config,
7 stdenv,
8 openssl,
9 withALSA ? stdenv.hostPlatform.isLinux,
10 alsa-lib,
11 alsa-plugins,
12 withPortAudio ? false,
13 portaudio,
14 withPulseAudio ? false,
15 libpulseaudio,
16 withRodio ? true,
17 withAvahi ? false,
18 withMDNS ? true,
19 withDNS-SD ? false,
20 avahi-compat,
21}:
22
23rustPlatform.buildRustPackage rec {
24 pname = "librespot";
25 version = "0.6.0";
26
27 src = fetchFromGitHub {
28 owner = "librespot-org";
29 repo = "librespot";
30 rev = "v${version}";
31 sha256 = "sha256-dGQDRb7fgIkXelZKa+PdodIs9DxbgEMlVGJjK/hU3Mo=";
32 };
33
34 cargoHash = "sha256-SqvJSHkyd1IicT6c4pE96dBJNNodULhpyG14HRGVWCk=";
35
36 nativeBuildInputs = [
37 pkg-config
38 makeWrapper
39 ]
40 ++ lib.optionals stdenv.hostPlatform.isDarwin [
41 rustPlatform.bindgenHook
42 ];
43
44 buildInputs = [
45 openssl
46 ]
47 ++ lib.optional withALSA alsa-lib
48 ++ lib.optional withDNS-SD avahi-compat
49 ++ lib.optional withPortAudio portaudio
50 ++ lib.optional withPulseAudio libpulseaudio;
51
52 buildNoDefaultFeatures = true;
53 buildFeatures =
54 lib.optional withRodio "rodio-backend"
55 ++ lib.optional withMDNS "with-libmdns"
56 ++ lib.optional withDNS-SD "with-dns-sd"
57 ++ lib.optional withALSA "alsa-backend"
58 ++ lib.optional withAvahi "with-avahi"
59 ++ lib.optional withPortAudio "portaudio-backend"
60 ++ lib.optional withPulseAudio "pulseaudio-backend";
61
62 postFixup = lib.optionalString withALSA ''
63 wrapProgram "$out/bin/librespot" \
64 --set ALSA_PLUGIN_DIR '${alsa-plugins}/lib/alsa-lib'
65 '';
66
67 meta = {
68 description = "Open Source Spotify client library and playback daemon";
69 mainProgram = "librespot";
70 homepage = "https://github.com/librespot-org/librespot";
71 changelog = "https://github.com/librespot-org/librespot/blob/v${version}/CHANGELOG.md";
72 license = with lib.licenses; [ mit ];
73 maintainers = with lib.maintainers; [ bennofs ];
74 };
75}