mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-30 10:53:11 +00:00
bluetooth module: add option to power up bluetooth controller (#22685)
This commit is contained in:
parent
89a0365063
commit
5231d0ac29
@ -1,8 +1,11 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
bluez-bluetooth = pkgs.bluez;
|
bluez-bluetooth = pkgs.bluez;
|
||||||
|
cfg = config.hardware.bluetooth;
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -11,33 +14,53 @@ in
|
|||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
hardware.bluetooth.enable = mkOption {
|
hardware.bluetooth.enable = mkEnableOption "support for Bluetooth.";
|
||||||
type = types.bool;
|
|
||||||
default = false;
|
hardware.bluetooth.powerOnBoot = mkOption {
|
||||||
description = "Whether to enable support for Bluetooth.";
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = "Whether to power up the default Bluetooth controller on boot.";
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkIf config.hardware.bluetooth.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
environment.systemPackages = [ bluez-bluetooth pkgs.openobex pkgs.obexftp ];
|
environment.systemPackages = [ bluez-bluetooth pkgs.openobex pkgs.obexftp ];
|
||||||
|
|
||||||
services.udev.packages = [ bluez-bluetooth ];
|
services.udev.packages = [ bluez-bluetooth ];
|
||||||
|
|
||||||
services.dbus.packages = [ bluez-bluetooth ];
|
services.dbus.packages = [ bluez-bluetooth ];
|
||||||
|
systemd.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.services.bluetooth = {
|
|
||||||
wantedBy = [ "bluetooth.target" ];
|
|
||||||
aliases = [ "dbus-org.bluez.service" ];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.user.services.obex = {
|
systemd.user.services = {
|
||||||
aliases = [ "dbus-org.bluez.obex.service" ];
|
obex.aliases = [ "dbus-org.bluez.obex.service" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user