machine(Tytonidae): Add udev rule and systemd service to load backlight module

This commit is contained in:
ulic-youthlic 2025-07-06 08:58:26 +08:00
parent ee4fe74676
commit 73b25d9798
Signed by: youthlic
GPG key ID: 63E86C3C14A0D721

View file

@ -1,6 +1,7 @@
{ {
pkgs, pkgs,
lib, lib,
config,
... ...
}: { }: {
nixpkgs.config.cudaSupport = true; nixpkgs.config.cudaSupport = true;
@ -33,11 +34,46 @@
}; };
}; };
}; };
boot.binfmt = { boot = {
emulatedSystems = [ extraModulePackages = with config.boot.kernelPackages; [ddcci-driver];
"aarch64-linux" kernelModules = ["ddcci" "ddcci-backlight" "i2c-dev"];
"x86_64-windows" binfmt = {
"wasm64-wasi" emulatedSystems = [
]; "aarch64-linux"
"x86_64-windows"
"wasm64-wasi"
];
};
}; };
systemd.services."ddcci@" = {
description = "ddcci handler";
after = ["graphical.target"];
before = ["shutdown.target"];
conflicts = ["shutdown.target"];
serviceConfig = {
Type = "oneshot";
ExecStart = let
script = pkgs.writeShellApplication {
name = "ddcci-handler";
runtimeInputs = with pkgs; [coreutils ddcutil];
text = ''
echo Trying to attach ddcci to "$1"
success=0
i=0
id=$(echo "$1" | cut -d "-" -f 2)
while ((success < 1)) && ((i++ < 5)); do
if ddcutil getvcp 10 -b "$id"; then
success=1
echo ddcci 0x37 | tee "/sys/bus/i2c/devices/$1/new_device"
echo ddcci attached to "$1"
fi
done
'';
};
in "${lib.getExe' script "ddcci-handler"} %i";
};
};
services.udev.extraRules = ''
SUBSYSTEM=="i2c-dev", ACTION=="add", ATTR{name}=="NVIDIA i2c adapter*", TAG+="ddcci", TAG+="systemd", ENV{SYSTEMD_WANTS}+="ddcci@$kernel.service"
'';
} }