configuration files that power my machines
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788{ 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" <<EOF verbose = 2 log = - host = $MPD_HOST port = ${toString cfg.mpdPort}
[last.fm] url = ${cfg.serviceUrl} username = ${cfg.username} password = $PASSWORD journal = $STATE_DIRECTORY/lastfm.journal EOF
exec ${pkgs.mpdscribble}/bin/mpdscribble --no-daemon --conf "$CONF_FILE" ''; Restart = "always"; DynamicUser = true; StateDirectory = "mpdscribble"; }; }; };}