at 18.09-beta 1.9 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.hardware.bluetooth; 7 bluez-bluetooth = cfg.package; 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 package = mkOption { 25 type = types.package; 26 default = pkgs.bluez; 27 defaultText = "pkgs.bluez"; 28 example = "pkgs.bluez.override { enableMidi = true; }"; 29 description = '' 30 Which BlueZ package to use. 31 ''; 32 }; 33 34 extraConfig = mkOption { 35 type = types.lines; 36 default = ""; 37 example = '' 38 [General] 39 ControllerMode = bredr 40 ''; 41 description = '' 42 Set additional configuration for system-wide bluetooth (/etc/bluetooth/main.conf). 43 44 NOTE: We already include [Policy], so any configuration under the Policy group should come first. 45 ''; 46 }; 47 }; 48 49 }; 50 51 ###### implementation 52 53 config = mkIf cfg.enable { 54 55 environment.systemPackages = [ bluez-bluetooth pkgs.openobex pkgs.obexftp ]; 56 57 environment.etc = singleton { 58 source = pkgs.writeText "main.conf" '' 59 [Policy] 60 AutoEnable=${lib.boolToString cfg.powerOnBoot} 61 62 ${cfg.extraConfig} 63 ''; 64 target = "bluetooth/main.conf"; 65 }; 66 67 services.udev.packages = [ bluez-bluetooth ]; 68 services.dbus.packages = [ bluez-bluetooth ]; 69 systemd.packages = [ bluez-bluetooth ]; 70 71 systemd.services = { 72 bluetooth = { 73 wantedBy = [ "bluetooth.target" ]; 74 aliases = [ "dbus-org.bluez.service" ]; 75 }; 76 }; 77 78 systemd.user.services = { 79 obex.aliases = [ "dbus-org.bluez.obex.service" ]; 80 }; 81 82 }; 83 84}