# Prevent laptop from suspending when lid is closed if on AC

**URL:** https://discourse.nixos.org/t/prevent-laptop-from-suspending-when-lid-is-closed-if-on-ac/12630
**Category:** Help
**Created:** [April 23, 2021, 12:00am UTC](https://discourse.nixos.org/t/prevent-laptop-from-suspending-when-lid-is-closed-if-on-ac/12630 "2021-04-23T00:00:09Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![epowell](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/e/4bbf92/32.png) [@epowell](https://discourse.nixos.org/u/epowell)
#### Post date: [August 27, 2024, 12:20am UTC](https://discourse.nixos.org/t/prevent-laptop-from-suspending-when-lid-is-closed-if-on-ac/12630/6 "2024-08-27T00:20:09Z")

</div>

I needed to do this below. I don’t think `services.logind.lidSwitchExternalPower` was doing anything for me. After below (and a restart seemed necessary), I can ssh in after hours of idle time. Plus, I can do `sudo reboot` from an ssh session, it will end my session, the laptop will reboot, and then I can ssh back in a minute or two later.:

```auto
  # Enable automatic login for the user.
  services.displayManager.autoLogin.enable = true;
  services.displayManager.autoLogin.user = "eric";

  # Workaround for GNOME autologin: https://github.com/NixOS/nixpkgs/issues/103746#issuecomment-945091229
  systemd.services."getty@tty1".enable = false;
  systemd.services."autovt@tty1".enable = false;

  systemd.sleep.extraConfig = ''
    AllowSuspend=no
    AllowHibernation=no
    AllowHybridSleep=no
    AllowSuspendThenHibernate=no
  '';

```

---

_[View the full topic](https://discourse.nixos.org/t/prevent-laptop-from-suspending-when-lid-is-closed-if-on-ac/12630)._
