2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-08-10 20:25:09 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2017-02-17 19:44:04 +01:00
|
|
|
|
2016-01-29 23:08:42 +01:00
|
|
|
let
|
2017-02-11 20:01:13 +01:00
|
|
|
bluez-bluetooth = pkgs.bluez;
|
2017-02-17 19:44:04 +01:00
|
|
|
cfg = config.hardware.bluetooth;
|
|
|
|
|
2016-01-29 23:08:42 +01:00
|
|
|
in
|
2009-08-10 20:25:09 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2010-08-27 17:32:49 +02:00
|
|
|
|
2017-02-17 19:44:04 +01:00
|
|
|
hardware.bluetooth.enable = mkEnableOption "support for Bluetooth.";
|
|
|
|
|
|
|
|
hardware.bluetooth.powerOnBoot = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Whether to power up the default Bluetooth controller on boot.";
|
2010-08-27 17:32:49 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-08-10 20:25:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
2017-02-10 03:25:03 +01:00
|
|
|
|
2017-02-17 19:44:04 +01:00
|
|
|
config = mkIf cfg.enable {
|
2010-08-27 17:32:49 +02:00
|
|
|
|
2016-01-29 23:08:42 +01:00
|
|
|
environment.systemPackages = [ bluez-bluetooth pkgs.openobex pkgs.obexftp ];
|
2017-02-01 22:52:12 +01:00
|
|
|
|
2016-01-29 23:08:42 +01:00
|
|
|
services.udev.packages = [ bluez-bluetooth ];
|
|
|
|
services.dbus.packages = [ bluez-bluetooth ];
|
2017-02-17 19:44:04 +01:00
|
|
|
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";
|
|
|
|
};
|
2017-02-01 22:52:12 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-02-17 19:44:04 +01:00
|
|
|
systemd.user.services = {
|
|
|
|
obex.aliases = [ "dbus-org.bluez.obex.service" ];
|
2017-02-01 22:52:12 +01:00
|
|
|
};
|
2013-02-10 19:30:02 +01:00
|
|
|
|
2011-09-14 20:20:50 +02:00
|
|
|
};
|
|
|
|
|
2009-08-10 20:25:09 +02:00
|
|
|
}
|