{ config, lib, pkgs, ... }: let cfg = config.services.haravara.mpdscribble; in { options.services.haravara.mpdscribble = { enable = lib.mkEnableOption "mpdscribble"; username = lib.mkOption { type = lib.types.str; default = ""; description = "Username for the scrobbling service"; }; passwordFile = lib.mkOption { type = lib.types.nullOr lib.types.path; default = null; description = "Path to the secret file containing the password or MD5 hash"; }; serviceUrl = lib.mkOption { type = lib.types.str; default = "https://post.audioscrobbler.com/"; description = "URL of the scrobbling service"; }; mpdHostFile = lib.mkOption { type = lib.types.nullOr lib.types.path; default = null; description = "Path to the secret file"; }; mpdPort = lib.mkOption { type = lib.types.port; default = 6600; }; }; config = lib.mkIf cfg.enable { systemd.services.mpdscribble = { description = "mpdscribble scrobbler"; after = ["network.target"]; wantedBy = ["multi-user.target"]; environment = { XDG_DATA_HOME = "/var/lib/mpdscribble"; }; serviceConfig = { LoadCredential = lib.concatLists [ (lib.optional (cfg.mpdHostFile != null) "mpd_host:${toString cfg.mpdHostFile}") (lib.optional (cfg.passwordFile != null) "password:${toString cfg.passwordFile}") ]; ExecStart = pkgs.writeShellScript "mpdscribble-start" '' CONF_FILE="$STATE_DIRECTORY/mpdscribble.conf" MPD_HOST="localhost" if [ -f "$CREDENTIALS_DIRECTORY/mpd_host" ]; then MPD_HOST=$(cat "$CREDENTIALS_DIRECTORY/mpd_host") fi PASSWORD="" if [ -f "$CREDENTIALS_DIRECTORY/password" ]; then PASSWORD=$(cat "$CREDENTIALS_DIRECTORY/password") fi cat > "$CONF_FILE" <