[Services] Use socket-based activation for SSHd and inhibit sleep when connections are active

This commit is contained in:
Antoine Viallon 2023-04-16 17:16:51 +02:00
parent 4ba062d0db
commit acd5467047
Signed by: aviallon
GPG key ID: 186FC35EDEB25716

View file

@ -51,7 +51,22 @@ in {
permitRootLogin = mkDefault "prohibit-password";
forwardX11 = mkDefault config.services.xserver.enable;
openFirewall = true;
startWhenNeeded = true;
};
systemd.services."ssh-inhibit-sleep@" = {
description = "Inhibit sleep when SSH connections are active";
bindsTo = [ "sshd@%i.service" ];
script = ''
exec ${pkgs.systemd}/bin/systemd-inhibit --mode block --what sleep \
--who "ssh session $1" \
--why "remote session still active" \
${pkgs.coreutils}/bin/sleep infinity
'';
scriptArgs = "%I";
wantedBy = [ "sshd@.service" ];
};
programs.ssh.setXAuthLocation = config.services.xserver.enable;
programs.ssh.forwardX11 = mkDefault config.services.xserver.enable;
security.pam.services.sudo.forwardXAuth = mkDefault true; # Easier to start GUI programs as root