Commit 531af35

HPCesia <me@hpcesia.com>
2025-10-25 07:30:41
refactor: plasma laptop power manage
1 parent 200de61
Changed files (2)
modules
desktop
desktop-environment
plasma6
hosts
chaser-kevin
modules/desktop/desktop-environment/plasma6/options/powerdevil.nix
@@ -1,19 +1,67 @@
-{
-  flake.modules.homeManager.de-plasma6 = _: {
+{lib, ...} @ topArgs: {
+  flake.modules.homeManager.de-plasma6 = {osConfig}: let
+    hostMeta = topArgs.config.flake.meta.host.hosts.${osConfig.networking.hostName};
+  in {
     # AC is compatible for all hosts
-    programs.plasma.powerdevil.AC = {
-      powerProfile = "performance";
-      # Auto Power Save
-      autoSuspend.action = "nothing";
-      turnOffDisplay = {
-        idleTimeout = 14400;
-        idleTimeoutWhenLocked = 600;
+    programs.plasma.powerdevil = {
+      AC = {
+        powerProfile = "performance";
+        # Auto Power Save
+        autoSuspend.action = "nothing";
+        turnOffDisplay = {
+          idleTimeout = 14400;
+          idleTimeoutWhenLocked = 600;
+        };
+        dimDisplay.enable = false;
+        # Actions
+        whenLaptopLidClosed = "sleep";
+        whenSleepingEnter = "standby";
+        powerButtonAction = "hibernate";
+        inhibitLidActionWhenExternalMonitorConnected = lib.mkIf hostMeta.isLaptop true;
+      };
+
+      battery = lib.mkIf hostMeta.isLaptop {
+        powerProfile = "powerSaving";
+        # Auto Power Save
+        autoSuspend = {
+          action = "sleep";
+          idleTimeout = 600;
+        };
+        turnOffDisplay = {
+          idleTimeout = 360;
+          idleTimeoutWhenLocked = 120;
+        };
+        dimDisplay = {
+          enable = true;
+          idleTimeout = 120;
+        };
+        # Actions
+        whenLaptopLidClosed = "hibernate";
+        whenSleepingEnter = "standbyThenHibernate";
+        powerButtonAction = "shutDown";
+        inhibitLidActionWhenExternalMonitorConnected = true;
+      };
+      lowBattery = lib.mkIf hostMeta.isLaptop {
+        powerProfile = "powerSaving";
+        # Auto Power Save
+        autoSuspend = {
+          action = "sleep";
+          idleTimeout = 300;
+        };
+        turnOffDisplay = {
+          idleTimeout = 180;
+          idleTimeoutWhenLocked = 60;
+        };
+        dimDisplay = {
+          enable = true;
+          idleTimeout = 60;
+        };
+        # Actions
+        whenLaptopLidClosed = "hibernate";
+        whenSleepingEnter = "standbyThenHibernate";
+        powerButtonAction = "shutDown";
+        inhibitLidActionWhenExternalMonitorConnected = true;
       };
-      dimDisplay.enable = false;
-      # Actions
-      whenLaptopLidClosed = "sleep";
-      whenSleepingEnter = "standby";
-      powerButtonAction = "hibernate";
     };
   };
 }
modules/hosts/chaser-kevin/home/plasma.nix
@@ -3,53 +3,6 @@
     hasPlasma = osConfig.services.desktopManager.plasma6.enable;
   in
     lib.optionalAttrs hasPlasma {
-      # Power Control
-      programs.plasma.powerdevil = {
-        AC.inhibitLidActionWhenExternalMonitorConnected = true;
-        battery = {
-          powerProfile = "powerSaving";
-          # Auto Power Save
-          autoSuspend = {
-            action = "sleep";
-            idleTimeout = 600;
-          };
-          turnOffDisplay = {
-            idleTimeout = 360;
-            idleTimeoutWhenLocked = 120;
-          };
-          dimDisplay = {
-            enable = true;
-            idleTimeout = 120;
-          };
-          # Actions
-          whenLaptopLidClosed = "hibernate";
-          whenSleepingEnter = "standbyThenHibernate";
-          powerButtonAction = "shutDown";
-          inhibitLidActionWhenExternalMonitorConnected = true;
-        };
-        lowBattery = {
-          powerProfile = "powerSaving";
-          # Auto Power Save
-          autoSuspend = {
-            action = "sleep";
-            idleTimeout = 300;
-          };
-          turnOffDisplay = {
-            idleTimeout = 180;
-            idleTimeoutWhenLocked = 60;
-          };
-          dimDisplay = {
-            enable = true;
-            idleTimeout = 60;
-          };
-          # Actions
-          whenLaptopLidClosed = "hibernate";
-          whenSleepingEnter = "standbyThenHibernate";
-          powerButtonAction = "shutDown";
-          inhibitLidActionWhenExternalMonitorConnected = true;
-        };
-      };
-
       programs.plasma.input = {
         touchpads = [
           {