nix

configuration files that power my machines
Log | Files | Refs | README | LICENSE

commit b71f1db3a195458d9e2acc13cd8e162c775e065a
parent c5c7ed320be67b7f3e416776c1028adbeb1681c9
Author: mtmn <miro@haravara.org>
Date:   Thu, 23 Apr 2026 12:55:51 +0200

hosts/nixaran/configuration.nix modules/services/mpdscribble.nix

Diffstat:
Mhosts/nixaran/configuration.nix | 0
Amodules/services/mpdscribble.nix | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 86 insertions(+), 0 deletions(-)

diff --git a/hosts/nixaran/configuration.nix b/hosts/nixaran/configuration.nix Binary files differ. diff --git a/modules/services/mpdscribble.nix b/modules/services/mpdscribble.nix @@ -0,0 +1,86 @@ +{ + 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 containing MPD_HOST (can include password@host)"; + }; + 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.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" + + # Start with a clean config + echo "[mpd]" > "$CONF_FILE" + + if [ -f "$CREDENTIALS_DIRECTORY/mpd_host" ]; then + MPD_HOST=$(cat "$CREDENTIALS_DIRECTORY/mpd_host") + echo "host = $MPD_HOST" >> "$CONF_FILE" + else + echo "host = localhost" >> "$CONF_FILE" + fi + echo "port = ${toString cfg.mpdPort}" >> "$CONF_FILE" + + echo "" >> "$CONF_FILE" + echo "[last.fm]" >> "$CONF_FILE" + echo "url = ${cfg.serviceUrl}" >> "$CONF_FILE" + echo "username = ${cfg.username}" >> "$CONF_FILE" + + if [ -f "$CREDENTIALS_DIRECTORY/password" ]; then + PASSWORD=$(cat "$CREDENTIALS_DIRECTORY/password") + echo "password = $PASSWORD" >> "$CONF_FILE" + fi + + echo "journal = $STATE_DIRECTORY/lastfm.journal" >> "$CONF_FILE" + + exec ${pkgs.mpdscribble}/bin/mpdscribble --no-daemon --conf "$CONF_FILE" + ''; + Restart = "always"; + DynamicUser = true; + StateDirectory = "mpdscribble"; + }; + }; + }; +}