From eb76cc5ad2354807b5876d8520afa372dffc3a6e Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 21 Jan 2026 23:10:53 -0800 Subject: [PATCH] Switch MusicLink to Matrix-native config Replace Matterbridge settings with matrix config options. Generate TOML with proper room list commas. --- hosts/ops-jrz1.nix | 14 +++- modules/dev-services.nix | 57 +++++++++++--- modules/musiclink.nix | 159 ++++++++++++++------------------------- 3 files changed, 115 insertions(+), 115 deletions(-) diff --git a/hosts/ops-jrz1.nix b/hosts/ops-jrz1.nix index 199b4eb..25f854c 100644 --- a/hosts/ops-jrz1.nix +++ b/hosts/ops-jrz1.nix @@ -105,9 +105,17 @@ musiclink = { enable = true; - matterbridge = { - enable = true; - slackChannel = "music"; + matrix = { + server = "http://127.0.0.1:8008"; + userId = "@musiclink:clarun.xyz"; + rooms = [ + "!whU7Geg7JPrBL5wHcW:clarun.xyz" + "!dT40EUcemb8e6bPiig:clarun.xyz" + "!DPQveBnfuDrbgOe6dm:clarun.xyz" + ]; + shadow = false; + healthAddr = ":8080"; + stateStorePath = "data/matrix-state.db"; }; }; }; diff --git a/modules/dev-services.nix b/modules/dev-services.nix index 0bd2056..cdafdb3 100644 --- a/modules/dev-services.nix +++ b/modules/dev-services.nix @@ -103,17 +103,47 @@ in description = "Enable MusicLink bot"; }; - matterbridge = { - enable = mkOption { - type = types.bool; - default = true; - description = "Enable bundled Matterbridge"; + matrix = { + server = mkOption { + type = types.str; + default = "http://127.0.0.1:${toString cfg.matrix.port}"; + description = "Matrix homeserver base URL"; }; - slackChannel = mkOption { + userId = mkOption { type = types.str; - default = "music"; - description = "Slack channel for MusicLink"; + default = "@musiclink:${cfg.matrix.serverName}"; + description = "Matrix user ID for MusicLink"; + }; + + rooms = mkOption { + type = types.listOf types.str; + default = []; + 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"; }; }; }; @@ -298,9 +328,14 @@ in # MusicLink Service services.musiclink = mkIf cfg.musiclink.enable { enable = true; - matterbridge = { - enable = cfg.musiclink.matterbridge.enable; - slackChannel = cfg.musiclink.matterbridge.slackChannel; + matrix = { + server = cfg.musiclink.matrix.server; + userId = cfg.musiclink.matrix.userId; + rooms = cfg.musiclink.matrix.rooms; + tokenFile = cfg.musiclink.matrix.tokenFile; + shadow = cfg.musiclink.matrix.shadow; + healthAddr = cfg.musiclink.matrix.healthAddr; + stateStorePath = cfg.musiclink.matrix.stateStorePath; }; }; diff --git a/modules/musiclink.nix b/modules/musiclink.nix index f99bf58..92dbc18 100644 --- a/modules/musiclink.nix +++ b/modules/musiclink.nix @@ -4,18 +4,10 @@ with lib; let cfg = config.services.musiclink; - musiclinkPkg = musiclink; # musiclink input passed via specialArgs is the package set? No, usually it's the flake itself if not mapped. - # But in flake.nix we did: musiclink = inputs.musiclink.packages.x86_64-linux.default; - # So `musiclink` here is the package. - matterbridgePkg = pkgs.matterbridge.overrideAttrs (old: { - patches = (old.patches or []) ++ [ - ./patches/matterbridge-api-websocket-max-message.patch - ]; - }); in { options.services.musiclink = { - enable = mkEnableOption "MusicLink bot with Matterbridge"; + enable = mkEnableOption "MusicLink bot"; package = mkOption { type = types.package; @@ -23,100 +15,52 @@ in { description = "The MusicLink bot package"; }; - matterbridge = { - enable = mkOption { - type = types.bool; - default = true; - description = "Enable bundled Matterbridge instance"; + matrix = { + server = mkOption { + type = types.str; + description = "Matrix homeserver base URL"; }; - port = mkOption { - type = types.port; - default = 4242; - description = "Matterbridge API port"; - }; - - slackChannel = mkOption { + userId = mkOption { type = types.str; - default = "music"; - description = "Slack channel to bridge"; + 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 { - # ------------------------------------------------------------------------- - # Matterbridge Service - # ------------------------------------------------------------------------- - systemd.services.musiclink-matterbridge = mkIf cfg.matterbridge.enable { - description = "Matterbridge for MusicLink"; - after = [ "network.target" ]; - wantedBy = [ "multi-user.target" ]; - - serviceConfig = { - Type = "simple"; - DynamicUser = true; - StateDirectory = "musiclink-matterbridge"; - WorkingDirectory = "/var/lib/musiclink-matterbridge"; - - # Secrets - LoadCredential = [ - "musiclink-matrix-token:/run/secrets/musiclink-matrix-token" - ]; - - ExecStartPre = pkgs.writeShellScript "generate-matterbridge-config" '' - set -euo pipefail - - MATRIX_TOKEN=$(cat $CREDENTIALS_DIRECTORY/musiclink-matrix-token) - - cat > /var/lib/musiclink-matterbridge/matterbridge.toml < /var/lib/musiclink/config.toml < /var/lib/musiclink/config.toml <