2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.hardware.bluetooth;
|
2021-02-17 17:02:09 +00:00
|
|
|
package = cfg.package;
|
|
|
|
|
|
|
|
inherit (lib)
|
2024-01-02 11:29:13 +00:00
|
|
|
mkDefault mkEnableOption mkIf mkOption mkPackageOption
|
2021-02-17 17:02:09 +00:00
|
|
|
mkRenamedOptionModule mkRemovedOptionModule
|
2021-10-06 13:57:05 +00:00
|
|
|
concatStringsSep escapeShellArgs literalExpression
|
2021-02-17 17:02:09 +00:00
|
|
|
optional optionals optionalAttrs recursiveUpdate types;
|
|
|
|
|
|
|
|
cfgFmt = pkgs.formats.ini { };
|
|
|
|
|
|
|
|
defaults = {
|
|
|
|
General.ControllerMode = "dual";
|
|
|
|
Policy.AutoEnable = cfg.powerOnBoot;
|
|
|
|
};
|
|
|
|
|
|
|
|
hasDisabledPlugins = builtins.length cfg.disabledPlugins > 0;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-02-17 17:02:09 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "hardware" "bluetooth" "config" ] [ "hardware" "bluetooth" "settings" ])
|
|
|
|
(mkRemovedOptionModule [ "hardware" "bluetooth" "extraConfig" ] ''
|
|
|
|
Use hardware.bluetooth.settings instead.
|
|
|
|
|
|
|
|
This is part of the general move to use structured settings instead of raw
|
|
|
|
text for config as introduced by RFC0042:
|
|
|
|
https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md
|
|
|
|
'')
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
hardware.bluetooth = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "support for Bluetooth";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
hsphfpd.enable = mkEnableOption "support for hsphfpd[-prototype] implementation";
|
2020-11-12 09:05:59 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
powerOnBoot = mkOption {
|
2021-02-17 17:02:09 +00:00
|
|
|
type = types.bool;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Whether to power up the default Bluetooth controller on boot.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "bluez" { };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-02-17 17:02:09 +00:00
|
|
|
disabledPlugins = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Built-in plugins to disable";
|
2021-02-17 17:02:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = cfgFmt.type;
|
|
|
|
default = { };
|
2020-04-24 23:36:52 +00:00
|
|
|
example = {
|
|
|
|
General = {
|
|
|
|
ControllerMode = "bredr";
|
|
|
|
};
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Set configuration for system-wide bluetooth (/etc/bluetooth/main.conf).";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2023-02-02 18:25:31 +00:00
|
|
|
|
|
|
|
input = mkOption {
|
|
|
|
type = cfgFmt.type;
|
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
General = {
|
|
|
|
IdleTimeout = 30;
|
|
|
|
ClassicBondedOnly = true;
|
|
|
|
};
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Set configuration for the input service (/etc/bluetooth/input.conf).";
|
2023-02-02 18:25:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
network = mkOption {
|
|
|
|
type = cfgFmt.type;
|
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
General = {
|
|
|
|
DisableSecurity = true;
|
|
|
|
};
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Set configuration for the network service (/etc/bluetooth/network.conf).";
|
2023-02-02 18:25:31 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-02-17 17:02:09 +00:00
|
|
|
environment.systemPackages = [ package ]
|
|
|
|
++ optional cfg.hsphfpd.enable pkgs.hsphfpd;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
environment.etc."bluetooth/input.conf".source =
|
|
|
|
cfgFmt.generate "input.conf" cfg.input;
|
|
|
|
environment.etc."bluetooth/network.conf".source =
|
|
|
|
cfgFmt.generate "network.conf" cfg.network;
|
2021-02-17 17:02:09 +00:00
|
|
|
environment.etc."bluetooth/main.conf".source =
|
|
|
|
cfgFmt.generate "main.conf" (recursiveUpdate defaults cfg.settings);
|
|
|
|
services.udev.packages = [ package ];
|
|
|
|
services.dbus.packages = [ package ]
|
|
|
|
++ optional cfg.hsphfpd.enable pkgs.hsphfpd;
|
|
|
|
systemd.packages = [ package ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
systemd.services = {
|
2021-02-17 17:02:09 +00:00
|
|
|
bluetooth =
|
|
|
|
let
|
|
|
|
# `man bluetoothd` will refer to main.conf in the nix store but bluez
|
|
|
|
# will in fact load the configuration file at /etc/bluetooth/main.conf
|
|
|
|
# so force it here to avoid any ambiguity and things suddenly breaking
|
|
|
|
# if/when the bluez derivation is changed.
|
2021-02-19 19:06:45 +00:00
|
|
|
args = [ "-f" "/etc/bluetooth/main.conf" ]
|
2021-02-17 17:02:09 +00:00
|
|
|
++ optional hasDisabledPlugins
|
|
|
|
"--noplugin=${concatStringsSep "," cfg.disabledPlugins}";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
wantedBy = [ "bluetooth.target" ];
|
|
|
|
aliases = [ "dbus-org.bluez.service" ];
|
|
|
|
serviceConfig.ExecStart = [
|
|
|
|
""
|
|
|
|
"${package}/libexec/bluetooth/bluetoothd ${escapeShellArgs args}"
|
|
|
|
];
|
|
|
|
# restarting can leave people without a mouse/keyboard
|
|
|
|
unitConfig.X-RestartIfChanged = false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// (optionalAttrs cfg.hsphfpd.enable {
|
|
|
|
hsphfpd = {
|
|
|
|
after = [ "bluetooth.service" ];
|
|
|
|
requires = [ "bluetooth.service" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
wantedBy = [ "bluetooth.target" ];
|
2021-02-17 17:02:09 +00:00
|
|
|
|
|
|
|
description = "A prototype implementation used for connecting HSP/HFP Bluetooth devices";
|
|
|
|
serviceConfig.ExecStart = "${pkgs.hsphfpd}/bin/hsphfpd.pl";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2021-02-17 17:02:09 +00:00
|
|
|
});
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
systemd.user.services = {
|
|
|
|
obex.aliases = [ "dbus-org.bluez.obex.service" ];
|
2020-11-12 09:05:59 +00:00
|
|
|
}
|
2021-02-17 17:02:09 +00:00
|
|
|
// optionalAttrs cfg.hsphfpd.enable {
|
|
|
|
telephony_client = {
|
|
|
|
wantedBy = [ "default.target" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-02-17 17:02:09 +00:00
|
|
|
description = "telephony_client for hsphfpd";
|
|
|
|
serviceConfig.ExecStart = "${pkgs.hsphfpd}/bin/telephony_client.pl";
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|