<commit_before>{ stdenv, fetchurl, libspotify, alsaLib, readline, pkgconfig, apiKey }:

let version = "12.1.51"; in

if stdenv.system != "x86_64-linux" then throw ''
  Check https://developer.spotify.com/technologies/libspotify/ for a tarball for your system and add it here
'' else stdenv.mkDerivation {
  name = "libspotify-${version}";

  src = fetchurl {
    url = "https://developer.spotify.com/download/libspotify/libspotify-${version}-Linux-x86_64-release.tar.gz";

    sha256 = "0n0h94i4xg46hfba95n3ypah93crwb80bhgsg00f6sms683lx8a3";
  };

  buildPhase = "true";

  installFlags = "prefix=$(out)";

  postInstall = "mv -v share $out";

  patchPhase = "sed -i 's/ldconfig//' Makefile";

  passthru = {
    samples = if apiKey == null
      then throw ''
        Please visit ${libspotify.meta.homepage} to get an api key then set config.libspotify.apiKey accordingly
      '' else stdenv.mkDerivation {
        name = "libspotify-samples-${version}";

        src = libspotify.src;

        buildInputs = [ pkgconfig libspotify alsaLib readline ];

        postUnpack = "sourceRoot=$sourceRoot/share/doc/libspotify/examples";

        patchPhase = "cp ${apiKey} appkey.c";

        installPhase = ''
          mkdir -p $out/bin
          install -m 755 jukebox/jukebox $out/bin
          install -m 755 spshell/spshell $out/bin
          install -m 755 localfiles/posix_stu $out/bin
        '';

        meta = libspotify.meta // { description = "Spotify API library samples"; };
      };

    inherit apiKey;
  };

  meta = {
    description = "Spotify API library";

    homepage = https://developer.spotify.com/technologies/libspotify;

    maintainers = [ stdenv.lib.maintainers.shlevy ];

    license = stdenv.lib.licenses.unfree;<commit_msg>libspotify: add darwin library<commit_after>{ stdenv, fetchurl, libspotify, alsaLib, readline, pkgconfig, apiKey, unzip }:

let version = "12.1.51"; in

if (stdenv.system == "x86_64-linux" && stdenv.system != "x86_64-darwin")
then throw "Check https://developer.spotify.com/technologies/libspotify/ for a tarball for your system and add it here"
else stdenv.mkDerivation {
  name = "libspotify-${version}";

  src =
    if stdenv.system == "x86_64-linux" then
      fetchurl {
        url    = "https://developer.spotify.com/download/libspotify/libspotify-${version}-Linux-x86_64-release.tar.gz";
        sha256 = "0n0h94i4xg46hfba95n3ypah93crwb80bhgsg00f6sms683lx8a3";
      }
    else if stdenv.system == "x86_64-darwin" then
      fetchurl {
        url    = "https://developer.spotify.com/download/libspotify/libspotify-${version}-Darwin-universal.zip";
        sha256 = "1gcgrc8arim3hnszcc886lmcdb4iigc08abkaa02l6gng43ky1c0";
      }
    else
      null;

  # common
  buildPhase = "true";
  # no patch or build phase for darwin
  phases = [ "unpackPhase" "installPhase" ]
    ++ stdenv.lib.optionals (stdenv.system == "x86_64-linux")
      [ "patchPhase" "buildPhase" ];
  installPhase = if (stdenv.system == "x86_64-linux")
    then "installPhase"
    else ''
      mkdir -p "$out"/include/libspotify
      mv -v libspotify.framework/Versions/Current/Headers/api.h \
        "$out"/include/libspotify
      mkdir -p "$out"/lib
      mv -v libspotify.framework/Versions/Current/libspotify \
        "$out"/lib/libspotify.dylib
      mkdir -p "$out"/share/man
      mv -v man3 "$out"/share/man
    '';
 

  # darwin-specific
  buildInputs = stdenv.lib.optional (stdenv.system == "x86_64-darwin") unzip;

  # linux-specific
  installFlags = stdenv.lib.optionalString (stdenv.system == "x86_64-linux")
    "prefix=$(out)";
  patchPhase = stdenv.lib.optionalString (stdenv.system == "x86_64-linux")
    "sed -i 's/ldconfig//' Makefile";
  postInstall = stdenv.lib.optionalString (stdenv.system == "x86_64-linux")
    "mv -v share $out";

  passthru = {
    samples = if apiKey == null
      then throw ''
        Please visit ${libspotify.meta.homepage} to get an api key then set config.libspotify.apiKey accordingly
      '' else stdenv.mkDerivation {
        name = "libspotify-samples-${version}";
        src = libspotify.src;
        buildInputs = [ pkgconfig libspotify readline ]
          ++ stdenv.lib.optional (!stdenv.isDarwin) alsaLib;
        postUnpack = "sourceRoot=$sourceRoot/share/doc/libspotify/examples";
        patchPhase = "cp ${apiKey} appkey.c";
        installPhase = ''
          mkdir -p $out/bin
          install -m 755 jukebox/jukebox $out/bin
          install -m 755 spshell/spshell $out/bin
          install -m 755 localfiles/posix_stu $out/bin
        '';
        meta = libspotify.meta // { description = "Spotify API library samples"; };
      };

    inherit apiKey;
  };

  meta = with stdenv.lib; {
    description = "Spotify API library";
    homepage    = https://developer.spotify.com/technologies/libspotify;
    maintainers = with maintainers; [ lovek323 shlevy ];
    license     = licenses.unfree;
{'fraction_non_alphanumeric': 0.12831497348021215, 'fraction_numerical': 0.031211750305997554, 'mean_word_length': 2.8820269200316706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7480671', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1686, 'n_words': 344}