From 865bffa641925c559f31ef293efe42ff11be9062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Mon, 10 Jun 2024 03:00:52 +0200 Subject: [PATCH] phases: Allow loosen brightness setting again Didn't manage to do what I wanted to do for some reason, but hey, at least ddcutils is there. --- curacao/hardware.nix | 22 +++++++++++++++++----- hm/brightness/default.nix | 26 +++++++++----------------- options.nix | 9 ++++----- os/desktop/default.nix | 2 ++ pindakaas/hardware.nix | 15 ++++++++++----- 5 files changed, 42 insertions(+), 32 deletions(-) diff --git a/curacao/hardware.nix b/curacao/hardware.nix index 0247edf..6147188 100644 --- a/curacao/hardware.nix +++ b/curacao/hardware.nix @@ -44,11 +44,23 @@ in ]; maxVideoHeight = 1440; numlock = true; - phasesBrightness = { - enable = true; - jour = "40000"; - crepuscule = "10000"; - nuit = "1"; + phasesCommands = { + jour = '' + ${pkgs.brightnessctl}/bin/brightnessctl set 40000 & + ${pkgs.ddcutil}/bin/ddcutil setvcp 10 20 -d 1 & + ${pkgs.ddcutil}/bin/ddcutil setvcp 10 20 -d 2 & + ''; + crepuscule = '' + ${pkgs.brightnessctl}/bin/brightnessctl set 10000 & + ${pkgs.ddcutil}/bin/ddcutil setvcp 10 10 -d 1 & + ${pkgs.ddcutil}/bin/ddcutil setvcp 10 10 -d 2 & + ''; + nuit = '' + ${pkgs.brightnessctl}/bin/brightnessctl set 1 & + ${pkgs.ddcutil}/bin/ddcutil setvcp 10 0 -d 1 & + ${pkgs.ddcutil}/bin/ddcutil setvcp 10 0 -d 2 & + ''; + # TODO Display 2 doesn't work anymore? }; }; nixpkgs.overlays = [ diff --git a/hm/brightness/default.nix b/hm/brightness/default.nix index 6810d09..7b73fd8 100644 --- a/hm/brightness/default.nix +++ b/hm/brightness/default.nix @@ -6,27 +6,19 @@ let { command = "crepuscule"; specialisation = "dark"; } { command = "nuit"; specialisation = "dark"; } ]; - phasesBrightness = config.frogeye.desktop.phasesBrightness; in { config = { home.packages = map - (phase: (pkgs.writeShellApplication { - name = "${phase.command}"; - runtimeInputs = [ pkgs.brightnessctl ]; - text = (lib.optionalString phasesBrightness.enable '' - brightnessctl set ${builtins.getAttr phase.command phasesBrightness} - '') + '' - switch="/nix/var/nix/profiles/system${lib.strings.optionalString (phase.specialisation != null) "/specialisation/${phase.specialisation}"}/bin/switch-to-configuration" - if [ -x "$switch" ] - then - # In two steps to get the visual changes slightly earlier - sudo "$switch" test - sudo "$switch" boot - fi - ''; - }) - ) + (phase: (pkgs.writeShellScriptBin phase.command '' + switch="/nix/var/nix/profiles/system${lib.strings.optionalString (phase.specialisation != null) "/specialisation/${phase.specialisation}"}/bin/switch-to-configuration" + if [ -x "$switch" ] + then + sudo "$switch" test & + sudo "$switch" boot & + fi + ${builtins.getAttr phase.command config.frogeye.desktop.phasesCommands} + '')) phases; xsession.windowManager.i3.config.keybindings = { "XF86MonBrightnessUp" = "exec ${pkgs.brightnessctl}/bin/brightnessctl set +5%"; diff --git a/options.nix b/options.nix index 180c3cb..a9c16e6 100644 --- a/options.nix +++ b/options.nix @@ -22,11 +22,10 @@ description = "Maximum video height in pixel the machine can reasonably watch"; default = 1080; }; - phasesBrightness = { - enable = lib.mkEnableOption "Set a specific brightness for the screen when running phases commands"; - jour = lib.mkOption { type = lib.types.str; default = "100%"; description = "brightnessctl value for phase: jour"; }; - crepuscule = lib.mkOption { type = lib.types.str; default = "50%"; description = "brightnessctl value for phase: crepuscule"; }; - nuit = lib.mkOption { type = lib.types.str; default = "1%"; description = "brightnessctl value for phase: nuit"; }; + phasesCommands = { + jour = lib.mkOption { type = lib.types.lines; default = ""; description = "Command to execute for phase: jour"; }; + crepuscule = lib.mkOption { type = lib.types.lines; default = ""; description = "Command to execute for phase: crepuscule"; }; + nuit = lib.mkOption { type = lib.types.lines; default = ""; description = "Command to execute for phase: nuit"; }; }; }; dev = { diff --git a/os/desktop/default.nix b/os/desktop/default.nix index 1f47bc2..799edcc 100644 --- a/os/desktop/default.nix +++ b/os/desktop/default.nix @@ -1,9 +1,11 @@ { pkgs, lib, config, ... }: { config = lib.mkIf config.frogeye.desktop.xorg { + boot.kernelModules = [ "i2c-dev" ]; # Allows using ddcutil services = { blueman.enable = true; displayManager.defaultSession = "none+i3"; + udev.packages = with pkgs; [ ddcutil ]; # TODO Doesn't seem to help xserver = { enable = true; windowManager.i3.enable = true; diff --git a/pindakaas/hardware.nix b/pindakaas/hardware.nix index d085653..5c00977 100644 --- a/pindakaas/hardware.nix +++ b/pindakaas/hardware.nix @@ -16,11 +16,16 @@ frogeye.desktop = { x11_screens = [ "DP-1" "eDP-1" ]; maxVideoHeight = 1080; - phasesBrightness = { - enable = true; - jour = "3500"; - crepuscule = "3000"; - nuit = "700"; + phasesCommands = { + jour = '' + ${pkgs.brightnessctl}/bin/brightnessctl set 3500 + ''; + crepuscule = '' + ${pkgs.brightnessctl}/bin/brightnessctl set 3000 + ''; + nuit = '' + ${pkgs.brightnessctl}/bin/brightnessctl set 700 + ''; }; };