From d416e6878c0cd46d2831b7a19398692978377ac7 Mon Sep 17 00:00:00 2001
From: OPNA2608 <christoph.neidahl@gmail.com>
Date: Mon, 16 Aug 2021 17:40:03 +0200
Subject: [PATCH 1/3] mpg123: Add audio support on Darwin

---
 pkgs/applications/audio/mpg123/default.nix | 11 +++++++----
 pkgs/top-level/all-packages.nix            |  4 +++-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/pkgs/applications/audio/mpg123/default.nix b/pkgs/applications/audio/mpg123/default.nix
index 44788467d8f6..09a588857e33 100644
--- a/pkgs/applications/audio/mpg123/default.nix
+++ b/pkgs/applications/audio/mpg123/default.nix
@@ -2,8 +2,10 @@
 , fetchurl
 , makeWrapper
 , alsa-lib
+, AudioUnit
+, AudioToolbox
 , perl
-, withConplay ? !stdenv.targetPlatform.isWindows
+, withConplay ? !stdenv.hostPlatform.isWindows
 }:
 
 stdenv.mkDerivation rec {
@@ -20,7 +22,8 @@ stdenv.mkDerivation rec {
   nativeBuildInputs = lib.optionals withConplay [ makeWrapper ];
 
   buildInputs = lib.optionals withConplay [ perl ]
-    ++ lib.optionals (!stdenv.isDarwin && !stdenv.targetPlatform.isWindows) [ alsa-lib ];
+    ++ lib.optionals (stdenv.hostPlatform.isLinux) [ alsa-lib ]
+    ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ AudioUnit AudioToolbox ];
 
   configureFlags = lib.optional
     (stdenv.hostPlatform ? mpg123)
@@ -43,8 +46,8 @@ stdenv.mkDerivation rec {
   meta = with lib; {
     description = "Fast console MPEG Audio Player and decoder library";
     homepage = "https://mpg123.org";
-    license = licenses.lgpl21;
-    maintainers = [ maintainers.ftrvxmtrx ];
+    license = licenses.lgpl21Only;
+    maintainers = with maintainers; [ ftrvxmtrx ];
     platforms = platforms.all;
   };
 }
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 8d6d2b4248ee..30bdd91c4387 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -26073,7 +26073,9 @@ with pkgs;
 
   mpc123 = callPackage ../applications/audio/mpc123 { };
 
-  mpg123 = callPackage ../applications/audio/mpg123 { };
+  mpg123 = callPackage ../applications/audio/mpg123 {
+    inherit (darwin.apple_sdk.frameworks) AudioUnit AudioToolbox;
+  };
 
   mpg321 = callPackage ../applications/audio/mpg321 { };
 

From 8f4c7af8aa7b47dabeb3cccd30bf1ff51f1127b7 Mon Sep 17 00:00:00 2001
From: OPNA2608 <christoph.neidahl@gmail.com>
Date: Mon, 16 Aug 2021 18:42:23 +0200
Subject: [PATCH 2/3] mpg123: Refactor

* Adds support for more audio APIs
* Explicitly requires APIs for sane order of preference
* Enables parallel building
---
 pkgs/applications/audio/mpg123/default.nix | 35 +++++++++++++++++-----
 pkgs/top-level/all-packages.nix            |  1 +
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/pkgs/applications/audio/mpg123/default.nix b/pkgs/applications/audio/mpg123/default.nix
index 09a588857e33..1023c9ab2b46 100644
--- a/pkgs/applications/audio/mpg123/default.nix
+++ b/pkgs/applications/audio/mpg123/default.nix
@@ -1,10 +1,18 @@
-{ lib, stdenv
+{ lib
+, stdenv
 , fetchurl
 , makeWrapper
+, pkg-config
+, perl
+, withAlsa ? stdenv.hostPlatform.isLinux
 , alsa-lib
+, withPulse ? stdenv.hostPlatform.isLinux
+, libpulseaudio
+, withCoreAudio ? stdenv.hostPlatform.isDarwin
 , AudioUnit
 , AudioToolbox
-, perl
+, withJack ? stdenv.hostPlatform.isUnix
+, jack
 , withConplay ? !stdenv.hostPlatform.isWindows
 }:
 
@@ -19,15 +27,26 @@ stdenv.mkDerivation rec {
 
   outputs = [ "out" ] ++ lib.optionals withConplay [ "conplay" ];
 
-  nativeBuildInputs = lib.optionals withConplay [ makeWrapper ];
+  nativeBuildInputs = lib.optionals withConplay [ makeWrapper ]
+    ++ lib.optionals (withPulse || withJack) [ pkg-config ];
 
   buildInputs = lib.optionals withConplay [ perl ]
-    ++ lib.optionals (stdenv.hostPlatform.isLinux) [ alsa-lib ]
-    ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ AudioUnit AudioToolbox ];
+    ++ lib.optionals withAlsa [ alsa-lib ]
+    ++ lib.optionals withPulse [ libpulseaudio ]
+    ++ lib.optionals withCoreAudio [ AudioUnit AudioToolbox ]
+    ++ lib.optionals withJack [ jack ];
 
-  configureFlags = lib.optional
-    (stdenv.hostPlatform ? mpg123)
-    "--with-cpu=${stdenv.hostPlatform.mpg123.cpu}";
+  configureFlags = [
+    "--with-audio=${lib.strings.concatStringsSep "," (
+      lib.optional withJack "jack"
+      ++ lib.optional withPulse "pulse"
+      ++ lib.optional withAlsa "alsa"
+      ++ lib.optional withCoreAudio "coreaudio"
+      ++ [ "dummy" ]
+    )}"
+  ] ++ lib.optional (stdenv.hostPlatform ? mpg123) "--with-cpu=${stdenv.hostPlatform.mpg123.cpu}";
+
+  enableParallelBuilding = true;
 
   postInstall = lib.optionalString withConplay ''
     mkdir -p $conplay/bin
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 30bdd91c4387..4b5af8d26f62 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -26075,6 +26075,7 @@ with pkgs;
 
   mpg123 = callPackage ../applications/audio/mpg123 {
     inherit (darwin.apple_sdk.frameworks) AudioUnit AudioToolbox;
+    jack = libjack2;
   };
 
   mpg321 = callPackage ../applications/audio/mpg321 { };

From beb28636469416bd5dffaf3e42ac84c6a8261307 Mon Sep 17 00:00:00 2001
From: OPNA2608 <christoph.neidahl@gmail.com>
Date: Mon, 16 Aug 2021 19:01:14 +0200
Subject: [PATCH 3/3] mpg123: 1.26.5 -> 1.28.2

---
 pkgs/applications/audio/mpg123/default.nix | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pkgs/applications/audio/mpg123/default.nix b/pkgs/applications/audio/mpg123/default.nix
index 1023c9ab2b46..6f55a82e13b8 100644
--- a/pkgs/applications/audio/mpg123/default.nix
+++ b/pkgs/applications/audio/mpg123/default.nix
@@ -18,11 +18,11 @@
 
 stdenv.mkDerivation rec {
   pname = "mpg123";
-  version = "1.26.5";
+  version = "1.28.2";
 
   src = fetchurl {
     url = "mirror://sourceforge/${pname}/${pname}-${version}.tar.bz2";
-    sha256 = "sha256-UCqX4Nk1vn432YczgCHY8wG641wohPKoPVnEtSRm7wY=";
+    sha256 = "006v44nz4nkpgvxz1k2vbbrfpa2m47hyydscs0wf3iysiyvd9vvy";
   };
 
   outputs = [ "out" ] ++ lib.optionals withConplay [ "conplay" ];