Use case: docking in a laptop to a specific external screen.
the screen should be possible to detect with kscreendoctor and then I assume systemd-inhibit would be the preferred way of blocking sleep?
External monitors tend to take a while to wake up again, which is the reason for the idea
My attempt
[Unit]
Description=Inhibit sleep if HDMI display is connected
After=graphical.target
[Service]
Type=oneshot
RemainAfterExit=no
ExecPre=/bin/sh -c 'kscreen-doctor -o | grep -q HDMI || exit 1'
ExecStart=/bin/sh -c 'systemd-inhibit --what=idle:sleep --why="HDMI display connected" --mode=block sleep infinity'
Restart=always
RestartSec=5 min
[Install]
WantedBy=multi-user.target
in Nix:
{ config, lib, pkgs, ... }:
{
# Inhibit sleep
systemd = {
services.hdmi-inhibit-sleep = {
description = "Inhibit system sleep when external monitor is connected";
requires = [ "graphical.target" ];
unitConfig = {
Type="oneshot"; #default
ExecPre="/bin/sh -c 'kscreen-doctor -o | grep -q HDMI || exit 1'";
ExecStart="/bin/sh -c 'systemd-inhibit --what=idle:sleep --why="HDMI display connected" --mode=block sleep infinity'";
};
serviceConfig = {
Restart = "on-failure";
RestartSec = "5 min";
User="user";
};
WantedBy="multi-user.target";
};
};
}