Prevent laptop from suspending when lid is closed if on AC

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.:

  # 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
  '';
1 Like