update astro service

This commit is contained in:
2026-01-05 18:03:56 +01:00
parent 648380f91b
commit e3e1d93b99

View File

@@ -20,37 +20,47 @@ in
}; };
}; };
config = mkIf cfg.enable { config =
services.udev.extraRules = '' let
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="0b1c", MODE="0660", GROUP="input" name = "Astro A50";
''; nick = "A50";
users.extraGroups.input.members = [ username ]; pipewireFilter = bitrate: {
home-manager.users.${username} = "media.class" = "Audio/Sink";
let "alsa.components" = "USB046d:0b1c";
name = "Astro A50"; "alsa.resolution_bits" = bitrate;
nick = "A50"; };
filter = bitrate: { serviceName = "astro-a50-dock-detection";
"media.class" = "Audio/Sink"; nodeNameIn = "astro-a50-eq-harman-in";
"alsa.components" = "USB046d:0b1c"; hidrawName = "hidraw_astro_a50";
"alsa.resolution_bits" = bitrate; hidrawPath = "/dev/${hidrawName}";
}; deviceUnit = "dev-${hidrawName}.device";
hidrawPath = "/dev/input/by-id/usb-Logitech_A50-if08-hidraw"; in
nodeNameIn = "astro-a50-eq-harman-in";
in mkIf cfg.enable {
{ services.udev.extraRules = lib.strings.join ", " [
"KERNEL==\"hidraw*\""
"ATTRS{idVendor}==\"046d\""
"ATTRS{idProduct}==\"0b1c\""
"MODE=\"0660\""
"GROUP=\"input\""
"TAG+=\"systemd\""
"SYMLINK+=\"${hidrawName}\""
];
users.extraGroups.input.members = [ username ];
home-manager.users.${username} = {
home.packages = with pkgs; [ zam-plugins ]; home.packages = with pkgs; [ zam-plugins ];
xdg.configFile = { xdg.configFile = {
"wireplumber/wireplumber.conf.d/51-astro-a50.conf".text = builtins.toJSON { "wireplumber/wireplumber.conf.d/51-astro-a50.conf".text = builtins.toJSON {
"monitor.alsa.rules" = [ "monitor.alsa.rules" = [
{ {
matches = [ (filter 16) ]; matches = [ (pipewireFilter 16) ];
actions.update-props = { actions.update-props = {
"node.description" = "${name} Chat"; "node.description" = "${name} Chat";
"node.nick" = "${nick} Chat"; "node.nick" = "${nick} Chat";
}; };
} }
{ {
matches = [ (filter 24) ]; matches = [ (pipewireFilter 24) ];
actions.update-props = { actions.update-props = {
"node.description" = name; "node.description" = name;
"node.nick" = nick; "node.nick" = nick;
@@ -68,7 +78,7 @@ in
"capture.props" = { "capture.props" = {
"node.name" = nodeNameIn; "node.name" = nodeNameIn;
"filter.smart" = true; "filter.smart" = true;
"filter.smart.target" = filter 24; "filter.smart.target" = pipewireFilter 24;
}; };
"playback.props"."node.name" = "EQ Output"; "playback.props"."node.name" = "EQ Output";
}; };
@@ -76,31 +86,33 @@ in
]; ];
}; };
}; };
systemd.user.services.astro-dock = mkIf (cfg.sinkWhenDocked != null) { systemd.user.services.${serviceName} = mkIf (cfg.sinkWhenDocked != null) {
Unit = { Unit = {
Description = "Astro A50 Dock Detection"; Description = "Astro A50 Dock Detection";
After = [ "pipewire.service" ]; StopPropagatedFrom = [ deviceUnit ];
}; };
Install.WantedBy = [
Install.WantedBy = [ "default.target" ]; "default.target"
Path.PathExists = hidrawPath; deviceUnit
];
Service = { Service = {
Restart = "always"; Restart = "always";
RestartSec = 10; RestartSec = "5";
ExecStart = lib.getExe ( ExecStart = "-${
pkgs.writeShellApplication { lib.getExe (
name = "astro-dock-detect"; pkgs.writeShellApplication {
runtimeEnv = { name = "astro-dock-detect";
HID_DEVICE = hidrawPath; runtimeEnv = {
HEADSET_NAME = nodeNameIn; HID_DEVICE = hidrawPath;
SPEAKERS_NAME = cfg.sinkWhenDocked; HEADSET_NAME = nodeNameIn;
}; SPEAKERS_NAME = cfg.sinkWhenDocked;
text = builtins.readFile ./astro-a50-dock.sh; };
} text = builtins.readFile ./astro-a50-dock.sh;
); }
)
}";
}; };
}; };
}; };
}; };
} }