|
@@ -0,0 +1,47 @@
|
|
|
|
|
+{ pkgs }:
|
|
|
|
|
+
|
|
|
|
|
+pkgs.stdenv.mkDerivation {
|
|
|
|
|
+ pname = "nct6775-pwm-udev-rules";
|
|
|
|
|
+ version = "1.0";
|
|
|
|
|
+
|
|
|
|
|
+ dontUnpack = true;
|
|
|
|
|
+ dontBuild = true;
|
|
|
|
|
+
|
|
|
|
|
+ linkScript = pkgs.writeShellScript "link-nct6775-pwm" ''
|
|
|
|
|
+ echo "NCT6775 udev rule triggered at $(date): devpath=$1" >> /tmp/udev-nct-debug.log
|
|
|
|
|
+ # Input: DEVPATH from udev (e.g., /devices/platform/nct6775.656/hwmon/hwmon3)
|
|
|
|
|
+ DEVPATH="$1"
|
|
|
|
|
+ HWMON_PATH="/sys$DEVPATH"
|
|
|
|
|
+ SYMLINK_DIR="/run/hwmon"
|
|
|
|
|
+
|
|
|
|
|
+ # Ensure the symlink directory exists
|
|
|
|
|
+ mkdir -p "$SYMLINK_DIR" || { echo "Failed to create $SYMLINK_DIR"; exit 1; }
|
|
|
|
|
+
|
|
|
|
|
+ # Create symlinks for all attributes in the hwmon directory
|
|
|
|
|
+ for attr in "$HWMON_PATH"/*; do
|
|
|
|
|
+ if [ -e "$attr" ]; then
|
|
|
|
|
+ attr_name=$(basename "$attr")
|
|
|
|
|
+ echo "Linking $attr_name -> $SYMLINK_DIR/$attr_name" >> /tmp/udev-nct-debug.log
|
|
|
|
|
+ ln -sf "$attr" "$SYMLINK_DIR/$attr_name" || echo "Failed to create symlink for $attr_name"
|
|
|
|
|
+ else
|
|
|
|
|
+ echo "No attributes found in $HWMON_PATH"
|
|
|
|
|
+ fi
|
|
|
|
|
+ done
|
|
|
|
|
+
|
|
|
|
|
+ ls -la /sys/hwmon/ >> /tmp/udev-nct-debug.log 2>/dev/null || true
|
|
|
|
|
+ '';
|
|
|
|
|
+
|
|
|
|
|
+ installPhase = ''
|
|
|
|
|
+ mkdir -p $out/etc/udev/rules.d
|
|
|
|
|
+ cat > $out/etc/udev/rules.d/99-nct6775-pwm.rules << EOF
|
|
|
|
|
+ # Create constant paths for NCT6775 PWM controls
|
|
|
|
|
+ SUBSYSTEM=="hwmon", KERNEL=="hwmon[0-9]*", RUN+="$linkScript %p"
|
|
|
|
|
+ EOF
|
|
|
|
|
+ '';
|
|
|
|
|
+
|
|
|
|
|
+ meta = with pkgs.lib; {
|
|
|
|
|
+ description = "Udev rules for NCT6775 PWM device symlinks";
|
|
|
|
|
+ license = licenses.mit;
|
|
|
|
|
+ platforms = platforms.linux;
|
|
|
|
|
+ };
|
|
|
|
|
+}
|