2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-08-10 19:25:09 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2017-02-17 18:44:04 +00:00
|
|
|
|
2016-01-29 22:08:42 +00:00
|
|
|
let
|
2017-02-17 18:44:04 +00:00
|
|
|
cfg = config.hardware.bluetooth;
|
2018-03-07 04:12:22 +00:00
|
|
|
bluez-bluetooth = cfg.package;
|
2017-02-17 18:44:04 +00:00
|
|
|
|
2017-04-13 03:48:58 +01:00
|
|
|
in {
|
2009-08-10 19:25:09 +01:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2010-08-27 16:32:49 +01:00
|
|
|
|
2017-03-20 13:28:02 +00:00
|
|
|
hardware.bluetooth = {
|
2019-04-20 02:41:48 +01:00
|
|
|
enable = mkEnableOption "support for Bluetooth";
|
2017-02-17 18:44:04 +00:00
|
|
|
|
2017-03-20 13:28:02 +00:00
|
|
|
powerOnBoot = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Whether to power up the default Bluetooth controller on boot.";
|
|
|
|
};
|
|
|
|
|
2018-03-07 04:12:22 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.bluez;
|
|
|
|
defaultText = "pkgs.bluez";
|
2018-12-15 05:49:41 +00:00
|
|
|
example = "pkgs.bluezFull";
|
2018-03-07 04:12:22 +00:00
|
|
|
description = ''
|
|
|
|
Which BlueZ package to use.
|
2018-12-15 05:49:41 +00:00
|
|
|
|
|
|
|
<note><para>
|
|
|
|
Use the <literal>pkgs.bluezFull</literal> package to enable all
|
|
|
|
bluez plugins.
|
|
|
|
</para></note>
|
2018-03-07 04:12:22 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-11-21 16:35:45 +00:00
|
|
|
config = mkOption {
|
|
|
|
type = with types; attrsOf (attrsOf (oneOf [ bool int str ]));
|
|
|
|
example = {
|
|
|
|
General = {
|
|
|
|
ControllerMode = "bredr";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
description = "Set configuration for system-wide bluetooth (/etc/bluetooth/main.conf).";
|
|
|
|
};
|
|
|
|
|
2017-03-20 13:28:02 +00:00
|
|
|
extraConfig = mkOption {
|
2019-11-21 16:35:45 +00:00
|
|
|
type = with types; nullOr lines;
|
|
|
|
default = null;
|
2017-03-20 13:28:02 +00:00
|
|
|
example = ''
|
|
|
|
[General]
|
|
|
|
ControllerMode = bredr
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Set additional configuration for system-wide bluetooth (/etc/bluetooth/main.conf).
|
|
|
|
'';
|
|
|
|
};
|
2010-08-27 16:32:49 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
2017-02-10 02:25:03 +00:00
|
|
|
|
2017-02-17 18:44:04 +00:00
|
|
|
config = mkIf cfg.enable {
|
2019-11-21 16:35:45 +00:00
|
|
|
warnings = optional (cfg.extraConfig != null) "hardware.bluetooth.`extraConfig` is deprecated, please use hardware.bluetooth.`config`.";
|
|
|
|
|
|
|
|
hardware.bluetooth.config = {
|
|
|
|
Policy = {
|
|
|
|
AutoEnable = mkDefault cfg.powerOnBoot;
|
|
|
|
};
|
|
|
|
};
|
2010-08-27 16:32:49 +01:00
|
|
|
|
2019-06-21 10:17:33 +01:00
|
|
|
environment.systemPackages = [ bluez-bluetooth ];
|
2017-02-01 21:52:12 +00:00
|
|
|
|
2019-09-14 18:51:29 +01:00
|
|
|
environment.etc."bluetooth/main.conf"= {
|
|
|
|
source = pkgs.writeText "main.conf"
|
|
|
|
(generators.toINI { } cfg.config + optionalString (cfg.extraConfig != null) cfg.extraConfig);
|
2017-03-20 13:28:02 +00:00
|
|
|
};
|
|
|
|
|
2016-01-29 22:08:42 +00:00
|
|
|
services.udev.packages = [ bluez-bluetooth ];
|
|
|
|
services.dbus.packages = [ bluez-bluetooth ];
|
2017-02-17 18:44:04 +00:00
|
|
|
systemd.packages = [ bluez-bluetooth ];
|
|
|
|
|
|
|
|
systemd.services = {
|
|
|
|
bluetooth = {
|
|
|
|
wantedBy = [ "bluetooth.target" ];
|
|
|
|
aliases = [ "dbus-org.bluez.service" ];
|
2020-10-31 20:46:42 +00:00
|
|
|
# restarting can leave people without a mouse/keyboard
|
|
|
|
unitConfig.X-RestartIfChanged = false;
|
2017-02-17 18:44:04 +00:00
|
|
|
};
|
2017-02-01 21:52:12 +00:00
|
|
|
};
|
|
|
|
|
2017-02-17 18:44:04 +00:00
|
|
|
systemd.user.services = {
|
|
|
|
obex.aliases = [ "dbus-org.bluez.obex.service" ];
|
2017-02-01 21:52:12 +00:00
|
|
|
};
|
2013-02-10 18:30:02 +00:00
|
|
|
|
2011-09-14 19:20:50 +01:00
|
|
|
};
|
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
}
|