From 7df87bf0bb24e3869c162549cbcdc1434271b4a8 Mon Sep 17 00:00:00 2001 From: Stefan Junker Date: Thu, 25 May 2023 11:29:46 +0200 Subject: [PATCH] feat(t14): add power and fan control --- nix/home-manager/programs/waybar.css | 146 +-------------------------- nix/home-manager/programs/waybar.nix | 16 ++- nix/os/devices/steveej-t14/hw.nix | 65 ++++++++++++ 3 files changed, 79 insertions(+), 148 deletions(-) diff --git a/nix/home-manager/programs/waybar.css b/nix/home-manager/programs/waybar.css index 9adcc7b..60eff50 100644 --- a/nix/home-manager/programs/waybar.css +++ b/nix/home-manager/programs/waybar.css @@ -1,146 +1,6 @@ -* { - /* all: unset;*/ - border: none; - border-radius: 0; - /* `otf-font-awesome` is required to be installed for icons */ - /* font matches sway-config.nix */ - font-family: "Iosevka Comfy Fixed"; /* TODO: parameterize this? */ - font-weight: bold; - font-size: 12px; - min-height: 0; - - padding: 0px; -} - -window#waybar { - background-color: #111111; - color: #666666; - border-bottom: 2px double #fff; - border-bottom: 2px double #33ccff; -} - -/* -window#waybar.termite { - background-color: #3F3F3F; -} - -window#waybar.chromium { - background-color: #000000; - border: none; -} -*/ - -#workspaces button { - padding: 0px; - margin: 4px; - margin-left: 2px; - margin-right: 2px; - color: #cccccc; - min-width: 25px; - border: 1px solid transparent; -} - -/* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */ -/* -#workspaces button:hover { - background: rgba(0, 0, 0, 0.2); - box-shadow: inherit; - border-bottom: 3px solid #ffffff; -} -*/ - -#workspaces button.current_output { - border-color: #aaa; - border-style: dotted; +#custom-cputemp { + padding: 0 10px; + background-color: #f0932b; color: #ffffff; } - -#workspaces button.focused { - background-color: #aaa; - color: #000000; - border-color: #aaa; - border-style: solid; -} - -#workspaces button.focused.current_output { - border-color: #ee00ff; - border-style: solid; -} - -#workspaces button.urgent { - background-color: #eb4d4b; -} - -#mode { - background-color: #64727D; - border-bottom: 1px solid #ffffff; -} - -#tray { - background-color: #111111; -} - -#clock, -#clock-time, -#battery, -#cpu, -#memory, -#temperature, -#network, -#custom-ppp, -#custom-rog, -#tray, -#mode, -#backlight, -#pulseaudio, -#idle_inhibitor, -#mpd { - /*padding: 2px;*/ - padding: 0px; - padding-left: 4px; - padding-right: 4px; - margin: 4px; - margin-right: 6px; - color: #fff; - background-color: #333; -} - -#battery { -} - -#battery.charging { - color: #26A65B; -} - -@keyframes blink { - to { - background-color: #f53c3c; - color: #ffffff; - } -} - -#battery.Charging { - color: green; -} -#battery.Discharging { - color: blue; -} -#battery.Discharging.warning { - color: orange; -} -#battery.Discharging.critical { - background-color: #f53c3c; - color: #ffffff; - animation-name: blink; - animation-duration: 0.5s; - animation-timing-function: linear; - animation-iteration-count: infinite; - animation-direction: alternate; -} - -/* -label:focus { - background-color: #000000; -} -*/ diff --git a/nix/home-manager/programs/waybar.nix b/nix/home-manager/programs/waybar.nix index c228404..106e397 100644 --- a/nix/home-manager/programs/waybar.nix +++ b/nix/home-manager/programs/waybar.nix @@ -10,7 +10,8 @@ programs.waybar = { enable = true; package = repoFlake.inputs.nixpkgs-wayland.outputs.packages.${pkgs.stdenv.hostPlatform.system}.waybar; - # style = pkgs.lib.readFile ./waybar.css; + style = pkgs.lib.readFile "${pkgs.waybar.src}/resources/style.css" + + pkgs.lib.readFile ./waybar.css; systemd.enable = true; settings = { mainBar = { @@ -44,7 +45,7 @@ "cpu" "memory" - "temperature" + "custom/cputemp" "custom/fan" "battery" "pulseaudio" @@ -60,19 +61,24 @@ hwmon-path = "/sys/class/hwmon/hwmon3/temp1_input"; format = " {temperatureC} °C"; }; - "custom/fan" = { + "custom/cputemp" = { + format = " {}"; + exec = "${pkgs.lm_sensors}/bin/sensors | ${pkgs.gawk}/bin/awk '/CPU:/ {print $2}'"; + interval = 2; + }; + "custom/fan" = { format = "  {} rpm "; exec = "${pkgs.lm_sensors}/bin/sensors | ${pkgs.gawk}/bin/awk '/fan1:/ {print $2}'"; - interval = 5; + interval = 2; }; battery.format = "🔋 {}%"; pulseaudio = { format = "🔉 {volume}%"; # on-click-middle = ''${pkgs.sway}/bin/swaymsg exec "${pkgs.pavucontrol}/bin/pavucontrol"''; }; - "clock#date".format = "{:%d %b %Y}"; clock.format = "{:%H:%M %p}"; + "clock#date".format = "{:%a, %d %b '%y}"; }; }; }; diff --git a/nix/os/devices/steveej-t14/hw.nix b/nix/os/devices/steveej-t14/hw.nix index 551617e..01b8e7b 100644 --- a/nix/os/devices/steveej-t14/hw.nix +++ b/nix/os/devices/steveej-t14/hw.nix @@ -16,6 +16,71 @@ in { diskId = "nvme-WD_BLACK_SN850X_4000GB_2227DT443901"; }; + # see https://linrunner.de/tlp/ + services.tlp = { + enable = true; + settings = { + CPU_SCALING_GOVERNOR_ON_AC = "schedutil"; + CPU_SCALING_GOVERNOR_ON_BAT = "schedutil"; + + CPU_ENERGY_PERF_POLICY_ON_AC="balance_power"; + CPU_ENERGY_PERF_POLICY_ON_BAT="power"; + + SCHED_POWERSAVE_ON_AC="1"; + SCHED_POWERSAVE_ON_BAT="1"; + + CPU_BOOST_ON_AC="0"; + CPU_BOOST_ON_BAT="0"; + + + RADEON_DPM_PERF_LEVEL_ON_AC="auto"; + RADEON_DPM_PERF_LEVEL_ON_BAT="low"; + RADEON_DPM_STATE_ON_AC="balanced"; + RADEON_DPM_STATE_ON_BAT="battery"; + + SOUND_POWER_SAVE_ON_AC="1"; + SOUND_POWER_SAVE_ON_BAT="1"; + + # PLATFORM_PROFILE_ON_AC="low-power"; + # PLATFORM_PROFILE_ON_BAT="low-power"; + PLATFORM_PROFILE_ON_AC="balanced"; + PLATFORM_PROFILE_ON_BAT="low-power"; + + RUNTIME_PM_ON_AC = "auto"; + RUNTIME_PM_ON_BAT = "auto"; + + PCIE_ASPM_ON_AC="default"; + PCIE_ASPM_ON_BAT="powersave"; + + START_CHARGE_THRESH_BAT0 = "75"; + STOP_CHARGE_THRESH_BAT0 = "80"; + + WOL_DISABLE="Y"; + WIFI_PWR_ON_AC="on"; + WIFI_PWR_ON_BAT="on"; + DEVICES_TO_DISABLE_ON_STARTUP="wwan"; + #DEVICES_TO_DISABLE_ON_LAN_CONNECT="wifi wwan"; + #DEVICES_TO_DISABLE_ON_WIFI_CONNECT="wwan"; + #DEVICES_TO_DISABLE_ON_WWAN_CONNECT="wifi"; + }; + }; + + services.thinkfan = { + enable = true; + levels = [ + [0 0 55] + [1 55 65] + [1 65 75] + [3 75 78] + [4 78 80] + [5 80 82] + [6 82 84] + [7 84 86] + ["level full-speed" 86 999] + ]; + }; + + # boot.initrd.availableKernelModules = stage1Modules; boot.initrd.kernelModules = stage1Modules; }