commit 1471dbf54cc9be3e435e6522c4bcc67be8c93b62
parent 9cd2aa68413277edf46596681b6a00773e5db264
Author: mtmn <miro@haravara.org>
Date: Sat, 11 Apr 2026 03:41:38 +0200
feat: install listenbrainz-mpd
Diffstat:
6 files changed, 104 insertions(+), 0 deletions(-)
diff --git a/flake.nix b/flake.nix
@@ -168,6 +168,7 @@
attic = import ./modules/services/attic.nix;
static = import ./modules/services/static.nix;
miniflux = import ./modules/services/miniflux.nix;
+ listenbrainz-mpd = import ./modules/services/listenbrainz-mpd.nix;
};
deploy = {
diff --git a/hosts/nixaran/configuration.nix b/hosts/nixaran/configuration.nix
Binary files differ.
diff --git a/modules/services/listenbrainz-mpd.nix b/modules/services/listenbrainz-mpd.nix
@@ -0,0 +1,101 @@
+{
+ config,
+ lib,
+ pkgs,
+ ...
+}: let
+ cfg = config.services.haravara.listenbrainz-mpd;
+in {
+ options.services.haravara.listenbrainz-mpd = {
+ enable = lib.mkEnableOption "ListenBrainz MPD client";
+ tokenFile = lib.mkOption {
+ type = lib.types.nullOr lib.types.path;
+ default = null;
+ description = "Path to the file containing the ListenBrainz token";
+ };
+ token = lib.mkOption {
+ type = lib.types.nullOr lib.types.str;
+ default = null;
+ description = "The ListenBrainz token (unsecure, prefer tokenFile)";
+ };
+ apiUrl = lib.mkOption {
+ type = lib.types.str;
+ default = "https://api.listenbrainz.org";
+ };
+ genresAsFolksonomy = lib.mkOption {
+ type = lib.types.bool;
+ default = false;
+ };
+ mpdAddress = lib.mkOption {
+ type = lib.types.str;
+ default = "localhost:6695";
+ };
+ mpdPassword = lib.mkOption {
+ type = lib.types.str;
+ default = "";
+ };
+ mpdHostFile = lib.mkOption {
+ type = lib.types.nullOr lib.types.path;
+ default = null;
+ description = "Path to the file containing the MPD host";
+ };
+ mpdHostEnv = lib.mkOption {
+ type = lib.types.nullOr lib.types.str;
+ default = null;
+ };
+ mpdPortEnv = lib.mkOption {
+ type = lib.types.nullOr lib.types.int;
+ default = null;
+ };
+ };
+
+ config = lib.mkIf cfg.enable {
+ systemd.services.listenbrainz-mpd = {
+ description = "ListenBrainz MPD client";
+ after = ["network.target"];
+ wantedBy = ["multi-user.target"];
+
+ serviceConfig = {
+ ExecStartPre = pkgs.writeShellScript "listenbrainz-mpd-setup" ''
+ mkdir -p "$RUNTIME_DIRECTORY/config"
+ TOKEN=$([ -n "${toString (cfg.tokenFile != null)}" ] && cat "${toString cfg.tokenFile}" || echo "${toString cfg.token}")
+ cat > "$RUNTIME_DIRECTORY/config/config.toml" <<EOF
+ [submission]
+ token = "$TOKEN"
+ api_url = "${cfg.apiUrl}"
+ genres_as_folksonomy = ${lib.boolToString cfg.genresAsFolksonomy}
+
+ [mpd]
+ address = "${cfg.mpdAddress}"
+ password = "${cfg.mpdPassword}"
+ EOF
+ '';
+ ExecStart = "${pkgs.listenbrainz-mpd}/bin/listenbrainz-mpd";
+ Restart = "always";
+ DynamicUser = true;
+ RuntimeDirectory = "listenbrainz-mpd";
+ };
+
+ environment =
+ lib.optionalAttrs (cfg.mpdHostEnv != null || cfg.mpdHostFile != null) {
+ # We'll set this in ExecStart wrapper if it's a file, but let's see if we can use environment variables
+ }
+ // lib.optionalAttrs (cfg.mpdPortEnv != null) {
+ MPD_PORT = toString cfg.mpdPortEnv;
+ }
+ // {
+ XDG_CONFIG_HOME = "/run/listenbrainz-mpd/config";
+ };
+ };
+
+ # Update ExecStart to handle MPD_HOST from file if provided
+ systemd.services.listenbrainz-mpd.serviceConfig.ExecStart = lib.mkForce (pkgs.writeShellScript "listenbrainz-mpd-start" ''
+ if [ -n "${toString (cfg.mpdHostFile != null)}" ]; then
+ export MPD_HOST=$(cat "${toString cfg.mpdHostFile}")
+ elif [ -n "${toString (cfg.mpdHostEnv != null)}" ]; then
+ export MPD_HOST="${toString cfg.mpdHostEnv}"
+ fi
+ exec ${pkgs.listenbrainz-mpd}/bin/listenbrainz-mpd
+ '');
+ };
+}
diff --git a/secrets.nix b/secrets.nix
@@ -14,4 +14,6 @@ in {
"secrets/headscale-api-key.age".publicKeys = allKeys;
"secrets/attic-credentials.age".publicKeys = allKeys;
"secrets/miniflux-secrets.age".publicKeys = allKeys;
+ "secrets/listenbrainz-token.age".publicKeys = allKeys;
+ "secrets/mpd-host.age".publicKeys = allKeys;
}
diff --git a/secrets/listenbrainz-token.age b/secrets/listenbrainz-token.age
Binary files differ.
diff --git a/secrets/mpd-host.age b/secrets/mpd-host.age
Binary files differ.