Skip to content

Commit

Permalink
Merge pull request #24948 from peterhoeg/m/bluetooth
Browse files Browse the repository at this point in the history
bluetooth: use upstream's recommendation for enabling interfaces
  • Loading branch information
Mic92 committed Apr 16, 2017
2 parents 69d77ea + 99d4ed5 commit 16f5bc0
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions nixos/modules/services/hardware/bluetooth.nix
Expand Up @@ -6,9 +6,7 @@ let
bluez-bluetooth = pkgs.bluez;
cfg = config.hardware.bluetooth;

in

{
in {

###### interface

Expand All @@ -32,6 +30,8 @@ in
'';
description = ''
Set additional configuration for system-wide bluetooth (/etc/bluetooth/main.conf).
NOTE: We already include [Policy], so any configuration under the Policy group should come first.
'';
};
};
Expand All @@ -45,37 +45,24 @@ in
environment.systemPackages = [ bluez-bluetooth pkgs.openobex pkgs.obexftp ];

environment.etc = singleton {
source = pkgs.writeText "main.conf" cfg.extraConfig;
source = pkgs.writeText "main.conf" ''
[Policy]
AutoEnable=${lib.boolToString cfg.powerOnBoot}
${cfg.extraConfig}
'';
target = "bluetooth/main.conf";
};

services.udev.packages = [ bluez-bluetooth ];
services.dbus.packages = [ bluez-bluetooth ];
systemd.packages = [ bluez-bluetooth ];

services.udev.extraRules = optionalString cfg.powerOnBoot ''
ACTION=="add", KERNEL=="hci[0-9]*", ENV{SYSTEMD_WANTS}="bluetooth-power@%k.service"
'';

systemd.services = {
bluetooth = {
wantedBy = [ "bluetooth.target" ];
aliases = [ "dbus-org.bluez.service" ];
};

"bluetooth-power@" = mkIf cfg.powerOnBoot {
description = "Power up bluetooth controller";
after = [
"bluetooth.service"
"suspend.target"
"sys-subsystem-bluetooth-devices-%i.device"
];
wantedBy = [ "suspend.target" ];

serviceConfig.Type = "oneshot";
serviceConfig.ExecStart = "${pkgs.bluez.out}/bin/hciconfig %i up";
};

};

systemd.user.services = {
Expand Down

0 comments on commit 16f5bc0

Please sign in to comment.