@@ -6,9 +6,7 @@ let
66 bluez-bluetooth = pkgs.bluez;
77 cfg = config.hardware.bluetooth;
88
9−in
10−
11−{
9+in {
1210
1311 ###### interface
1412
@@ -32,6 +30,8 @@ in
3230 '';
3331 description = ''
3432 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.
3535 '';
3636 };
3737 };
@@ -45,7 +45,12 @@ in
4545 environment.systemPackages = [ bluez-bluetooth pkgs.openobex pkgs.obexftp ];
4646
4747 environment.etc = singleton {
48− source = pkgs.writeText "main.conf" cfg.extraConfig;
48+ source = pkgs.writeText "main.conf" ''
49+ [Policy]
50+ AutoEnable=${lib.boolToString cfg.powerOnBoot}
51+
52+ ${cfg.extraConfig}
53+ '';
4954 target = "bluetooth/main.conf";
5055 };
5156
@@ -53,29 +58,11 @@ in
5358 services.dbus.packages = [ bluez-bluetooth ];
5459 systemd.packages = [ bluez-bluetooth ];
5560
56− services.udev.extraRules = optionalString cfg.powerOnBoot ''
57− ACTION=="add", KERNEL=="hci[0-9]*", ENV{SYSTEMD_WANTS}="bluetooth-power@%k.service"
58− '';
59−
6061 systemd.services = {
6162 bluetooth = {
6263 wantedBy = [ "bluetooth.target" ];
6364 aliases = [ "dbus-org.bluez.service" ];
6465 };
65−
66− "bluetooth-power@" = mkIf cfg.powerOnBoot {
67− description = "Power up bluetooth controller";
68− after = [
69− "bluetooth.service"
70− "suspend.target"
71− "sys-subsystem-bluetooth-devices-%i.device"
72− ];
73− wantedBy = [ "suspend.target" ];
74−
75− serviceConfig.Type = "oneshot";
76− serviceConfig.ExecStart = "${pkgs.bluez.out}/bin/hciconfig %i up";
77− };
78−
7966 };
8067
8168 systemd.user.services = {