[audio] Adds script to inhibit sleep while media is playing.

This commit is contained in:
2025-12-30 11:05:10 -08:00
parent 889d0b1057
commit b951779a92

View File

@@ -1,7 +1,41 @@
{ pkgs, ... }:
with pkgs;
let
# A script that runs as long as media is playing.
isMediaPlaying = writeShellApplication {
name = "isMediaPlaying";
runtimeInputs = [
playerctl
];
text = ''
set -e
while [ "$(playerctl status)" = "Playing" ]; do
echo -n "."
sleep 1
done
'';
};
# A script that prevents the system from going to sleep while media is playing
mediaCaffeine = writeShellApplication {
name = "media-caffeine";
runtimeInputs = [
isMediaPlaying
systemd
];
text = ''
set -e
systemd-inhibit --what=sleep --why="Media is playing" --mode=block isMediaPlaying
'';
};
in
{
home.packages = with pkgs; [
pulseaudio # for pactl and other tools
pavucontrol # GUI volume control with lots of options
mediaCaffeine
];
}