8 cfg = config.hardware.bluetooth;
29 cfgFmt = pkgs.formats.ini { };
32 General.ControllerMode = "dual";
33 Policy.AutoEnable = cfg.powerOnBoot;
36 hasDisabledPlugins = builtins.length cfg.disabledPlugins > 0;
41 (mkRenamedOptionModule [ "hardware" "bluetooth" "config" ] [ "hardware" "bluetooth" "settings" ])
42 (mkRemovedOptionModule [ "hardware" "bluetooth" "extraConfig" ] ''
43 Use hardware.bluetooth.settings instead.
45 This is part of the general move to use structured settings instead of raw
46 text for config as introduced by RFC0042:
47 https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md
55 hardware.bluetooth = {
56 enable = mkEnableOption "support for Bluetooth";
58 hsphfpd.enable = mkEnableOption "support for hsphfpd[-prototype] implementation";
60 powerOnBoot = mkOption {
63 description = "Whether to power up the default Bluetooth controller on boot.";
66 package = mkPackageOption pkgs "bluez" { };
68 disabledPlugins = mkOption {
69 type = types.listOf types.str;
71 description = "Built-in plugins to disable";
79 ControllerMode = "bredr";
83 Set configuration for system-wide bluetooth (/etc/bluetooth/main.conf).
84 See <https://github.com/bluez/bluez/blob/master/src/main.conf> for full list of options.
94 ClassicBondedOnly = true;
98 Set configuration for the input service (/etc/bluetooth/input.conf).
99 See <https://github.com/bluez/bluez/blob/master/profiles/input/input.conf> for full list of options.
108 DisableSecurity = true;
112 Set configuration for the network service (/etc/bluetooth/network.conf).
113 See <https://github.com/bluez/bluez/blob/master/profiles/network/network.conf> for full list of options.
119 ###### implementation
121 config = mkIf cfg.enable {
122 environment.systemPackages = [ package ] ++ optional cfg.hsphfpd.enable pkgs.hsphfpd;
124 environment.etc."bluetooth/input.conf".source = cfgFmt.generate "input.conf" cfg.input;
125 environment.etc."bluetooth/network.conf".source = cfgFmt.generate "network.conf" cfg.network;
126 environment.etc."bluetooth/main.conf".source = cfgFmt.generate "main.conf" (
127 recursiveUpdate defaults cfg.settings
129 services.udev.packages = [ package ];
130 services.dbus.packages = [ package ] ++ optional cfg.hsphfpd.enable pkgs.hsphfpd;
131 systemd.packages = [ package ];
137 # `man bluetoothd` will refer to main.conf in the nix store but bluez
138 # will in fact load the configuration file at /etc/bluetooth/main.conf
139 # so force it here to avoid any ambiguity and things suddenly breaking
140 # if/when the bluez derivation is changed.
143 "/etc/bluetooth/main.conf"
144 ] ++ optional hasDisabledPlugins "--noplugin=${concatStringsSep "," cfg.disabledPlugins}";
147 wantedBy = [ "bluetooth.target" ];
148 aliases = [ "dbus-org.bluez.service" ];
149 serviceConfig.ExecStart = [
151 "${package}/libexec/bluetooth/bluetoothd ${escapeShellArgs args}"
153 # restarting can leave people without a mouse/keyboard
154 unitConfig.X-RestartIfChanged = false;
157 // (optionalAttrs cfg.hsphfpd.enable {
159 after = [ "bluetooth.service" ];
160 requires = [ "bluetooth.service" ];
161 wantedBy = [ "bluetooth.target" ];
163 description = "A prototype implementation used for connecting HSP/HFP Bluetooth devices";
164 serviceConfig.ExecStart = "${pkgs.hsphfpd}/bin/hsphfpd.pl";
168 systemd.user.services =
170 obex.aliases = [ "dbus-org.bluez.obex.service" ];
172 // optionalAttrs cfg.hsphfpd.enable {
174 wantedBy = [ "default.target" ];
176 description = "telephony_client for hsphfpd";
177 serviceConfig.ExecStart = "${pkgs.hsphfpd}/bin/telephony_client.pl";