nixos/uptime-kuma: Add additional lockdown settings to systemd unit (#361452)
[NixPkgs.git] / pkgs / by-name / bl / bluez / package.nix
blob4337cd90b5193ff56971ad3efcf87e599804b8c6
1 { lib
2 , stdenv
3 , alsa-lib
4 , dbus
5 , docutils
6 , ell
7 , enableExperimental ? false
8 , fetchpatch
9 , fetchurl
10 , glib
11 , json_c
12 , libical
13 , pkg-config
14 , python3Packages
15 , readline
16 , systemdMinimal
17 , udev
18 # Test gobject-introspection instead of pygobject because the latter
19 # causes an infinite recursion.
20 , gobject-introspection
21 , buildPackages
22 , installTests ? lib.meta.availableOn stdenv.hostPlatform gobject-introspection && stdenv.hostPlatform.emulatorAvailable buildPackages
25 stdenv.mkDerivation (finalAttrs: {
26   pname = "bluez";
27   version = "5.78";
29   src = fetchurl {
30     url = "mirror://kernel/linux/bluetooth/bluez-${finalAttrs.version}.tar.xz";
31     hash = "sha256-gw/tGRXF03W43g9eb0X83qDcxf9f+z0x227Q8A1zxeM=";
32   };
34   patches = [
35     # Upstream fix is wrong:
36     # https://github.com/bluez/bluez/issues/843#issuecomment-2352696535
37     (fetchurl {
38       name = "basename.patch";
39       url = "https://github.com/void-linux/void-packages/raw/187b45d47d93b6857a95cae10c2132d76e4955fc/srcpkgs/bluez/patches/basename.patch";
40       hash = "sha256-Jb4u7rxIShDp1yUgaQVDJo2HJfZBzRoVlcDEWxooFgk=";
41     })
42   ] ++ lib.optional (stdenv.hostPlatform.isMusl && stdenv.hostPlatform.isx86_64)
43     # Disable one failing test with musl libc, also seen by alpine
44     # https://github.com/bluez/bluez/issues/726
45     (fetchurl {
46       url = "https://git.alpinelinux.org/aports/plain/main/bluez/disable_aics_unit_testcases.patch?id=8e96f7faf01a45f0ad8449c1cd825db63a8dfd48";
47       hash = "sha256-1PJkipqBO3qxxOqRFQKfpWlne1kzTCgtnTFYI1cFQt4=";
48     });
50   buildInputs = [
51     alsa-lib
52     dbus
53     ell
54     glib
55     json_c
56     libical
57     python3Packages.python
58     readline
59     udev
60   ];
62   nativeBuildInputs = [
63     docutils
64     pkg-config
65     python3Packages.pygments
66     python3Packages.wrapPython
67   ];
69   outputs = [ "out" "dev" ]
70     ++ lib.optional installTests "test";
72   postPatch = ''
73     substituteInPlace tools/hid2hci.rules \
74       --replace-fail /sbin/udevadm ${systemdMinimal}/bin/udevadm \
75       --replace-fail "hid2hci " "$out/lib/udev/hid2hci "
76   '' +
77   # Disable some tests:
78   # - test-mesh-crypto depends on the following kernel settings:
79   #   CONFIG_CRYPTO_[USER|USER_API|USER_API_AEAD|USER_API_HASH|AES|CCM|AEAD|CMAC]
80   ''
81     if [[ ! -f unit/test-mesh-crypto.c ]]; then
82       echo "unit/test-mesh-crypto.c no longer exists"
83       false
84     fi
85     echo 'int main() { return 77; }' > unit/test-mesh-crypto.c
86   '';
88   configureFlags = [
89     "--localstatedir=/var"
90     (lib.enableFeature enableExperimental "experimental")
91     (lib.enableFeature true "btpclient")
92     (lib.enableFeature true "cups")
93     (lib.enableFeature true "external-ell")
94     (lib.enableFeature true "health")
95     (lib.enableFeature true "hid2hci")
96     (lib.enableFeature true "library")
97     (lib.enableFeature true "logger")
98     (lib.enableFeature true "mesh")
99     (lib.enableFeature true "midi")
100     (lib.enableFeature true "nfc")
101     (lib.enableFeature true "pie")
102     (lib.enableFeature true "sixaxis")
103     # Set "deprecated" to provide ciptool, sdptool, and rfcomm (unmaintained);
104     # superseded by new D-Bus APIs
105     (lib.enableFeature true "deprecated")
106     (lib.withFeatureAs true "dbusconfdir" "${placeholder "out"}/share")
107     (lib.withFeatureAs true "dbussessionbusdir" "${placeholder "out"}/share/dbus-1/services")
108     (lib.withFeatureAs true "dbussystembusdir" "${placeholder "out"}/share/dbus-1/system-services")
109     (lib.withFeatureAs true "systemdsystemunitdir" "${placeholder "out"}/etc/systemd/system")
110     (lib.withFeatureAs true "systemduserunitdir" "${placeholder "out"}/etc/systemd/user")
111     (lib.withFeatureAs true "udevdir" "${placeholder "out"}/lib/udev")
112   ];
114   makeFlags = [
115     "rulesdir=${placeholder "out"}/lib/udev/rules.d"
116   ];
118   # Work around `make install' trying to create /var/lib/bluetooth.
119   installFlags = [
120     "statedir=$(TMPDIR)/var/lib/bluetooth"
121   ];
123   doCheck = stdenv.hostPlatform.isx86_64;
125   postInstall = let
126     pythonPath = with python3Packages; [
127       dbus-python
128       pygobject3
129     ];
130   in
131   ''
132     # for bluez4 compatibility for NixOS
133     mkdir $out/sbin
134     ln -s ../libexec/bluetooth/bluetoothd $out/sbin/bluetoothd
135     ln -s ../libexec/bluetooth/obexd $out/sbin/obexd
137     # Add extra configuration
138     rm $out/etc/bluetooth/{main,input,network}.conf
139     ln -s /etc/bluetooth/main.conf $out/etc/bluetooth/main.conf
141     # https://github.com/NixOS/nixpkgs/issues/204418
142     ln -s /etc/bluetooth/input.conf $out/etc/bluetooth/input.conf
143     ln -s /etc/bluetooth/network.conf $out/etc/bluetooth/network.conf
145     # Add missing tools, ref https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/bluez
146     for files in $(find tools/ -type f -perm -755); do
147       filename=$(basename $files)
148       install -Dm755 tools/$filename $out/bin/$filename
149     done
150     install -Dm755 attrib/gatttool $out/bin/gatttool
151   '' + lib.optionalString installTests ''
152     mkdir -p $test/{bin,test}
153     cp -a test $test
154     pushd $test/test
155     for t in \
156             list-devices \
157             monitor-bluetooth \
158             simple-agent \
159             test-adapter \
160             test-device \
161             test-thermometer \
162             ; do
163       ln -s ../test/$t $test/bin/bluez-$t
164     done
165     popd
166     wrapPythonProgramsIn $test/test "$test/test ${toString pythonPath}"
167   '';
169   enableParallelBuilding = true;
171   meta = {
172     homepage = "https://www.bluez.org/";
173     description = "Official Linux Bluetooth protocol stack";
174     changelog = "https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/ChangeLog?h=${finalAttrs.version}";
175     license = with lib.licenses; [ bsd2 gpl2Plus lgpl21Plus mit ];
176     mainProgram = "btinfo";
177     maintainers = with lib.maintainers; [ ];
178     platforms = lib.platforms.linux;
179   };