Jump to content

Systemd/logind: Difference between revisions

From NixOS Wiki
Norude (talk | contribs)
explained the powerKey, rebootKey, suspendKey, hibernateKey and lidSwitch options
Ardenet (talk | contribs)
reposition translate tag to reduce translation chage
Tags: Mobile edit Mobile web edit Visual edit
Line 10: Line 10:
<translate>
<translate>
== Handling of power keys == <!--T:3-->
== Handling of power keys == <!--T:3-->
</translate>
 
<translate>
<!--T:4-->
<!--T:4-->
<code>logind</code> handles power and standby hardware switches. The Arch wiki has a [https://wiki.archlinux.org/index.php/Power_management#ACPI_events good overview of which ACPI events are handled].
<code>logind</code> handles power and standby hardware switches. The Arch wiki has a [https://wiki.archlinux.org/index.php/Power_management#ACPI_events good overview of which ACPI events are handled].
</translate>
 
<translate>
=== Don’t shutdown on power button press === <!--T:5-->
=== Don’t shutdown on power button press === <!--T:5-->
</translate>
 
<translate>
<!--T:6-->
<!--T:6-->
On a laptop, you often don’t want an accidental short press of the power button to shut down your system, but instead to <code>suspend</code> or <code>hibernate</code>. You can add the following snippet to your <code>logind</code> config:
On a laptop, you often don’t want an accidental short press of the power button to shut down your system, but instead to <code>suspend</code> or <code>hibernate</code>. You can add the following snippet to your <code>logind</code> config:
</translate>
</translate>
<translate>
 
<!--T:7-->
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
services.logind.powerKey = "suspend";
services.logind.powerKey = "suspend";
</syntaxhighlight>
</syntaxhighlight>
</translate>
 
<translate>
<translate>
<!--T:8-->
<!--T:8-->
If you want to ignore short presses of the power button entirely, you can use the following snippet instead:
If you want to ignore short presses of the power button entirely, you can use the following snippet instead:
</translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
services.logind.powerKey = "ignore";
services.logind.powerKey = "ignore";
</syntaxhighlight>
</syntaxhighlight>


<translate>
Long-pressing your power button (5 seconds or longer) to do a hard reset is handled by your machine’s BIOS/EFI and thus still possible.
Long-pressing your power button (5 seconds or longer) to do a hard reset is handled by your machine’s BIOS/EFI and thus still possible.
Similar to the power key, you can ignore the reboot, suspend and hibernate keys like this:
</translate>
</translate>
<translate>
 
Similar to the power key, you can ignore the reboot, suspend and hibernate keys like this:<syntaxhighlight lang="nixos">
<syntaxhighlight lang="nixos">
services.logind.rebootKey = "ignore";
services.logind.rebootKey = "ignore";
services.logind.suspendKey = "ignore";
services.logind.suspendKey = "ignore";
services.logind.hibernateKey = "ignore";
services.logind.hibernateKey = "ignore";
</syntaxhighlight>


</syntaxhighlight>Or ignore the action of closing/opening the lid on laptops like this:<syntaxhighlight lang="nixos">
<translate>
Or ignore the action of closing/opening the lid on laptops like this:
</translate>
 
<syntaxhighlight lang="nixos">
services.logind.lidSwitch = "ignore";
services.logind.lidSwitch = "ignore";
</syntaxhighlight></translate>
</syntaxhighlight>
 
<translate>
<translate>
=== Ignore hardware keys when using <code>systemd-inhibit</code> === <!--T:9-->
=== Ignore hardware keys when using <code>systemd-inhibit</code> === <!--T:9-->
</translate>
 
<translate>
<!--T:10-->
<!--T:10-->
<code>systemd-inhibit</code> allows you to put a lock on e.g. shutdown or sleep that is in place as long the given process is running. By default, the hardware key actions configured in <code>logind</code> override such inhibits.
<code>systemd-inhibit</code> allows you to put a lock on e.g. shutdown or sleep that is in place as long the given process is running. By default, the hardware key actions configured in <code>logind</code> override such inhibits.
</translate>
 
<translate>
<!--T:11-->
<!--T:11-->
Say you want your laptop to stay awake when closing the lid in some circumstances, for example if you want to listen to music. If you start your lock screen with an inhibit on the lid switch
Say you want your laptop to stay awake when closing the lid in some circumstances, for example if you want to listen to music. If you start your lock screen with an inhibit on the lid switch
</translate>
 
<code>
<code>systemd-inhibit --what=handle-lid-switch lock-screen-tool</code>
systemd-inhibit --what=handle-lid-switch lock-screen-tool
 
</code>
<translate>
<!--T:12-->
<!--T:12-->
<code>logind</code> still overrides that user decision. For it to work, you need to tell logind to ignore the lid switch in your system config:
<code>logind</code> still overrides that user decision. For it to work, you need to tell logind to ignore the lid switch in your system config:
</translate>
</translate>
<translate>
 
<!--T:13-->
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
services.logind.extraConfig = ''
services.logind.extraConfig = ''
Line 72: Line 74:
'';
'';
</syntaxhighlight>
</syntaxhighlight>
</translate>
 
<translate>
[[Category:Applications]]
[[Category:Applications]]
[[Category:systemd]]
[[Category:systemd]]
</translate>

Revision as of 21:40, 7 October 2025

←︎
Back to Systemd

logind is systemd’s login manager. Its main manual page is systemd-logind.service(8). Its configuration options are described in logind.conf(5).

Handling of power keys

logind handles power and standby hardware switches. The Arch wiki has a good overview of which ACPI events are handled.

Don’t shutdown on power button press

On a laptop, you often don’t want an accidental short press of the power button to shut down your system, but instead to suspend or hibernate. You can add the following snippet to your logind config:

services.logind.powerKey = "suspend";

If you want to ignore short presses of the power button entirely, you can use the following snippet instead:

services.logind.powerKey = "ignore";

Long-pressing your power button (5 seconds or longer) to do a hard reset is handled by your machine’s BIOS/EFI and thus still possible.

Similar to the power key, you can ignore the reboot, suspend and hibernate keys like this:

services.logind.rebootKey = "ignore";
services.logind.suspendKey = "ignore";
services.logind.hibernateKey = "ignore";

Or ignore the action of closing/opening the lid on laptops like this:

services.logind.lidSwitch = "ignore";

Ignore hardware keys when using systemd-inhibit

systemd-inhibit allows you to put a lock on e.g. shutdown or sleep that is in place as long the given process is running. By default, the hardware key actions configured in logind override such inhibits.

Say you want your laptop to stay awake when closing the lid in some circumstances, for example if you want to listen to music. If you start your lock screen with an inhibit on the lid switch

systemd-inhibit --what=handle-lid-switch lock-screen-tool

logind still overrides that user decision. For it to work, you need to tell logind to ignore the lid switch in your system config:

services.logind.extraConfig = ''
  # want to be able to listen to music while laptop closed
  LidSwitchIgnoreInhibited=no
'';