diff --git a/home-manager/features/audio.nix b/home-manager/features/audio.nix index 8f06d87..f9a8b54 100644 --- a/home-manager/features/audio.nix +++ b/home-manager/features/audio.nix @@ -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 ]; + }