From c5ef752a66f742002f011a25b9eb2feb11520330 Mon Sep 17 00:00:00 2001 From: smayzy Date: Thu, 24 Jul 2025 14:21:53 +0200 Subject: [PATCH] clean modules & add power modes --- modules/nix/audio/pipewire.nix | 2 +- modules/nix/base-cli/nh.nix | 2 +- modules/nix/base/base.nix | 2 +- modules/nix/browser/firefox.nix | 2 +- modules/nix/de/kde.nix | 2 +- modules/nix/displaymanager/sddm.nix | 2 +- modules/nix/flatpak/flatpak.nix | 2 +- modules/nix/groups/base.nix | 2 +- modules/nix/groups/desktop.nix | 3 +- modules/nix/groups/laptop.nix | 4 +-- modules/nix/hardware/default.nix | 1 + modules/nix/hardware/grub.nix | 2 +- modules/nix/hardware/nvidia.nix | 2 +- modules/nix/hardware/power.nix | 50 +++++++++++++++++++++++++++++ 14 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 modules/nix/hardware/power.nix diff --git a/modules/nix/audio/pipewire.nix b/modules/nix/audio/pipewire.nix index 9e71fd5..3c65741 100644 --- a/modules/nix/audio/pipewire.nix +++ b/modules/nix/audio/pipewire.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ config, lib, ... }: let inherit (lib) mkIf mkOption types; in diff --git a/modules/nix/base-cli/nh.nix b/modules/nix/base-cli/nh.nix index 96dab9a..2e558a6 100644 --- a/modules/nix/base-cli/nh.nix +++ b/modules/nix/base-cli/nh.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ...}: +{ config, lib, ...}: let inherit (lib) mkIf mkOption types; in diff --git a/modules/nix/base/base.nix b/modules/nix/base/base.nix index 17c7aea..5dfed36 100644 --- a/modules/nix/base/base.nix +++ b/modules/nix/base/base.nix @@ -1,4 +1,4 @@ -{ lib, config, pkgs, ... }: +{ lib, config, ... }: let inherit (lib) mkIf mkOption types; in diff --git a/modules/nix/browser/firefox.nix b/modules/nix/browser/firefox.nix index 66626a8..b51910e 100644 --- a/modules/nix/browser/firefox.nix +++ b/modules/nix/browser/firefox.nix @@ -1,4 +1,4 @@ -{ lib, config, pkgs, ... }: +{ lib, config, ... }: let inherit (lib) mkIf mkOption types; in diff --git a/modules/nix/de/kde.nix b/modules/nix/de/kde.nix index 7314b6d..f7b487d 100644 --- a/modules/nix/de/kde.nix +++ b/modules/nix/de/kde.nix @@ -1,4 +1,4 @@ -{ lib, config, pkgs, ... }: +{ lib, config, ... }: let inherit (lib) mkIf mkOption types; in diff --git a/modules/nix/displaymanager/sddm.nix b/modules/nix/displaymanager/sddm.nix index f1a32bd..2ea1902 100644 --- a/modules/nix/displaymanager/sddm.nix +++ b/modules/nix/displaymanager/sddm.nix @@ -1,4 +1,4 @@ -{ lib, config, pkgs, ... }: +{ lib, config, ... }: let inherit (lib) mkIf mkOption types; in diff --git a/modules/nix/flatpak/flatpak.nix b/modules/nix/flatpak/flatpak.nix index d35d73a..12c6818 100644 --- a/modules/nix/flatpak/flatpak.nix +++ b/modules/nix/flatpak/flatpak.nix @@ -1,4 +1,4 @@ -{ lib, config, pkgs, ... }: +{ lib, config, ... }: let inherit (lib) mkIf mkOption types; diff --git a/modules/nix/groups/base.nix b/modules/nix/groups/base.nix index 0a662c4..518769c 100644 --- a/modules/nix/groups/base.nix +++ b/modules/nix/groups/base.nix @@ -1,4 +1,4 @@ -{ lib, config, pkgs, ... }: +{ lib, config, ... }: let inherit (lib) mkIf mkOption types; in diff --git a/modules/nix/groups/desktop.nix b/modules/nix/groups/desktop.nix index 1a2e93b..0f26509 100644 --- a/modules/nix/groups/desktop.nix +++ b/modules/nix/groups/desktop.nix @@ -1,4 +1,4 @@ -{ lib, config, pkgs, ... }: +{ lib, config, ... }: let inherit (lib) mkIf mkOption types; in @@ -12,6 +12,7 @@ in config = mkIf config.smayzy.desktop.enable { smayzy = { base = true; + power = "desktop"; steam.enable = true; prism.enable = true; firefox.enable = true; diff --git a/modules/nix/groups/laptop.nix b/modules/nix/groups/laptop.nix index e653992..411397d 100644 --- a/modules/nix/groups/laptop.nix +++ b/modules/nix/groups/laptop.nix @@ -1,4 +1,4 @@ -{ lib, config, pkgs, ... }: +{ lib, config, ... }: let inherit (lib) mkIf mkOption types; in @@ -12,6 +12,7 @@ in config = mkIf config.smayzy.laptop.enable { smayzy = { base = true; + power = "laptop"; grub-on-lap.enable = true; prism.enable = true; firefox.enable = true; @@ -43,6 +44,5 @@ in fritzing.enable = true; aegisub.enable = true; }; - services.logind.lidSwitch = "ignore"; }; } diff --git a/modules/nix/hardware/default.nix b/modules/nix/hardware/default.nix index d7204aa..0f13c7c 100644 --- a/modules/nix/hardware/default.nix +++ b/modules/nix/hardware/default.nix @@ -3,5 +3,6 @@ imports = [ ./nvidia.nix ./grub.nix + ./power.nix ]; } diff --git a/modules/nix/hardware/grub.nix b/modules/nix/hardware/grub.nix index d451d1c..fc418f4 100644 --- a/modules/nix/hardware/grub.nix +++ b/modules/nix/hardware/grub.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ config, lib, ... }: with lib; diff --git a/modules/nix/hardware/nvidia.nix b/modules/nix/hardware/nvidia.nix index eea7c3f..fd41ecf 100644 --- a/modules/nix/hardware/nvidia.nix +++ b/modules/nix/hardware/nvidia.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ config, lib, ... }: let inherit (lib) mkIf mkOption types; in diff --git a/modules/nix/hardware/power.nix b/modules/nix/hardware/power.nix new file mode 100644 index 0000000..b6acb8c --- /dev/null +++ b/modules/nix/hardware/power.nix @@ -0,0 +1,50 @@ +{ config, lib, ... }: +let + inherit (lib) mkIf mkOption types mkMerge; + validOptions = [ "desktop" "laptop" ]; +in +{ + options.smayzy.power = mkOption { + type = types.enum validOptions; + default = "desktop"; + description = "chose power mode between desktop and laptop"; + }; + + config = mkMerge [ + (mkIf (config.smayzy.power == "desktop") { + services.power-profiles-daemon.enable = false; + services.auto-cpufreq = { + enable = true; + settings = { + charger = { + governor = "performance"; + turbo = "auto"; + }; + }; + }; + }) + + (mkIf (config.smayzy.power == "laptop") { + services.logind.lidSwitch = "suspend"; + services.power-profiles-daemon.enable = false; + services.tlp = { + enable = true; + settings = { + CPU_SCALING_GOVERNOR_ON_AC = "performance"; + CPU_SCALING_GOVERNOR_ON_BAT = "powersave"; + + CPU_ENERGY_PERF_POLICY_ON_BAT = "power"; + CPU_ENERGY_PERF_POLICY_ON_AC = "performance"; + + CPU_MIN_PERF_ON_AC = 0; + CPU_MAX_PERF_ON_AC = 100; + CPU_MIN_PERF_ON_BAT = 0; + CPU_MAX_PERF_ON_BAT = 100; + + STOP_CHARGE_THRESH_BAT0 = 95; + }; + }; + }) + + ]; +}