Headphone mechanism change
This commit is contained in:
@@ -5,15 +5,51 @@
|
||||
pkgs,
|
||||
...
|
||||
}: {
|
||||
options.azos.headphones-whmx4000.enable = lib.mkOption {
|
||||
default = true;
|
||||
type = lib.types.bool;
|
||||
options.azos.headphones = {
|
||||
enable = lib.mkOption {
|
||||
default = false;
|
||||
example = true;
|
||||
type = lib.types.bool;
|
||||
};
|
||||
devices = lib.mkOption {
|
||||
default = [];
|
||||
type = lib.types.listOf (lib.types.submodule {
|
||||
options = {
|
||||
mac = lib.mkOption {type = lib.types.str;};
|
||||
name = lib.mkOption {type = lib.types.str;};
|
||||
};
|
||||
});
|
||||
description = "Headphone devices; first entry is the default connect target.";
|
||||
};
|
||||
};
|
||||
config = lib.mkIf config.azos.headphones-whmx4000.enable {
|
||||
home.packages = [
|
||||
(pkgs.writeShellScriptBin
|
||||
"azos-connect-headphones-whmx4000"
|
||||
"echo \"connect AC:80:0A:AF:E1:C2\" | bluetoothctl")
|
||||
|
||||
config = lib.mkIf config.azos.headphones.enable {
|
||||
home.packages = let
|
||||
deviceEntries =
|
||||
lib.concatMapStrings
|
||||
(d: " ${lib.escapeShellArg "${d.mac} ${d.name}"}\n")
|
||||
config.azos.headphones.devices;
|
||||
defaultMac =
|
||||
if config.azos.headphones.devices == []
|
||||
then ""
|
||||
else (lib.head config.azos.headphones.devices).mac;
|
||||
in [
|
||||
(pkgs.writeShellScriptBin "azos-connect-headphones" ''
|
||||
DEVICES=(
|
||||
${deviceEntries})
|
||||
|
||||
case "$1" in
|
||||
--list)
|
||||
printf '%s\n' "''${DEVICES[@]}"
|
||||
;;
|
||||
--mac)
|
||||
echo "connect $2" | bluetoothctl
|
||||
;;
|
||||
*)
|
||||
echo "connect ${defaultMac}" | bluetoothctl
|
||||
;;
|
||||
esac
|
||||
'')
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user