Power Management: Difference between revisions

Clarified that solutions may vary when troubleshooting a blocked pre-sleep.service
Replace deprecated sleep extraConfig option that was missed last edit
 
(3 intermediate revisions by 2 users not shown)
Line 30: Line 30:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
  systemd.services.your-service-name = {  
systemd.services.your-service-name = {  
    description = "Service description here";
  description = "Service description here";
    wantedBy = [ "post-resume.target" ];
  wantedBy = [ "post-resume.target" ];
    after = [ "post-resume.target" ];
  after = [ "post-resume.target" ];
    script = ''
  script = ''
     echo "This should show up in the journal after resuming."
     echo "This should show up in the journal after resuming."
    '';
  '';
    serviceConfig.Type = "oneshot";
  serviceConfig.Type = "oneshot";
  };
};
</syntaxhighlight>
</syntaxhighlight>


Line 48: Line 48:


Therefore, an example configuration could look like this:<syntaxhighlight lang="nix">
Therefore, an example configuration could look like this:<syntaxhighlight lang="nix">
/*
// I'm hibernating into a logical volume that's also under LUKS. Pretty cool, right?
  I'm hibernating into a logical volume that's also under LUKS. Pretty cool, right?
*/


swapDevices = [
swapDevices = [
Line 69: Line 67:
== Tips and tricks ==
== Tips and tricks ==


=== Go into hibernate after specific suspend time ===
=== Hibernate after specified time ===
Using following configuration, your system will go from suspend into hibernate after 1 hour:<syntaxhighlight lang="nix">
Using following configuration, your system will go from suspend into hibernate after 1 hour:<syntaxhighlight lang="nix">
systemd.sleep.extraConfig = ''
systemd.sleep.settings.Sleep = {
   HibernateDelaySec=1h
   HibernateDelaySec = "1h";
'';
};
</syntaxhighlight>
</syntaxhighlight>


Or, to disable suspend entirely, consider a configuration like this:
=== Disable all sleep functionality ===
 
Some desktop environment and display manager combinations might attempt to put your machine to sleep as default behavior (i.e. SDDM and KDE Plasma 6 under Wayland).  If this is not what you want, you can define the following to block any service attempting to put your machine to sleep via systemd:
 
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
systemd.sleep.extraConfig = ''
systemd.sleep.settings.Sleep = {
   AllowSuspend=no
   AllowHibernation = "no";
   AllowHibernation=no
   AllowHybridSleep = "no";
   AllowHybridSleep=no
   AllowSuspend = "no";
   AllowSuspendThenHibernate=no
   AllowSuspendThenHibernate = "no";
'';
};
</syntaxhighlight>
</syntaxhighlight>