nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 203 lines 5.8 kB view raw
1{ 2 lib, 3 stdenv, 4 alsa-lib, 5 autoreconfHook, 6 dbus, 7 docutils, 8 ell, 9 enableExperimental ? false, 10 fetchurl, 11 glib, 12 json_c, 13 libical, 14 pkg-config, 15 python3Packages, 16 readline, 17 udev, 18 # Test gobject-introspection instead of pygobject because the latter 19 # causes an infinite recursion. 20 gobject-introspection, 21 buildPackages, 22 installTests ? 23 lib.meta.availableOn stdenv.hostPlatform gobject-introspection 24 && stdenv.hostPlatform.emulatorAvailable buildPackages, 25 gitUpdater, 26 udevCheckHook, 27}: 28 29stdenv.mkDerivation (finalAttrs: { 30 pname = "bluez"; 31 version = "5.83"; 32 33 src = fetchurl { 34 url = "mirror://kernel/linux/bluetooth/bluez-${finalAttrs.version}.tar.xz"; 35 hash = "sha256-EIUi2QnSIFgTmb/sk9qrYgNVOc7vPdo+eZcHhcY70kw="; 36 }; 37 38 patches = [ 39 (fetchurl { 40 name = "static.patch"; 41 url = "https://lore.kernel.org/linux-bluetooth/20250703182908.2370130-1-hi@alyssa.is/raw"; 42 hash = "sha256-4Yz3ljsn2emJf+uTcJO4hG/YXvjERtitce71TZx5Hak="; 43 }) 44 ]; 45 46 buildInputs = [ 47 alsa-lib 48 dbus 49 ell 50 glib 51 json_c 52 libical 53 python3Packages.python 54 readline 55 udev 56 ]; 57 58 nativeBuildInputs = [ 59 autoreconfHook 60 docutils 61 pkg-config 62 python3Packages.pygments 63 python3Packages.wrapPython 64 udevCheckHook 65 ]; 66 67 outputs = [ 68 "out" 69 "dev" 70 ] 71 ++ lib.optional installTests "test"; 72 73 postPatch = '' 74 substituteInPlace tools/hid2hci.rules \ 75 --replace-fail /sbin/udevadm ${udev}/bin/udevadm \ 76 --replace-fail "hid2hci " "$out/lib/udev/hid2hci " 77 '' 78 + 79 # Disable some tests: 80 # - test-mesh-crypto depends on the following kernel settings: 81 # CONFIG_CRYPTO_[USER|USER_API|USER_API_AEAD|USER_API_HASH|AES|CCM|AEAD|CMAC] 82 # - test-vcp is flaky (?), see: 83 # - https://github.com/bluez/bluez/issues/683 84 # - https://github.com/bluez/bluez/issues/726 85 '' 86 skipTest() { 87 if [[ ! -f unit/$1.c ]]; then 88 echo "unit/$1.c no longer exists" 89 false 90 fi 91 92 echo 'int main() { return 77; }' > unit/$1.c 93 } 94 95 skipTest test-mesh-crypto 96 skipTest test-vcp 97 ''; 98 99 configureFlags = [ 100 "--localstatedir=/var" 101 (lib.enableFeature enableExperimental "experimental") 102 (lib.enableFeature true "btpclient") 103 (lib.enableFeature true "cups") 104 (lib.enableFeature true "external-ell") 105 (lib.enableFeature true "health") 106 (lib.enableFeature true "hid2hci") 107 (lib.enableFeature true "library") 108 (lib.enableFeature true "logger") 109 (lib.enableFeature true "mesh") 110 (lib.enableFeature true "midi") 111 (lib.enableFeature true "nfc") 112 (lib.enableFeature true "pie") 113 (lib.enableFeature true "sixaxis") 114 (lib.enableFeature (lib.elem "libsystemd" udev.meta.pkgConfigModules) "systemd") 115 # Set "deprecated" to provide ciptool, sdptool, and rfcomm (unmaintained); 116 # superseded by new D-Bus APIs 117 (lib.enableFeature true "deprecated") 118 (lib.withFeatureAs true "dbusconfdir" "${placeholder "out"}/share") 119 (lib.withFeatureAs true "dbussessionbusdir" "${placeholder "out"}/share/dbus-1/services") 120 (lib.withFeatureAs true "dbussystembusdir" "${placeholder "out"}/share/dbus-1/system-services") 121 (lib.withFeatureAs true "systemdsystemunitdir" "${placeholder "out"}/etc/systemd/system") 122 (lib.withFeatureAs true "systemduserunitdir" "${placeholder "out"}/etc/systemd/user") 123 (lib.withFeatureAs true "udevdir" "${placeholder "out"}/lib/udev") 124 ]; 125 126 makeFlags = [ 127 "rulesdir=${placeholder "out"}/lib/udev/rules.d" 128 ]; 129 130 # Work around `make install' trying to create /var/lib/bluetooth. 131 installFlags = [ 132 "statedir=$(TMPDIR)/var/lib/bluetooth" 133 ]; 134 135 doCheck = stdenv.hostPlatform.isx86_64; 136 doInstallCheck = true; 137 138 postInstall = 139 let 140 pythonPath = with python3Packages; [ 141 dbus-python 142 pygobject3 143 ]; 144 in 145 '' 146 # for bluez4 compatibility for NixOS 147 mkdir $out/sbin 148 ln -s ../libexec/bluetooth/bluetoothd $out/sbin/bluetoothd 149 ln -s ../libexec/bluetooth/obexd $out/sbin/obexd 150 151 # Add extra configuration 152 rm $out/etc/bluetooth/{main,input,network}.conf 153 ln -s /etc/bluetooth/main.conf $out/etc/bluetooth/main.conf 154 155 # https://github.com/NixOS/nixpkgs/issues/204418 156 ln -s /etc/bluetooth/input.conf $out/etc/bluetooth/input.conf 157 ln -s /etc/bluetooth/network.conf $out/etc/bluetooth/network.conf 158 159 # Add missing tools, ref https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/bluez 160 for files in $(find tools/ -type f -perm -755); do 161 filename=$(basename $files) 162 install -Dm755 tools/$filename $out/bin/$filename 163 done 164 install -Dm755 attrib/gatttool $out/bin/gatttool 165 '' 166 + lib.optionalString installTests '' 167 mkdir -p $test/{bin,test} 168 cp -a test $test 169 pushd $test/test 170 for t in \ 171 list-devices \ 172 monitor-bluetooth \ 173 simple-agent \ 174 test-adapter \ 175 test-device \ 176 ; do 177 ln -s ../test/$t $test/bin/bluez-$t 178 done 179 popd 180 wrapPythonProgramsIn $test/test "$test/test ${toString pythonPath}" 181 ''; 182 183 enableParallelBuilding = true; 184 185 passthru.updateScript = gitUpdater { 186 url = "https://git.kernel.org/pub/scm/bluetooth/bluez.git"; 187 }; 188 189 meta = { 190 homepage = "https://www.bluez.org/"; 191 description = "Official Linux Bluetooth protocol stack"; 192 changelog = "https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/ChangeLog?h=${finalAttrs.version}"; 193 license = with lib.licenses; [ 194 bsd2 195 gpl2Plus 196 lgpl21Plus 197 mit 198 ]; 199 mainProgram = "btinfo"; 200 maintainers = with lib.maintainers; [ ]; 201 platforms = lib.platforms.linux; 202 }; 203})