66 lines
1.6 KiB
Nix
66 lines
1.6 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
{
|
|
systemd.services.no-rgb =
|
|
let
|
|
no-rgb = (
|
|
pkgs.writeShellApplication {
|
|
name = "no-rgb";
|
|
runtimeInputs = with pkgs; [
|
|
openrgb
|
|
coreutils
|
|
gnugrep
|
|
];
|
|
|
|
text = ''
|
|
# Retry loop to wait for hardware to be ready
|
|
NUM_DEVICES=0
|
|
for attempt in 1 2 3 4 5; do
|
|
NUM_DEVICES=$(openrgb --noautoconnect --list-devices 2>/dev/null | grep -cE '^[0-9]+: ' || echo 0)
|
|
if [ "$NUM_DEVICES" -gt 0 ]; then
|
|
break
|
|
fi
|
|
if [ "$attempt" -lt 5 ]; then
|
|
sleep 2
|
|
fi
|
|
done
|
|
|
|
# If no devices found after retries, exit gracefully
|
|
if [ "$NUM_DEVICES" -eq 0 ]; then
|
|
exit 0
|
|
fi
|
|
|
|
# Disable RGB on each device
|
|
for i in $(seq 0 $((NUM_DEVICES - 1))); do
|
|
openrgb --noautoconnect --device "$i" --mode direct --color 000000 || true
|
|
done
|
|
'';
|
|
}
|
|
);
|
|
in
|
|
{
|
|
description = "disable rgb";
|
|
after = [ "systemd-udev-settle.service" ];
|
|
serviceConfig = {
|
|
ExecStart = lib.getExe no-rgb;
|
|
Type = "oneshot";
|
|
Restart = "on-failure";
|
|
RestartSec = 5;
|
|
};
|
|
wantedBy = [ "multi-user.target" ];
|
|
};
|
|
|
|
services.hardware.openrgb = {
|
|
enable = true;
|
|
package = pkgs.openrgb-with-all-plugins;
|
|
motherboard = "amd";
|
|
};
|
|
|
|
services.udev.packages = [ pkgs.openrgb-with-all-plugins ];
|
|
hardware.i2c.enable = true;
|
|
}
|