<commit_before>{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.hardware.bluetooth;
  bluez-bluetooth = cfg.package;

in {

  ###### interface

  options = {

    hardware.bluetooth = {
      enable = mkEnableOption "support for Bluetooth";

      powerOnBoot = mkOption {
        type    = types.bool;
        default = true;
        description = "Whether to power up the default Bluetooth controller on boot.";
      };

      package = mkOption {
        type = types.package;
        default = pkgs.bluez;
        defaultText = "pkgs.bluez";
        example = "pkgs.bluezFull";
        description = ''
          Which BlueZ package to use.

          <note><para>
            Use the <literal>pkgs.bluezFull</literal> package to enable all
            bluez plugins.
          </para></note>
        '';
      };

      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 {
        type = with types; nullOr lines;
        default = null;
        example = ''
          [General]
          ControllerMode = bredr
        '';
        description = ''
          Set additional configuration for system-wide bluetooth (/etc/bluetooth/main.conf).
        '';
      };
    };

  };

  ###### implementation

  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 ];

    environment.etc."bluetooth/main.conf"= {
      source = pkgs.writeText "main.conf"
        (generators.toINI { } cfg.config + optionalString (cfg.extraConfig != null) cfg.extraConfig);
    };

    services.udev.packages = [ bluez-bluetooth ];
    services.dbus.packages = [ bluez-bluetooth ];
    systemd.packages       = [ bluez-bluetooth ];

    systemd.services = {
      bluetooth = {
        wantedBy = [ "bluetooth.target" ];
        aliases  = [ "dbus-org.bluez.service" ];
      };
    };

    systemd.user.services = {
      obex.aliases = [ "dbus-org.bluez.obex.service" ];
    };

  };

}<commit_msg>nixos/bluetooth: disable restart on unit changes<commit_after>{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.hardware.bluetooth;
  bluez-bluetooth = cfg.package;

in {

  ###### interface

  options = {

    hardware.bluetooth = {
      enable = mkEnableOption "support for Bluetooth";

      powerOnBoot = mkOption {
        type    = types.bool;
        default = true;
        description = "Whether to power up the default Bluetooth controller on boot.";
      };

      package = mkOption {
        type = types.package;
        default = pkgs.bluez;
        defaultText = "pkgs.bluez";
        example = "pkgs.bluezFull";
        description = ''
          Which BlueZ package to use.

          <note><para>
            Use the <literal>pkgs.bluezFull</literal> package to enable all
            bluez plugins.
          </para></note>
        '';
      };

      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 {
        type = with types; nullOr lines;
        default = null;
        example = ''
          [General]
          ControllerMode = bredr
        '';
        description = ''
          Set additional configuration for system-wide bluetooth (/etc/bluetooth/main.conf).
        '';
      };
    };

  };

  ###### implementation

  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 ];

    environment.etc."bluetooth/main.conf"= {
      source = pkgs.writeText "main.conf"
        (generators.toINI { } cfg.config + optionalString (cfg.extraConfig != null) cfg.extraConfig);
    };

    services.udev.packages = [ bluez-bluetooth ];
    services.dbus.packages = [ bluez-bluetooth ];
    systemd.packages       = [ bluez-bluetooth ];

    systemd.services = {
      bluetooth = {
        wantedBy = [ "bluetooth.target" ];
        aliases  = [ "dbus-org.bluez.service" ];
        # restarting can leave people without a mouse/keyboard
        unitConfig.X-RestartIfChanged = false;
      };
    };

    systemd.user.services = {
      obex.aliases = [ "dbus-org.bluez.obex.service" ];
    };

  };

}
{'fraction_non_alphanumeric': 0.123837784371909, 'fraction_numerical': 0.0, 'mean_word_length': 1.9793753682969948, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1075781', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1457, 'n_words': 320}