diff --git a/pkgs/servers/pulseaudio/0001-Make-gio-2.0-optional-when-gsettings-is-disabled.patch b/pkgs/servers/pulseaudio/0001-Make-gio-2.0-optional-when-gsettings-is-disabled.patch new file mode 100644 index 000000000000..c087dcd7e7d1 --- /dev/null +++ b/pkgs/servers/pulseaudio/0001-Make-gio-2.0-optional-when-gsettings-is-disabled.patch @@ -0,0 +1,26 @@ +From 72f3fe059f031f24c5ad026cb2fc16318f227c09 Mon Sep 17 00:00:00 2001 +From: Andrew Childs +Date: Tue, 19 Apr 2022 16:29:58 +0900 +Subject: [PATCH 1/8] Make gio-2.0 optional when gsettings is disabled + +Derived from https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/654 +--- + meson.build | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/meson.build b/meson.build +index d7e468cab..f7adf1413 100644 +--- a/meson.build ++++ b/meson.build +@@ -614,7 +614,7 @@ if dbus_dep.found() + cdata.set('HAVE_DBUS', 1) + endif + +-gio_dep = dependency('gio-2.0', version : '>= 2.26.0') ++gio_dep = dependency('gio-2.0', version : '>= 2.26.0', required : false) + if get_option('gsettings').enabled() + assert(gio_dep.found(), 'GSettings support needs glib I/O library (GIO)') + cdata.set('HAVE_GSETTINGS', 1) +-- +2.35.1 + diff --git a/pkgs/servers/pulseaudio/0002-Ignore-SCM_CREDS-on-macOS.patch b/pkgs/servers/pulseaudio/0002-Ignore-SCM_CREDS-on-macOS.patch new file mode 100644 index 000000000000..9196e205dc0c --- /dev/null +++ b/pkgs/servers/pulseaudio/0002-Ignore-SCM_CREDS-on-macOS.patch @@ -0,0 +1,27 @@ +From 39bef695f783614e6175477417298ddf37e2ac13 Mon Sep 17 00:00:00 2001 +From: Andrew Childs +Date: Tue, 19 Apr 2022 16:58:43 +0900 +Subject: [PATCH 2/8] Ignore SCM_CREDS on macOS + +It was added for FreeBSD support, but also enables the +unsupported[citation needed] feature on macOS. +--- + src/pulsecore/creds.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/pulsecore/creds.h b/src/pulsecore/creds.h +index b599b569c..b5b1c9f37 100644 +--- a/src/pulsecore/creds.h ++++ b/src/pulsecore/creds.h +@@ -34,7 +34,7 @@ + typedef struct pa_creds pa_creds; + typedef struct pa_cmsg_ancil_data pa_cmsg_ancil_data; + +-#if defined(SCM_CREDENTIALS) || defined(SCM_CREDS) ++#if defined(SCM_CREDENTIALS) || (defined(SCM_CREDS) && !defined(__APPLE__)) + + #define HAVE_CREDS 1 + +-- +2.35.1 + diff --git a/pkgs/servers/pulseaudio/0003-Disable-z-nodelete-on-darwin.patch b/pkgs/servers/pulseaudio/0003-Disable-z-nodelete-on-darwin.patch new file mode 100644 index 000000000000..81b3ab927333 --- /dev/null +++ b/pkgs/servers/pulseaudio/0003-Disable-z-nodelete-on-darwin.patch @@ -0,0 +1,26 @@ +From 3f1abb55f4eb985fd0715b2b2ca45dcce3a56824 Mon Sep 17 00:00:00 2001 +From: Andrew Childs +Date: Tue, 19 Apr 2022 17:06:50 +0900 +Subject: [PATCH 3/8] Disable `-z nodelete` on darwin + +Not supported[citation needed]. +--- + meson.build | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/meson.build b/meson.build +index f7adf1413..d4bece11a 100644 +--- a/meson.build ++++ b/meson.build +@@ -404,7 +404,7 @@ cdata.set('MESON_BUILD', 1) + # so we request the nodelete flag to be enabled. + # On other systems, we don't really know how to do that, but it's welcome if somebody can tell. + # Windows doesn't support this flag. +-if host_machine.system() != 'windows' ++if host_machine.system() != 'windows' and host_machine.system() != 'darwin' + nodelete_link_args = ['-Wl,-z,nodelete'] + else + nodelete_link_args = [] +-- +2.35.1 + diff --git a/pkgs/servers/pulseaudio/0004-Prefer-clock_gettime.patch b/pkgs/servers/pulseaudio/0004-Prefer-clock_gettime.patch new file mode 100644 index 000000000000..eb7bd1c62708 --- /dev/null +++ b/pkgs/servers/pulseaudio/0004-Prefer-clock_gettime.patch @@ -0,0 +1,57 @@ +From 0bd3b613ac3bf16a73b3223fa1b961da3a0db1b2 Mon Sep 17 00:00:00 2001 +From: Andrew Childs +Date: Tue, 19 Apr 2022 17:12:52 +0900 +Subject: [PATCH 4/8] Prefer clock_gettime + +Available in darwin since 10.12 (released in 2016). +--- + src/pulsecore/core-rtclock.c | 26 +++++++++++++------------- + 1 file changed, 13 insertions(+), 13 deletions(-) + +diff --git a/src/pulsecore/core-rtclock.c b/src/pulsecore/core-rtclock.c +index 2c2e28631..a08d4b391 100644 +--- a/src/pulsecore/core-rtclock.c ++++ b/src/pulsecore/core-rtclock.c +@@ -65,19 +65,7 @@ pa_usec_t pa_rtclock_age(const struct timeval *tv) { + + struct timeval *pa_rtclock_get(struct timeval *tv) { + +-#if defined(OS_IS_DARWIN) +- uint64_t val, abs_time = mach_absolute_time(); +- Nanoseconds nanos; +- +- nanos = AbsoluteToNanoseconds(*(AbsoluteTime *) &abs_time); +- val = *(uint64_t *) &nanos; +- +- tv->tv_sec = val / PA_NSEC_PER_SEC; +- tv->tv_usec = (val % PA_NSEC_PER_SEC) / PA_NSEC_PER_USEC; +- +- return tv; +- +-#elif defined(HAVE_CLOCK_GETTIME) ++#if defined(HAVE_CLOCK_GETTIME) + struct timespec ts; + + #ifdef CLOCK_MONOTONIC +@@ -109,6 +97,18 @@ struct timeval *pa_rtclock_get(struct timeval *tv) { + + return tv; + } ++#elif defined(OS_IS_DARWIN) ++ uint64_t val, abs_time = mach_absolute_time(); ++ Nanoseconds nanos; ++ ++ nanos = AbsoluteToNanoseconds(*(AbsoluteTime *) &abs_time); ++ val = *(uint64_t *) &nanos; ++ ++ tv->tv_sec = val / PA_NSEC_PER_SEC; ++ tv->tv_usec = (val % PA_NSEC_PER_SEC) / PA_NSEC_PER_USEC; ++ ++ return tv; ++ + #endif /* HAVE_CLOCK_GETTIME */ + + return pa_gettimeofday(tv); +-- +2.35.1 + diff --git a/pkgs/servers/pulseaudio/0005-Include-poll-posix.c-on-darwin.patch b/pkgs/servers/pulseaudio/0005-Include-poll-posix.c-on-darwin.patch new file mode 100644 index 000000000000..4779fce2afd6 --- /dev/null +++ b/pkgs/servers/pulseaudio/0005-Include-poll-posix.c-on-darwin.patch @@ -0,0 +1,24 @@ +From 8dee473920d3a331b73a415b37e7e0b01f014110 Mon Sep 17 00:00:00 2001 +From: Andrew Childs +Date: Tue, 19 Apr 2022 17:22:23 +0900 +Subject: [PATCH 5/8] Include poll-posix.c on darwin + +--- + src/meson.build | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/meson.build b/src/meson.build +index e2860811b..5bd68cb12 100644 +--- a/src/meson.build ++++ b/src/meson.build +@@ -182,6 +182,7 @@ if host_machine.system() == 'windows' + else + libpulsecommon_sources += [ + 'pulsecore/mutex-posix.c', ++ 'pulsecore/poll-posix.c', + 'pulsecore/semaphore-posix.c', + 'pulsecore/thread-posix.c' + ] +-- +2.35.1 + diff --git a/pkgs/servers/pulseaudio/0006-Only-use-version-script-on-GNU-ish-linkers.patch b/pkgs/servers/pulseaudio/0006-Only-use-version-script-on-GNU-ish-linkers.patch new file mode 100644 index 000000000000..8b27b3e5ab77 --- /dev/null +++ b/pkgs/servers/pulseaudio/0006-Only-use-version-script-on-GNU-ish-linkers.patch @@ -0,0 +1,29 @@ +From 419258112b9d90d149ebbd5c657a36d8532b78a2 Mon Sep 17 00:00:00 2001 +From: Andrew Childs +Date: Tue, 19 Apr 2022 17:31:36 +0900 +Subject: [PATCH 6/8] Only use version-script on GNU-ish linkers + +--- + src/pulse/meson.build | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/src/pulse/meson.build b/src/pulse/meson.build +index c2128e087..a5e47867e 100644 +--- a/src/pulse/meson.build ++++ b/src/pulse/meson.build +@@ -74,7 +74,11 @@ run_target('update-map-file', + command : [ join_paths(meson.source_root(), 'scripts/generate-map-file.sh'), 'map-file', + [ libpulse_headers, 'simple.h', join_paths(meson.build_root(), 'src', 'pulse', 'version.h') ] ]) + +-versioning_link_args = '-Wl,-version-script=' + join_paths(meson.source_root(), 'src', 'pulse', 'map-file') ++if meson.get_compiler('c').get_linker_id().startswith('ld.') ++ versioning_link_args = '-Wl,-version-script=' + join_paths(meson.source_root(), 'src', 'pulse', 'map-file') ++else ++ versioning_link_args = [] ++endif + + libpulse = shared_library('pulse', + libpulse_sources, +-- +2.35.1 + diff --git a/pkgs/servers/pulseaudio/0007-Adapt-undefined-link-args-per-linker.patch b/pkgs/servers/pulseaudio/0007-Adapt-undefined-link-args-per-linker.patch new file mode 100644 index 000000000000..6893df8a7e29 --- /dev/null +++ b/pkgs/servers/pulseaudio/0007-Adapt-undefined-link-args-per-linker.patch @@ -0,0 +1,44 @@ +From 6f132be835d5acb5db4301ea1818601504e47fae Mon Sep 17 00:00:00 2001 +From: Andrew Childs +Date: Tue, 19 Apr 2022 17:41:34 +0900 +Subject: [PATCH 7/8] Adapt undefined link args per linker + +TODO: Why is this required? Isn't it default? +--- + src/modules/meson.build | 13 ++++++++++++- + 1 file changed, 12 insertions(+), 1 deletion(-) + +diff --git a/src/modules/meson.build b/src/modules/meson.build +index be72c3b9b..0163b583f 100644 +--- a/src/modules/meson.build ++++ b/src/modules/meson.build +@@ -293,6 +293,17 @@ all_modules += [ + # FIXME: meson doesn't support multiple RPATH arguments currently + rpath_dirs = join_paths(privlibdir) + ':' + join_paths(modlibexecdir) + ++if meson.get_compiler('c').get_linker_id().startswith('ld.') ++ no_undefined_link_args = [ '-Wl,--no-undefined' ] ++elif meson.get_compiler('c').get_linker_id() == 'ld64' ++ # TODO: is this required? is this not default? ++ no_undefined_link_args = [ '-Wl,-undefined,error' ] ++else ++ # TODO: what platforms is this? what flag do they use? ++ no_undefined_link_args = [] ++endif ++ ++ + foreach m : all_modules + name = m[0] + sources = m[1] +@@ -310,7 +321,7 @@ foreach m : all_modules + install_rpath : rpath_dirs, + install_dir : modlibexecdir, + dependencies : [thread_dep, libpulse_dep, libpulsecommon_dep, libpulsecore_dep, libintl_dep, platform_dep, platform_socket_dep] + extra_deps, +- link_args : [nodelete_link_args, '-Wl,--no-undefined' ], ++ link_args : [nodelete_link_args, no_undefined_link_args ], + link_with : extra_libs, + name_prefix : '', + implicit_include_directories : false) +-- +2.35.1 + diff --git a/pkgs/servers/pulseaudio/0008-Use-correct-semaphore-on-darwin.patch b/pkgs/servers/pulseaudio/0008-Use-correct-semaphore-on-darwin.patch new file mode 100644 index 000000000000..274534665628 --- /dev/null +++ b/pkgs/servers/pulseaudio/0008-Use-correct-semaphore-on-darwin.patch @@ -0,0 +1,31 @@ +From 1a840b6e517004c902dfbea3d358b344c9588978 Mon Sep 17 00:00:00 2001 +From: Andrew Childs +Date: Tue, 19 Apr 2022 17:49:08 +0900 +Subject: [PATCH 8/8] Use correct semaphore on darwin + +--- + src/meson.build | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/src/meson.build b/src/meson.build +index 5bd68cb12..041e2fab4 100644 +--- a/src/meson.build ++++ b/src/meson.build +@@ -183,9 +183,13 @@ else + libpulsecommon_sources += [ + 'pulsecore/mutex-posix.c', + 'pulsecore/poll-posix.c', +- 'pulsecore/semaphore-posix.c', + 'pulsecore/thread-posix.c' + ] ++ if host_machine.system() == 'darwin' ++ libpulsecommon_sources += [ 'pulsecore/semaphore-osx.c' ] ++ else ++ libpulsecommon_sources += [ 'pulsecore/semaphore-posix.c' ] ++ endif + endif + # FIXME: Do SIMD things + +-- +2.35.1 + diff --git a/pkgs/servers/pulseaudio/default.nix b/pkgs/servers/pulseaudio/default.nix index 9e3075f09b76..deca94fca822 100644 --- a/pkgs/servers/pulseaudio/default.nix +++ b/pkgs/servers/pulseaudio/default.nix @@ -5,7 +5,7 @@ , sbc, bluez5, udev, openssl, fftwFloat , soxr, speexdsp, systemd, webrtc-audio-processing , gst_all_1 -, check, meson, ninja, m4, wrapGAppsHook +, check, libintl, meson, ninja, m4, wrapGAppsHook , x11Support ? false @@ -45,6 +45,18 @@ stdenv.mkDerivation rec { # Install sysconfdir files inside of the nix store, # but use a conventional runtime sysconfdir outside the store ./add-option-for-installation-sysconfdir.patch + ] ++ lib.optionals stdenv.isDarwin [ + # https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/654 + ./0001-Make-gio-2.0-optional-when-gsettings-is-disabled.patch + + # TODO (not sent upstream) + ./0002-Ignore-SCM_CREDS-on-macOS.patch + ./0003-Disable-z-nodelete-on-darwin.patch + ./0004-Prefer-clock_gettime.patch + ./0005-Include-poll-posix.c-on-darwin.patch + ./0006-Only-use-version-script-on-GNU-ish-linkers.patch + ./0007-Adapt-undefined-link-args-per-linker.patch + ./0008-Use-correct-semaphore-on-darwin.patch ]; outputs = [ "out" "dev" ]; @@ -60,7 +72,7 @@ stdenv.mkDerivation rec { buildInputs = [ libtool libsndfile soxr speexdsp fftwFloat check ] ++ lib.optionals stdenv.isLinux [ glib dbus ] - ++ lib.optionals stdenv.isDarwin [ AudioUnit Cocoa CoreServices ] + ++ lib.optionals stdenv.isDarwin [ AudioUnit Cocoa CoreServices libintl ] ++ lib.optionals (!libOnly) ( [ libasyncns webrtc-audio-processing ] ++ lib.optional jackaudioSupport libjack2 @@ -86,7 +98,7 @@ stdenv.mkDerivation rec { "-Ddoxygen=false" "-Delogind=disabled" # gsettings does not support cross-compilation - "-Dgsettings=${if stdenv.buildPlatform == stdenv.hostPlatform then "enabled" else "disabled"}" + "-Dgsettings=${if stdenv.isLinux && (stdenv.buildPlatform == stdenv.hostPlatform) then "enabled" else "disabled"}" "-Dgstreamer=disabled" "-Dgtk=disabled" "-Djack=${if jackaudioSupport && !libOnly then "enabled" else "disabled"}" @@ -105,10 +117,15 @@ stdenv.mkDerivation rec { "-Dsysconfdir_install=${placeholder "out"}/etc" "-Dudevrulesdir=${placeholder "out"}/lib/udev/rules.d" ] - ++ lib.optional (stdenv.isLinux && useSystemd) "-Dsystemduserunitdir=${placeholder "out"}/lib/systemd/user" - ; + ++ lib.optional (stdenv.isLinux && useSystemd) "-Dsystemduserunitdir=${placeholder "out"}/lib/systemd/user" + ++ lib.optionals (stdenv.isDarwin) [ + "-Ddbus=disabled" + "-Dglib=disabled" + "-Doss-output=disabled" + ]; - doCheck = true; + # tests fail on Darwin because of timeouts + doCheck = !stdenv.isDarwin; preCheck = '' export HOME=$(mktemp -d) '';