1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 fetchpatch2,
6 pkg-config,
7 python3Packages,
8 makeWrapper,
9 libsamplerate,
10 wafHook,
11 # Darwin Dependencies
12 aften,
13
14 # BSD Dependencies
15 freebsd,
16
17 # Optional Dependencies
18 dbus ? null,
19 libffado ? null,
20 alsa-lib ? null,
21
22 # Extra options
23 prefix ? "",
24
25 testers,
26}:
27
28let
29 inherit (python3Packages) python dbus-python;
30 shouldUsePkg =
31 pkg: if pkg != null && lib.meta.availableOn stdenv.hostPlatform pkg then pkg else null;
32
33 libOnly = prefix == "lib";
34
35 optDbus = if stdenv.hostPlatform.isDarwin then null else shouldUsePkg dbus;
36 optPythonDBus = if libOnly then null else shouldUsePkg dbus-python;
37 optLibffado = if libOnly then null else shouldUsePkg libffado;
38 optAlsaLib = if libOnly then null else shouldUsePkg alsa-lib;
39in
40stdenv.mkDerivation (finalAttrs: {
41 pname = "${prefix}jack2";
42 version = "1.9.22";
43
44 src = fetchFromGitHub {
45 owner = "jackaudio";
46 repo = "jack2";
47 rev = "v${finalAttrs.version}";
48 sha256 = "sha256-Cslfys5fcZDy0oee9/nM5Bd1+Cg4s/ayXjJJOSQCL4E=";
49 };
50
51 outputs = [
52 "out"
53 "dev"
54 ];
55
56 nativeBuildInputs = [
57 pkg-config
58 python
59 wafHook
60 ]
61 ++ lib.optionals (optDbus != null) [ makeWrapper ];
62 buildInputs = [
63 libsamplerate
64 optDbus
65 optPythonDBus
66 optLibffado
67 optAlsaLib
68 ]
69 ++ lib.optionals stdenv.hostPlatform.isDarwin [
70 aften
71 ]
72 ++ lib.optionals stdenv.hostPlatform.isFreeBSD [
73 freebsd.libsysinfo
74 ];
75
76 patches = [
77 (fetchpatch2 {
78 # Python 3.12 support
79 name = "jack2-waf2.0.26.patch";
80 url = "https://github.com/jackaudio/jack2/commit/250420381b1a6974798939ad7104ab1a4b9a9994.patch";
81 hash = "sha256-M/H72lLTeddefqth4BSkEfySZRYMIzLErb7nIgVN0u8=";
82 })
83 ];
84
85 postPatch = ''
86 patchShebangs --build svnversion_regenerate.sh
87 '';
88
89 wafConfigureFlags = [
90 "--classic"
91 "--autostart=${if (optDbus != null) then "dbus" else "classic"}"
92 ]
93 ++ lib.optional (optDbus != null) "--dbus"
94 ++ lib.optional (optLibffado != null) "--firewire"
95 ++ lib.optional (optAlsaLib != null) "--alsa"
96 ++ lib.optional (
97 stdenv.hostPlatform != stdenv.buildPlatform
98 ) "--platform=${stdenv.hostPlatform.parsed.kernel.name}";
99
100 postInstall = (
101 if libOnly then
102 ''
103 rm -rf $out/{bin,share}
104 rm -rf $out/lib/{jack,libjacknet*,libjackserver*}
105 ''
106 else
107 lib.optionalString (optDbus != null) ''
108 wrapProgram $out/bin/jack_control --set PYTHONPATH $PYTHONPATH
109 ''
110 );
111
112 postFixup = ''
113 substituteInPlace "$dev/lib/pkgconfig/jack.pc" \
114 --replace-fail "$out/include" "$dev/include"
115 '';
116
117 passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
118
119 meta = {
120 description = "JACK audio connection kit, version 2 with jackdbus";
121 homepage = "https://jackaudio.org";
122 license = lib.licenses.gpl2Plus;
123 pkgConfigModules = [ "jack" ];
124 platforms = lib.platforms.unix;
125 maintainers = [ ];
126 };
127})