From d0a4fbad2aee12ab543a69f100ad31ce05c863f1 Mon Sep 17 00:00:00 2001 From: workflow <4farlion@gmail.com> Date: Wed, 16 Oct 2024 21:54:15 +0100 Subject: [PATCH] refac(boar): DDCCI loading (but no cigar yet) --- home/i3/default.nix | 2 +- home/i3status-rust.nix | 2 +- home/xsession/boar_ddc_fix.sh | 28 ---------------------------- home/xsession/boar_ddcci_fix.sh | 28 ++++++++++++++++++++++++++++ machines/boar/system.nix | 9 ++++++++- packages/default.nix | 1 - system/screens.nix | 7 +------ 7 files changed, 39 insertions(+), 38 deletions(-) delete mode 100755 home/xsession/boar_ddc_fix.sh create mode 100755 home/xsession/boar_ddcci_fix.sh diff --git a/home/i3/default.nix b/home/i3/default.nix index 6724bed5..d378f376 100644 --- a/home/i3/default.nix +++ b/home/i3/default.nix @@ -378,7 +378,7 @@ in { # See https://discourse.nixos.org/t/brightness-control-of-external-monitors-with-ddcci-backlight/8639/10 # For some reason this has to run from userland, after the xSession is started { - command = "sudo /home/farlion/code/nixos-config/home/xsession/boar_ddc_fix.sh"; + command = "sudo /home/farlion/code/nixos-config/home/xsession/boar_ddcci_fix.sh"; notification = false; } ]; diff --git a/home/i3status-rust.nix b/home/i3status-rust.nix index 8a255aeb..5f5fa65c 100644 --- a/home/i3status-rust.nix +++ b/home/i3status-rust.nix @@ -243,7 +243,7 @@ in { # } { block = "backlight"; - device = "ddcci5"; + device = "ddcci0"; click = [ { button = "left"; diff --git a/home/xsession/boar_ddc_fix.sh b/home/xsession/boar_ddc_fix.sh deleted file mode 100755 index ebec242c..00000000 --- a/home/xsession/boar_ddc_fix.sh +++ /dev/null @@ -1,28 +0,0 @@ -#! /run/current-system/sw/bin/bash -set -euo pipefail - -# See https://discourse.nixos.org/t/brightness-control-of-external-monitors-with-ddcci-backlight/8639/10 - -sleep 5 - -echo Trying to attach ddcci to i2c-4 -counter=10 -while [ $counter -gt 0 ]; do - if ddcutil getvcp 10 -b 4; then - echo ddcci 0x37 >/sys/bus/i2c/devices/i2c-4/new_device - break - fi - sleep 1 - counter=$((counter - 1)) -done - -echo Trying to attach ddcci to i2c-5 -counter=10 -while [ $counter -gt 0 ]; do - if ddcutil getvcp 10 -b 5; then - echo ddcci 0x37 >/sys/bus/i2c/devices/i2c-5/new_device - break - fi - sleep 1 - counter=$((counter - 1)) -done diff --git a/home/xsession/boar_ddcci_fix.sh b/home/xsession/boar_ddcci_fix.sh new file mode 100755 index 00000000..144f3a3b --- /dev/null +++ b/home/xsession/boar_ddcci_fix.sh @@ -0,0 +1,28 @@ +#! /run/current-system/sw/bin/bash +set -euo pipefail + +# See https://discourse.nixos.org/t/brightness-control-of-external-monitors-with-ddcci-backlight/8639/10 + +sleep 5 + +echo Trying to attach ddcci to i2c-7 +counter=10 +while [ $counter -gt 0 ]; do + if ddcutil getvcp 10 -b 7; then + echo ddcci 0x37 >/sys/bus/i2c/devices/i2c-7/new_device + break + fi + sleep 1 + counter=$((counter - 1)) +done + +# echo Trying to attach ddcci to i2c-5 +# counter=10 +# while [ $counter -gt 0 ]; do +# if ddcutil getvcp 10 -b 5; then +# echo ddcci 0x37 >/sys/bus/i2c/devices/i2c-5/new_device +# break +# fi +# sleep 1 +# counter=$((counter - 1)) +# done diff --git a/machines/boar/system.nix b/machines/boar/system.nix index 5322420d..6a02bab8 100644 --- a/machines/boar/system.nix +++ b/machines/boar/system.nix @@ -1,6 +1,7 @@ { lib, config, + pkgs, ... }: { # Use the systemd-boot EFI boot loader. @@ -13,12 +14,18 @@ # External monitors brightness control # See https://discourse.nixos.org/t/brightness-control-of-external-monitors-with-ddcci-backlight/8639/11 boot.extraModulePackages = with config.boot.kernelPackages; [ddcci-driver]; + boot.initrd.kernelModules = ["ddcci_backlight"]; + environment.systemPackages = [pkgs.ddcutil]; + services.ddccontrol.enable = true; + hardware.i2c.enable = true; + users.users.farlion.extraGroups = ["i2c"]; + security.sudo.extraRules = [ { users = ["farlion"]; commands = [ { - command = "/home/farlion/code/nixos-config/home/xsession/boar_ddc_fix.sh"; + command = "/home/farlion/code/nixos-config/home/xsession/boar_ddcci_fix.sh"; options = ["NOPASSWD" "SETENV"]; } ]; diff --git a/packages/default.nix b/packages/default.nix index 11a4ae7e..d036823b 100644 --- a/packages/default.nix +++ b/packages/default.nix @@ -24,7 +24,6 @@ cht-sh cntr # for Nix sandbox breakpointHook debugging dconf - ddcutil # For external monitor management, used by home/xsession/boar_ddc_fix.sh delta # Syntax highlighter for git unstable.devenv difftastic diff --git a/system/screens.nix b/system/screens.nix index dfcbb142..3fc3e608 100644 --- a/system/screens.nix +++ b/system/screens.nix @@ -1,9 +1,4 @@ -{pkgs, ...}: { - # Controlling external screens - services.ddccontrol.enable = true; - hardware.i2c.enable = true; - users.users.farlion.extraGroups = ["i2c"]; - +{...}: { # For redshift services.geoclue2.enable = true; }