ops-jrz1/modules/musiclink.nix
Dan eb76cc5ad2 Switch MusicLink to Matrix-native config
Replace Matterbridge settings with matrix config options.

Generate TOML with proper room list commas.
2026-01-21 23:10:53 -08:00

103 lines
2.5 KiB
Nix

{ config, pkgs, lib, musiclink, ... }:
with lib;
let
cfg = config.services.musiclink;
in {
options.services.musiclink = {
enable = mkEnableOption "MusicLink bot";
package = mkOption {
type = types.package;
default = musiclink;
description = "The MusicLink bot package";
};
matrix = {
server = mkOption {
type = types.str;
description = "Matrix homeserver base URL";
};
userId = mkOption {
type = types.str;
description = "Matrix user ID for the bot";
};
rooms = mkOption {
type = types.listOf types.str;
description = "Allowlisted Matrix room IDs";
};
tokenFile = mkOption {
type = types.path;
default = "/run/secrets/musiclink-matrix-token";
description = "Path to Matrix access token file";
};
shadow = mkOption {
type = types.bool;
default = false;
description = "Shadow mode (log responses without sending)";
};
healthAddr = mkOption {
type = types.str;
default = "";
description = "Health server listen address (optional)";
};
stateStorePath = mkOption {
type = types.str;
default = "data/matrix-state.db";
description = "Path to Matrix sync state store";
};
};
};
config = mkIf cfg.enable {
systemd.services.musiclink = {
description = "MusicLink Bot";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
DynamicUser = true;
StateDirectory = "musiclink";
WorkingDirectory = "/var/lib/musiclink";
LoadCredential = [
"musiclink-matrix-token:${cfg.matrix.tokenFile}"
];
ExecStartPre = pkgs.writeShellScript "generate-musiclink-config" ''
set -euo pipefail
MATRIX_TOKEN=$(cat $CREDENTIALS_DIRECTORY/musiclink-matrix-token)
cat > /var/lib/musiclink/config.toml <<EOF
[matrix]
shadow = ${lib.boolToString cfg.matrix.shadow}
healthAddr = "${cfg.matrix.healthAddr}"
server = "${cfg.matrix.server}"
accessToken = "$MATRIX_TOKEN"
userId = "${cfg.matrix.userId}"
rooms = [
${lib.concatMapStringsSep ",\n" (room: " \"${room}\"") cfg.matrix.rooms}
]
stateStorePath = "${cfg.matrix.stateStorePath}"
EOF
'';
ExecStart = "${cfg.package}/bin/musiclink -config /var/lib/musiclink/config.toml";
Restart = "always";
RestartSec = "10s";
};
};
};
}