at 17.09-beta 1.6 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 bluez-bluetooth = pkgs.bluez; 7 cfg = config.hardware.bluetooth; 8 9in { 10 11 ###### interface 12 13 options = { 14 15 hardware.bluetooth = { 16 enable = mkEnableOption "support for Bluetooth."; 17 18 powerOnBoot = mkOption { 19 type = types.bool; 20 default = true; 21 description = "Whether to power up the default Bluetooth controller on boot."; 22 }; 23 24 extraConfig = mkOption { 25 type = types.lines; 26 default = ""; 27 example = '' 28 [General] 29 ControllerMode = bredr 30 ''; 31 description = '' 32 Set additional configuration for system-wide bluetooth (/etc/bluetooth/main.conf). 33 34 NOTE: We already include [Policy], so any configuration under the Policy group should come first. 35 ''; 36 }; 37 }; 38 39 }; 40 41 ###### implementation 42 43 config = mkIf cfg.enable { 44 45 environment.systemPackages = [ bluez-bluetooth pkgs.openobex pkgs.obexftp ]; 46 47 environment.etc = singleton { 48 source = pkgs.writeText "main.conf" '' 49 [Policy] 50 AutoEnable=${lib.boolToString cfg.powerOnBoot} 51 52 ${cfg.extraConfig} 53 ''; 54 target = "bluetooth/main.conf"; 55 }; 56 57 services.udev.packages = [ bluez-bluetooth ]; 58 services.dbus.packages = [ bluez-bluetooth ]; 59 systemd.packages = [ bluez-bluetooth ]; 60 61 systemd.services = { 62 bluetooth = { 63 wantedBy = [ "bluetooth.target" ]; 64 aliases = [ "dbus-org.bluez.service" ]; 65 }; 66 }; 67 68 systemd.user.services = { 69 obex.aliases = [ "dbus-org.bluez.obex.service" ]; 70 }; 71 72 }; 73 74}