1{ stdenv
2, lib
3, fetchurl
4, alsa-lib
5, dbus
6, ell
7, glib
8, json_c
9, libical
10, docutils
11, pkg-config
12, python3
13, readline
14, systemdMinimal
15, udev
16, withExperimental ? false
17}: let
18 pythonPath = with python3.pkgs; [
19 dbus-python
20 pygobject3
21 recursivePthLoader
22 ];
23in stdenv.mkDerivation rec {
24 pname = "bluez";
25 version = "5.65";
26
27 src = fetchurl {
28 url = "mirror://kernel/linux/bluetooth/${pname}-${version}.tar.xz";
29 sha256 = "sha256-JWWk1INUtXbmrZLiW1TtZoCCllgciruAWHBR+Zk9ltQ=";
30 };
31
32 buildInputs = [
33 alsa-lib
34 dbus
35 ell
36 glib
37 json_c
38 libical
39 python3
40 readline
41 udev
42 ];
43
44 nativeBuildInputs = [
45 docutils
46 pkg-config
47 python3.pkgs.wrapPython
48 ];
49
50 outputs = [ "out" "dev" "test" ];
51
52 postPatch = ''
53 substituteInPlace tools/hid2hci.rules \
54 --replace /sbin/udevadm ${systemdMinimal}/bin/udevadm \
55 --replace "hid2hci " "$out/lib/udev/hid2hci "
56 # Disable some tests:
57 # - test-mesh-crypto depends on the following kernel settings:
58 # CONFIG_CRYPTO_[USER|USER_API|USER_API_AEAD|USER_API_HASH|AES|CCM|AEAD|CMAC]
59 if [[ ! -f unit/test-mesh-crypto.c ]]; then echo "unit/test-mesh-crypto.c no longer exists"; false; fi
60 echo 'int main() { return 77; }' > unit/test-mesh-crypto.c
61 '';
62
63 configureFlags = [
64 "--localstatedir=/var"
65 "--enable-library"
66 "--enable-cups"
67 "--enable-pie"
68 "--enable-external-ell"
69 "--with-dbusconfdir=${placeholder "out"}/share"
70 "--with-dbussystembusdir=${placeholder "out"}/share/dbus-1/system-services"
71 "--with-dbussessionbusdir=${placeholder "out"}/share/dbus-1/services"
72 "--with-systemdsystemunitdir=${placeholder "out"}/etc/systemd/system"
73 "--with-systemduserunitdir=${placeholder "out"}/etc/systemd/user"
74 "--with-udevdir=${placeholder "out"}/lib/udev"
75 "--enable-health"
76 "--enable-mesh"
77 "--enable-midi"
78 "--enable-nfc"
79 "--enable-sap"
80 "--enable-sixaxis"
81 "--enable-btpclient"
82 "--enable-hid2hci"
83 "--enable-logger"
84
85 # To provide ciptool, sdptool, and rfcomm (unmaintained)
86 # superseded by new D-Bus APIs
87 "--enable-deprecated"
88 ] ++ lib.optional withExperimental "--enable-experimental";
89
90
91 # Work around `make install' trying to create /var/lib/bluetooth.
92 installFlags = [ "statedir=$(TMPDIR)/var/lib/bluetooth" ];
93
94 makeFlags = [ "rulesdir=${placeholder "out"}/lib/udev/rules.d" ];
95
96 doCheck = stdenv.hostPlatform.isx86_64;
97
98 postInstall = ''
99 mkdir -p $test/{bin,test}
100 cp -a test $test
101 pushd $test/test
102 for a in \
103 simple-agent \
104 test-adapter \
105 test-device \
106 test-thermometer \
107 list-devices \
108 monitor-bluetooth \
109 ; do
110 ln -s ../test/$a $test/bin/bluez-$a
111 done
112 popd
113 wrapPythonProgramsIn $test/test "$test/test ${toString pythonPath}"
114 '' + ''
115 # for bluez4 compatibility for NixOS
116 mkdir $out/sbin
117 ln -s ../libexec/bluetooth/bluetoothd $out/sbin/bluetoothd
118 ln -s ../libexec/bluetooth/obexd $out/sbin/obexd
119
120 # Add extra configuration
121 mkdir $out/etc/bluetooth
122 ln -s /etc/bluetooth/main.conf $out/etc/bluetooth/main.conf
123
124 # Add missing tools, ref https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/bluez
125 for files in `find tools/ -type f -perm -755`; do
126 filename=$(basename $files)
127 install -Dm755 tools/$filename $out/bin/$filename
128 done
129 install -Dm755 attrib/gatttool $out/bin/gatttool
130 '';
131
132 enableParallelBuilding = true;
133
134 meta = with lib; {
135 description = "Bluetooth support for Linux";
136 homepage = "http://www.bluez.org/";
137 license = with licenses; [ gpl2 lgpl21 ];
138 platforms = platforms.linux;
139 };
140}