From 4e547fd74af59abfe916f52295b27bc9c69a3f0c Mon Sep 17 00:00:00 2001 From: Tomas Rivera <137088692+Totorile1@users.noreply.github.com> Date: Sat, 28 Feb 2026 10:05:53 +0100 Subject: [PATCH] Corrected some bugs with waybar and added tlp --- hosts/laptop/configuration.nix | 2 ++ modules/home-manager/waybar.nix | 22 ++++++++-------- modules/nixos/battery.nix | 45 +++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 modules/nixos/battery.nix diff --git a/hosts/laptop/configuration.nix b/hosts/laptop/configuration.nix index 7cb34a5..bd68901 100755 --- a/hosts/laptop/configuration.nix +++ b/hosts/laptop/configuration.nix @@ -9,6 +9,7 @@ [ # Include the results of the hardware scan. ./hardware-configuration.nix inputs.home-manager.nixosModules.default + ../../modules/nixos/battery.nix ]; @@ -150,6 +151,7 @@ gcc # GNU C compiler libreoffice gruvbox-gtk-theme hyprpicker +power-profiles-daemon #we need to install gnome and kde utils individually as we dont use gnome gnome-calculator snapshot diff --git a/modules/home-manager/waybar.nix b/modules/home-manager/waybar.nix index 84784f6..ea8fd91 100644 --- a/modules/home-manager/waybar.nix +++ b/modules/home-manager/waybar.nix @@ -34,7 +34,7 @@ transition-duration = 500; transition-left-to-right = false; }; - items = [ + modules = [ "pulseaudio" "pulseaudio#mic" "pulseaudio/slider" @@ -46,7 +46,7 @@ transition-duration = 500; transition-left-to-right = true; }; - items = [ + modules = [ "bluetooth" "bluetooth#status" ]; @@ -57,18 +57,18 @@ transition-duration = 500; transition-left-to-right = false; }; - items = [ + modules = [ "backlight" "backlight/slider" ]; }; "group/connection" = { orientation = "inherit"; - items = [ "group/network" ]; + modules = [ "group/network" ]; }; "group/gcpu" = { orientation = "inherit"; - items = [ + modules = [ "custom/cpu-icon" "temperature" "cpu" @@ -76,7 +76,7 @@ }; "group/info" = { orientation = "inherit"; - items = [ + modules = [ "group/gcpu" "memory" "disk" @@ -88,7 +88,7 @@ transition-duration = 500; transition-left-to-right = true; }; - items = [ + modules = [ "network" "network#speed" ]; @@ -99,21 +99,21 @@ transition-duration = 500; transition-left-to-right = false; }; - items = [ + modules = [ "battery" "power-profiles-daemon" ]; }; "group/sound" = { orientation = "inherit"; - items = [ + modules = [ "group/audio" "custom/notification" ]; }; "group/together" = { orientation = "inherit"; - items = [ + modules = [ "group/utils" "clock" ]; @@ -124,7 +124,7 @@ transition-duration = 500; transition-left-to-right = true; }; - items = [ + modules = [ "custom/weather" "custom/colorpicker" ]; diff --git a/modules/nixos/battery.nix b/modules/nixos/battery.nix new file mode 100644 index 0000000..3971ef6 --- /dev/null +++ b/modules/nixos/battery.nix @@ -0,0 +1,45 @@ +# https://discourse.nixos.org/t/what-is-the-best-option-for-power-management/63406/2 +{ + config, + lib, + vars, + ... +}: let + cfg = config.custom; + hasBattery = + lib.any (x: lib.strings.hasPrefix "BAT" x) + (builtins.attrNames (builtins.readDir "/sys/class/power_supply")); +in { + options.custom = { + battery.enable = lib.mkOption { + default = hasBattery; + description = "Enable better battery support"; + type = lib.types.bool; + }; + }; + + config = lib.mkIf cfg.battery.enable { + powerManagement.powertop.enable = true; # enable powertop auto tuning on startup. + + services.system76-scheduler.settings.cfsProfiles.enable = true; # Better scheduling for CPU cycles - thanks System76!!! + services.thermald.enable = true; # Enable thermald, the temperature management daemon. (only necessary if on Intel CPUs) + services.power-profiles-daemon.enable = false; # Disable GNOMEs power management + services.tlp = { + enable = true; # Enable TLP (better than gnomes internal power manager) + settings = { + CPU_BOOST_ON_AC = 1; + CPU_BOOST_ON_BAT = 1; + CPU_HWP_DYN_BOOST_ON_AC = 1; + CPU_HWP_DYN_BOOST_ON_BAT = 1; + CPU_SCALING_GOVERNOR_ON_AC = "performance"; + CPU_SCALING_GOVERNOR_ON_BAT = "powersave"; + CPU_ENERGY_PERF_POLICY_ON_AC = "performance"; + CPU_ENERGY_PERF_POLICY_ON_BAT = "balance_power"; + PLATFORM_PROFILE_ON_AC = "performance"; + PLATFORM_PROFILE_ON_BAT = "balanced"; + START_CHARGE_THRESH_BAT0 = 75; + STOP_CHARGE_THRESH_BAT0 = 81; + }; + }; + }; +}