summary refs log tree commit diff
path: root/nixos/modules/services/hardware/bluetooth.nix
blob: fc95c4910bf7158e4ea9b19e18a63e7ad1fdc3a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{ config, lib, pkgs, ... }:

with lib;
let
    bluez-bluetooth = if config.services.xserver.desktopManager.kde4.enable then pkgs.bluez else pkgs.bluez5;

    configBluez = {
        description = "Bluetooth Service";
        serviceConfig = {
          Type = "dbus";
          BusName = "org.bluez";
          ExecStart = "${bluez-bluetooth}/sbin/bluetoothd -n";
        };
        wantedBy = [ "bluetooth.target" ];
    };

    configBluez5 =  {
        description = "Bluetooth Service";
        serviceConfig = {
          Type = "dbus";
          BusName = "org.bluez";
          ExecStart = "${bluez-bluetooth}/sbin/bluetoothd -n";
          NotifyAccess="main";
          CapabilityBoundingSet="CAP_NET_ADMIN CAP_NET_BIND_SERVICE";
          LimitNPROC=1;
        };
        wantedBy = [ "bluetooth.target" ];
    };

    obexConfig = {
        description = "Bluetooth OBEX service";
        serviceConfig = {
          Type = "dbus";
          BusName = "org.bluez.obex";
          ExecStart = "${bluez-bluetooth}/sbin/obexd";
        };
    };

    bluezConfig = if config.services.xserver.desktopManager.kde4.enable then configBluez else configBluez5;
in

{

  ###### interface

  options = {

    hardware.bluetooth.enable = mkOption {
      type = types.bool;
      default = false;
      description = "Whether to enable support for Bluetooth.";
    };

  };

  ###### implementation
  
  config = mkIf config.hardware.bluetooth.enable {

    environment.systemPackages = [ bluez-bluetooth pkgs.openobex pkgs.obexftp ];
    services.udev.packages = [ bluez-bluetooth ];
    services.dbus.packages = [ bluez-bluetooth ];
    systemd.services."dbus-org.bluez" = bluezConfig;
    systemd.services."dbus-org.bluez.obex" = obexConfig;

  };

}