NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.99k stars 14.01k forks source link

Allow in logind to specify a delay for hibernating when using "sleep-then-hibernating" #281081

Open mpapamanz opened 9 months ago

mpapamanz commented 9 months ago

Describe the bug

Per suspend-then-hibernate documentation, the system can hibernate in 2 cases

  1. When the battery is <= 5% (pretty risky for the battery imo but better than 0%)
  2. After n seconds when HibernateDelaySec=n (in the [Sleep] section of logind.conf) is set

Currently logind.nix doesn't allow to set HibernateDelaySec (nor any other parameter in [Sleep] if I read the nix file correctly).

Steps To Reproduce

Steps to reproduce the behavior:

  1. Set `services.logind.lidSwitch = "sleep-then-hibernate"
  2. Get confused there isn't a services.logind.hibernateDelay
  3. File this bug :smile:

Expected behavior

Have a services.logind.hibernateDelay (or similar) option that sets

HibernateDelaySec=

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

This is relevant for a laptop that, for example, it is used at a desk. Then it is necessary to go to a meeting and open the laptop from the meeting room (without waiting 1m till the system is restored from disk). On the other hand, it is desirable at the end of the day when the lid is closed for good that the system is hibernate and the additional restore time is acceptable. This can be achieved with sleep-then-hibernate + HibernateDelaySec set to 30m (or something like that)

Having only sleep causes overheating when the laptop is carried around, (relatively) fast battery draining and risking to damage the battery if it reaches 0% (current batteries get damaged when they reach <5-10%) Having only hibernate is inconvenient when the lid is closed for a small amount of time (e.g., time to go to a meeting room)

Notify maintainers

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

` - system:"x86_64-linux"`


Add a :+1: reaction to issues you find important.

mpapamanz commented 9 months ago

Filing a bug in case I missed something or there is already someone working on it. Please let me know if you want me to implement this (it seems a pretty trivial configuration piping from nix to logind.conf and I should be able to contribute to it even if new to Nix)

MithicSpirit commented 4 months ago

I believe that this should be in the [Sleep] section of sleep.conf, not of logind.conf. Such an option should thus be added to services.sleep, which would need to be created. Other options that should be added to such are also in the documentation linked above.