mirror of
https://github.com/Theaninova/TheaninovOS.git
synced 2026-01-21 17:12:39 +00:00
feat: a50 dock service
This commit is contained in:
13
modules/nixos/hardware/astro-a50-dock.sh
Normal file
13
modules/nixos/hardware/astro-a50-dock.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
stdbuf -oL hexdump -v -e '32/2 "%x " "\n"' "$HID_DEVICE" | while read -r line; do
|
||||
echo "$line"
|
||||
if [[ $line =~ ^c02[[:space:]]4[[:space:]]13[[:space:]]([0-9a-f]+) ]]; then
|
||||
power_state=${BASH_REMATCH[1]}
|
||||
if [[ $power_state == "0" ]]; then
|
||||
echo "power=on"
|
||||
wpctl set-default "$(pw-cli info "$HEADSET_NAME" | head -n 1 | awk '{print $2}')"
|
||||
else
|
||||
echo "power=off"
|
||||
wpctl set-default "$(pw-cli info "$SPEAKERS_NAME" | head -n 1 | awk '{print $2}')"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
@@ -13,9 +13,18 @@ in
|
||||
{
|
||||
options.hardware.astro-a50 = {
|
||||
enable = mkEnableOption "Enable optimisations for the Logitech Astro A50 headset";
|
||||
sinkWhenDocked = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
description = "The PipeWire sink name to switch to when the Astro A50 is docked. If null, no switching will be done.";
|
||||
default = "alsa_output.pci-0000_0a_00.4.analog-stereo";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.udev.extraRules = ''
|
||||
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="0b1c", MODE="0660", GROUP="input"
|
||||
'';
|
||||
users.extraGroups.input.members = [ username ];
|
||||
home-manager.users.${username} =
|
||||
let
|
||||
name = "Astro A50";
|
||||
@@ -66,6 +75,29 @@ in
|
||||
];
|
||||
};
|
||||
};
|
||||
systemd.user.services.astro-dock = mkIf (cfg.sinkWhenDocked != null) {
|
||||
Unit = {
|
||||
Description = "Astro A50 Dock Detection";
|
||||
After = [ "pipewire.service" ];
|
||||
};
|
||||
|
||||
Install.WantedBy = [ "default.target" ];
|
||||
|
||||
Service = {
|
||||
Restart = "always";
|
||||
ExecStart = lib.getExe (
|
||||
pkgs.writeShellApplication {
|
||||
name = "astro-dock-detect";
|
||||
runtimeEnv = {
|
||||
HID_DEVICE = "/dev/input/by-id/usb-Logitech_A50-if08-hidraw";
|
||||
HEADSET_NAME = nodeNameIn;
|
||||
SPEAKERS_NAME = cfg.sinkWhenDocked;
|
||||
};
|
||||
text = builtins.readFile ./astro-a50-dock.sh;
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user