hardware/bluetooth: add support for INI generator

- Add services.hardware.bluetooth.config option
- Use lib.generators.toINI with both config and extraConfig options

hardware/bluetooth: a couple suggestions

Co-authored-by: Aaron Andersen <aaron@fosslib.net>
This commit is contained in:
Oleksii Filonenko 2019-11-21 18:35:45 +02:00
parent 6b2504f9f2
commit 95fc2d3fe1
No known key found for this signature in database
GPG Key ID: F3510FE5691629A1

View File

@ -36,17 +36,25 @@ in {
''; '';
}; };
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).";
};
extraConfig = mkOption { extraConfig = mkOption {
type = types.lines; type = with types; nullOr lines;
default = ""; default = null;
example = '' example = ''
[General] [General]
ControllerMode = bredr ControllerMode = bredr
''; '';
description = '' description = ''
Set additional configuration for system-wide bluetooth (/etc/bluetooth/main.conf). Set additional configuration for system-wide bluetooth (/etc/bluetooth/main.conf).
NOTE: We already include [Policy], so any configuration under the Policy group should come first.
''; '';
}; };
}; };
@ -56,16 +64,18 @@ in {
###### implementation ###### implementation
config = mkIf cfg.enable { config = mkIf cfg.enable {
warnings = optional (cfg.extraConfig != null) "hardware.bluetooth.`extraConfig` is deprecated, please use hardware.bluetooth.`config`.";
hardware.bluetooth.config = {
Policy = {
AutoEnable = mkDefault cfg.powerOnBoot;
};
};
environment.systemPackages = [ bluez-bluetooth pkgs.openobex pkgs.obexftp ]; environment.systemPackages = [ bluez-bluetooth pkgs.openobex pkgs.obexftp ];
environment.etc = singleton { environment.etc = singleton {
source = pkgs.writeText "main.conf" '' source = pkgs.writeText "main.conf" (generators.toINI { } cfg.config + optionalString (cfg.extraConfig != null) cfg.extraConfig);
[Policy]
AutoEnable=${lib.boolToString cfg.powerOnBoot}
${cfg.extraConfig}
'';
target = "bluetooth/main.conf"; target = "bluetooth/main.conf";
}; };