1{ config, lib, pkgs, ... }: 2 3with lib; 4let 5 bluez-bluetooth = if config.services.xserver.desktopManager.kde4.enable then pkgs.bluez else pkgs.bluez5; 6 7 configBluez = { 8 description = "Bluetooth Service"; 9 serviceConfig = { 10 Type = "dbus"; 11 BusName = "org.bluez"; 12 ExecStart = "${bluez-bluetooth}/sbin/bluetoothd -n"; 13 }; 14 wantedBy = [ "bluetooth.target" ]; 15 }; 16 17 configBluez5 = { 18 description = "Bluetooth Service"; 19 serviceConfig = { 20 Type = "dbus"; 21 BusName = "org.bluez"; 22 ExecStart = "${bluez-bluetooth}/sbin/bluetoothd -n"; 23 NotifyAccess="main"; 24 CapabilityBoundingSet="CAP_NET_ADMIN CAP_NET_BIND_SERVICE"; 25 LimitNPROC=1; 26 }; 27 wantedBy = [ "bluetooth.target" ]; 28 }; 29 30 obexConfig = { 31 description = "Bluetooth OBEX service"; 32 serviceConfig = { 33 Type = "dbus"; 34 BusName = "org.bluez.obex"; 35 ExecStart = "${bluez-bluetooth}/sbin/obexd"; 36 }; 37 }; 38 39 bluezConfig = if config.services.xserver.desktopManager.kde4.enable then configBluez else configBluez5; 40in 41 42{ 43 44 ###### interface 45 46 options = { 47 48 hardware.bluetooth.enable = mkOption { 49 type = types.bool; 50 default = false; 51 description = "Whether to enable support for Bluetooth."; 52 }; 53 54 }; 55 56 ###### implementation 57 58 config = mkIf config.hardware.bluetooth.enable { 59 60 environment.systemPackages = [ bluez-bluetooth pkgs.openobex pkgs.obexftp ]; 61 services.udev.packages = [ bluez-bluetooth ]; 62 services.dbus.packages = [ bluez-bluetooth ]; 63 systemd.services."dbus-org.bluez" = bluezConfig; 64 systemd.services."dbus-org.bluez.obex" = obexConfig; 65 66 }; 67 68}