|
245 | 245 | ''; |
246 | 246 | }; |
247 | 247 |
|
| 248 | + genericSleepConf = '' |
| 249 | + AllowHibernation=no |
| 250 | + AllowHybridSleep=no |
| 251 | + AllowSuspendThenHibernate=no |
| 252 | + '' |
| 253 | + + optionalString (!cfg.suspend.enable) '' |
| 254 | + AllowSuspend=no |
| 255 | + ''; |
| 256 | + |
248 | 257 | in |
249 | 258 | { |
250 | 259 | options.ghaf.services.power-manager = { |
|
280 | 289 | ''; |
281 | 290 | }; |
282 | 291 |
|
283 | | - allowSuspend = mkOption { |
284 | | - type = types.bool; |
285 | | - default = true; |
286 | | - description = '' |
287 | | - Whether to enable system suspension. |
| 292 | + suspend = { |
| 293 | + enable = mkOption { |
| 294 | + type = types.bool; |
| 295 | + default = true; |
| 296 | + description = '' |
| 297 | + Whether to enable system suspension. |
288 | 298 |
|
289 | | - If disabled, the system will not respond to suspend requests, and all VMs with a power management profile enabled are |
290 | | - prohibited to perform any suspend action. |
291 | | - ''; |
| 299 | + If disabled, the system will not respond to suspend requests, and all VMs with a |
| 300 | + power management profile enabled are prohibited to perform any suspend action. |
| 301 | + ''; |
| 302 | + }; |
| 303 | + |
| 304 | + mode = mkOption { |
| 305 | + type = types.nullOr ( |
| 306 | + types.enum [ |
| 307 | + "s2idle" |
| 308 | + "shallow" |
| 309 | + "deep" |
| 310 | + ] |
| 311 | + ); |
| 312 | + default = null; |
| 313 | + description = '' |
| 314 | + The memory suspend mode to use. |
| 315 | +
|
| 316 | + To check which modes are supported, run `cat /sys/power/mem_sleep`. |
| 317 | +
|
| 318 | + More info: https://docs.kernel.org/admin-guide/pm/sleep-states.html |
| 319 | + ''; |
| 320 | + }; |
292 | 321 | }; |
293 | 322 |
|
294 | 323 | vm = { |
|
412 | 441 | } |
413 | 442 | ]; |
414 | 443 |
|
415 | | - # Prohibited sleep actions for VMs |
416 | | - systemd.sleep.extraConfig = '' |
417 | | - AllowHibernation=no |
418 | | - AllowHybridSleep=no |
419 | | - AllowSuspendThenHibernate=no |
420 | | - '' |
421 | | - + optionalString (!cfg.allowSuspend) '' |
422 | | - AllowSuspend=no |
423 | | - ''; |
| 444 | + systemd.sleep.extraConfig = genericSleepConf; |
424 | 445 |
|
425 | 446 | powerManagement = optionalAttrs cfg.vm.enable { |
426 | 447 | powerDownCommands = optionalString cfg.vm.pciSuspend ( |
|
467 | 488 | powerDownCommands = lib.mkBefore '' |
468 | 489 | ${getExe ghaf-powercontrol} turn-off-displays '*' |
469 | 490 | ''; |
| 491 | + powerUpCommands = lib.mkBefore '' |
| 492 | + ${getExe ghaf-powercontrol} turn-on-displays '*' |
| 493 | + ''; |
470 | 494 | }; |
471 | 495 |
|
472 | 496 | # Override systemd actions for suspend, poweroff, and reboot |
|
497 | 521 | # Logind configuration for desktop |
498 | 522 | services.logind.settings.Login = |
499 | 523 | let |
500 | | - lidEvent = if cfg.allowSuspend then "suspend" else "lock"; |
| 524 | + lidEvent = if cfg.suspend.enable then "suspend" else "lock"; |
501 | 525 | in |
502 | 526 | mkDefault { |
503 | 527 | HandleLidSwitch = lidEvent; |
|
519 | 543 | (mkIf cfg.host.enable { |
520 | 544 | services.logind.settings.Login.HandleLidSwitch = mkDefault "ignore"; |
521 | 545 |
|
522 | | - systemd.sleep.extraConfig = '' |
523 | | - AllowHibernation=no |
524 | | - AllowHybridSleep=no |
525 | | - AllowSuspendThenHibernate=no |
526 | | - '' |
527 | | - + optionalString (!cfg.allowSuspend) '' |
528 | | - AllowSuspend=no |
529 | | - ''; |
| 546 | + systemd.sleep.extraConfig = genericSleepConf; |
| 547 | + |
| 548 | + # We can accomplish the same via systemd.sleep.extraConfig MemorySleepMode |
| 549 | + # but it seems keyboard wakeup stops functioning with that approach |
| 550 | + boot.kernelParams = optionals (cfg.suspend.mode != null) [ |
| 551 | + "mem_sleep_default=${cfg.suspend.mode}" |
| 552 | + ]; |
530 | 553 |
|
531 | | - systemd.targets = optionalAttrs cfg.allowSuspend { |
| 554 | + systemd.targets = optionalAttrs cfg.suspend.enable { |
532 | 555 | "pre-sleep-actions" = { |
533 | 556 | description = "Target for pre-sleep host actions"; |
534 | 557 | unitConfig.StopWhenUnneeded = true; |
|
552 | 575 |
|
553 | 576 | systemd.services = mkMerge [ |
554 | 577 | # suspend/resume action units |
555 | | - (optionalAttrs cfg.allowSuspend ( |
| 578 | + (optionalAttrs cfg.suspend.enable ( |
556 | 579 | lib.listToAttrs ( |
557 | 580 | flatten ( |
558 | 581 | map |
|
0 commit comments