How to disable suspend on close laptop lid on NixOS

acpilaptopnixossuspend

I'm using NixOS on a laptop and want to disable auto-suspension that happens every time I close the laptop lid. Approach described in “How to disable auto suspend when I close laptop lid?”, that is, editing /etc/systemd/logind.conf won't work, as it is just a symlink to /etc/static/systemd/logind.conf, which itself is a symlink to a file in /nix/store.

AFAIK, you shouldn't edit the Nix store directly, although I'm not entirely sure what would happen if I did. But the file in /nix/store doesn't have write permissions anyway.

How do I disable auto-suspension of a laptop in a NixOS idiomatic way?

Best Answer

While the solution proposed by Mirzhan will probably work, there is a much more elegant way using the services.logind.lidSwitch and services.logind.lidSwitchDocked options.

Now, you can just write

services.logind.lidSwitch = "ignore";

These options also have types provided so an invalid configuration would be detected at build time.

Related Question