{ lib, pkgs, config, ...}: let inherit (lib) mkIf mkEnableOption mkOption; cfg = config.chuj.stuff.mpd; user = config.chuj.system.user; in { options.chuj.stuff.mpd = { enable = mkEnableOption "mpd"; statusFile = mkOption { type = lib.types.str; default = "/tmp/mpdstatus"; }; mpdstatusPackage = mkOption { type = lib.types.package; default = let sleep = lib.getExe' pkgs.coreutils "sleep"; cut = lib.getExe' pkgs.coreutils "cut"; basename = lib.getExe' pkgs.coreutils "basename"; echo = lib.getExe' pkgs.coreutils "echo"; mpc = lib.getExe pkgs.mpc-cli; sed = lib.getExe pkgs.gnused; in (pkgs.writeShellScriptBin "mpdstatus" '' trap "echo SIG" USR1 EXIT while true; do ${sleep} 1 & wait status=$(${mpc} status | ${sed} -n 2p | ${cut} -d' ' -f1) title=$(${basename} "$(${mpc} current -f '%file%')" .mp3) ${echo} "$status $title" > ${config.chuj.stuff.mpd.statusFile} done ''); }; }; config = mkIf cfg.enable { home-manager.users.${user} = { services.mpd = { enable = true; extraConfig = '' audio_output { type "pulse" name "PulseAudio Output" } ''; }; home.packages = [ pkgs.mpc-cli config.chuj.stuff.mpd.mpdstatusPackage ]; }; }; }