dot

NixOS dotfiles
git clone https://git.echoz.io/dot.git
Log | Files | Refs

commit a9b215d42d675d67bf49040b0c720fea48c4f294
parent ab4085f137b0255701171babcd8ba6ff3a62d87e
Author: Chris <chris@echoz.io>
Date:   Tue,  7 Oct 2025 10:52:52 +0200

feat: make hypridle brightness control configurable

Diffstat:
Mhosts/rc/default.nix | 4+++-
Mmodules/hypr/hypridle.nix | 141++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
Mmodules/hypr/hyprlock.nix | 1+
Mmodules/syncthing/syncthingtray-init.nix | 82++++++++++++++++++++++++++++++++++++++++---------------------------------------
4 files changed, 136 insertions(+), 92 deletions(-)

diff --git a/hosts/rc/default.nix b/hosts/rc/default.nix @@ -1,4 +1,4 @@ -{ modulesPath, sec, ... }: +{ modulesPath, sec, user, ... }: { imports = [ sec.nixosModules.dot @@ -28,4 +28,6 @@ enableAllFirmware = true; cpu.intel.updateMicrocode = true; }; + + home-manager.users.${user}.services.hypridle.brightnessDevice = "intel_backlight"; } diff --git a/modules/hypr/hypridle.nix b/modules/hypr/hypridle.nix @@ -1,65 +1,104 @@ { + lib, pkgs, user, ... }: { - home-manager.users.${user} = { - home.packages = [ pkgs.brightnessctl ]; - - wayland.windowManager.hyprland.settings.bind = [ "$mod, Delete, exec, loginctl lock-session" ]; + home-manager.users.${user} = + { config, ... }: + { + options.services.hypridle = { + brightnessDevice = lib.mkOption { + type = with lib.types; nullOr str; + default = null; + }; + }; - services.hypridle = { - enable = true; + config = { + home.packages = [ pkgs.brightnessctl ]; - settings = { - general.lock_cmd = builtins.toString (pkgs.writeShellScript "lock" '' - pidof hyprlock || hyprlock - ''); + wayland.windowManager.hyprland.settings.bind = [ "$mod, Delete, exec, loginctl lock-session" ]; - listener = [ - { - timeout = 1; - on-resume = builtins.toString (pkgs.writeShellScript "dpms-on-undim" '' - hyprctl dispatch dpms on - brightnessctl -r - ''); - } - { - timeout = 10; - on-timeout = builtins.toString (pkgs.writeShellScript "manual-lock-dim" '' - save="$(brightnessctl -m | awk -F, '{if ($4 != "10%") {print "-s"; exit}}')" - pidof hyprlock && brightnessctl $save set 10% - ''); - } - { - timeout = 30; - on-timeout = builtins.toString (pkgs.writeShellScript "manual-lock-dpms-off" '' - pidof hyprlock && hyprctl dispatch dpms off - ''); - } + services.hypridle = + let + cfg = config.services.hypridle; + in { - timeout = 60; - on-timeout = builtins.toString (pkgs.writeShellScript "auto-dim" '' - save="$(brightnessctl -m | awk -F, '{if ($4 != "10%") {print "-s"; exit}}')" - brightnessctl $save set 10% - ''); - } - { - timeout = 300; - on-timeout = builtins.toString (pkgs.writeShellScript "auto-lock" '' - loginctl lock-session - ''); - } - { - timeout = 330; - on-timeout = builtins.toString (pkgs.writeShellScript "auto-lock-dpms-off" '' - hyprctl dispatch dpms off - ''); - } - ]; + enable = true; + + settings = { + general.lock_cmd = builtins.toString ( + pkgs.writeShellScript "lock" '' + pidof hyprlock || hyprlock + '' + ); + + listener = [ + { + timeout = 1; + on-resume = builtins.toString ( + pkgs.writeShellScript "dpms-on" '' + hyprctl dispatch dpms on + '' + ); + } + { + timeout = 30; + on-timeout = builtins.toString ( + pkgs.writeShellScript "manual-lock-dpms-off" '' + pidof hyprlock && hyprctl dispatch dpms off + '' + ); + } + { + timeout = 300; + on-timeout = builtins.toString ( + pkgs.writeShellScript "auto-lock" '' + loginctl lock-session + '' + ); + } + { + timeout = 330; + on-timeout = builtins.toString ( + pkgs.writeShellScript "auto-lock-dpms-off" '' + hyprctl dispatch dpms off + '' + ); + } + ] + ++ (lib.optionals (cfg.brightnessDevice != null) [ + { + timeout = 1; + on-resume = builtins.toString ( + pkgs.writeShellScript "undim" '' + brightnessctl -d ${lib.escapeShellArg cfg.brightnessDevice} -r + '' + ); + } + { + timeout = 10; + on-timeout = builtins.toString ( + pkgs.writeShellScript "manual-lock-dim" '' + save="$(brightnessctl -m | awk -F, '{if ($4 != "10%") {print "-s"; exit}}')" + pidof hyprlock && brightnessctl $save set 10% + '' + ); + } + { + timeout = 60; + on-timeout = builtins.toString ( + pkgs.writeShellScript "auto-dim" '' + save="$(brightnessctl -m | awk -F, '{if ($4 != "10%") {print "-s"; exit}}')" + brightnessctl $save set 10% + '' + ); + } + ]); + }; + }; }; }; - }; } diff --git a/modules/hypr/hyprlock.nix b/modules/hypr/hyprlock.nix @@ -28,6 +28,7 @@ inner_color = "rgba(0,0,0,0.2)"; check_color = "rgba(0,0,255,0.2)"; fail_color = "rgba(255,0,0,0.2)"; + fail_text = ""; outline_thickness = 0; placeholder_text = ""; shadow_passes = 0; diff --git a/modules/syncthing/syncthingtray-init.nix b/modules/syncthing/syncthingtray-init.nix @@ -6,50 +6,52 @@ ... }: { - home-manager.users.${user} = { config, ... }: { - systemd.user.services = { - ${config.services.syncthing.tray.package.pname}.Unit.Requires = [ "syncthingtray-init.service" ]; - syncthingtray-init = { - Unit = { - Description = "Generate syncthingtray config"; - After = [ - "syncthing.service" - "graphical-session.target" - ]; - Requires = [ "syncthing.service" ]; - Before = [ "${config.services.syncthing.tray.package.pname}.service" ]; - PartOf = [ "graphical-session.target" ]; - }; + home-manager.users.${user} = + { config, ... }: + { + systemd.user.services = { + ${config.services.syncthing.tray.package.pname}.Unit.Requires = [ "syncthingtray-init.service" ]; + syncthingtray-init = { + Unit = { + Description = "Generate syncthingtray config"; + After = [ + "syncthing.service" + "graphical-session.target" + ]; + Requires = [ "syncthing.service" ]; + Before = [ "${config.services.syncthing.tray.package.pname}.service" ]; + PartOf = [ "graphical-session.target" ]; + }; - Install.WantedBy = [ "default.target" ]; + Install.WantedBy = [ "default.target" ]; - Service = { - Type = "oneshot"; - RuntimeDirectory = "syncthingtray-init"; - RemainAfterExit = true; - ExecStart = pkgs.writeShellScript "syncthingtray-init" '' - while - ! ${pkgs.libxml2}/bin/xmllint \ - --xpath 'string(configuration/gui/apikey)' \ - "''${XDG_STATE_HOME:-$HOME/.local/state}/syncthing/config.xml" \ - >"$RUNTIME_DIRECTORY/api_key" - do ${lib.getExe' pkgs.coreutils "sleep"} 1; done - cat >"''${XDG_CONFIG_HOME:-$HOME/.config}/syncthingtray.ini" <<EOF - [General] - v=${config.services.syncthing.tray.package.version} + Service = { + Type = "oneshot"; + RuntimeDirectory = "syncthingtray-init"; + RemainAfterExit = true; + ExecStart = pkgs.writeShellScript "syncthingtray-init" '' + while + ! ${pkgs.libxml2}/bin/xmllint \ + --xpath 'string(configuration/gui/apikey)' \ + "''${XDG_STATE_HOME:-$HOME/.local/state}/syncthing/config.xml" \ + >"$RUNTIME_DIRECTORY/api_key" + do ${lib.getExe' pkgs.coreutils "sleep"} 1; done + cat >"''${XDG_CONFIG_HOME:-$HOME/.config}/syncthingtray.ini" <<EOF + [General] + v=${config.services.syncthing.tray.package.version} - [tray] - connections\\1\\apiKey=@ByteArray($(cat "$RUNTIME_DIRECTORY/api_key")) - connections\\1\\syncthingUrl=http://127.0.0.1:8384 - connections\\1\\authEnabled=false - connections\\1\\autoConnect=true - connections\\1\\httpsCertPath=''${XDG_STATE_HOME:-$HOME/.local/state}/syncthing/https-cert.pem - connections\\1\\label=localhost - connections\size=1 - EOF - ''; + [tray] + connections\\1\\apiKey=@ByteArray($(cat "$RUNTIME_DIRECTORY/api_key")) + connections\\1\\syncthingUrl=http://127.0.0.1:8384 + connections\\1\\authEnabled=false + connections\\1\\autoConnect=true + connections\\1\\httpsCertPath=''${XDG_STATE_HOME:-$HOME/.local/state}/syncthing/https-cert.pem + connections\\1\\label=localhost + connections\size=1 + EOF + ''; + }; }; }; }; - }; }