Skip to content

Add native module options for Discord channel configuration #20

@schickling

Description

@schickling

Problem

The nix-clawdbot module doesn't provide native options for configuring the Discord channel. Users need to configure:

  • Discord bot token
  • DM policies (enabled, allowlist/blocklist, allowed user IDs)
  • Guild settings (which guilds, which channels, requireMention, etc.)

Currently, this requires manually injecting JSON into the config file via activation scripts, which is error-prone and not declarative.

Current Workaround

Using an activation script that:

  1. Reads the Discord token from a secrets file
  2. Uses jq to inject the full Discord configuration into the generated config
home.activation.injectDiscordConfig = lib.hm.dag.entryAfter [ "fixClawdbotConfig" ] ''
  CONFIG_FILE="${config.home.homeDirectory}/.clawdbot/config.json"
  TOKEN_FILE="${config.home.homeDirectory}/.secrets/discord-bot-token"
  
  if [ -f "$TOKEN_FILE" ] && [ -f "$CONFIG_FILE" ]; then
    DISCORD_TOKEN=$(cat "$TOKEN_FILE")
    ${pkgs.jq}/bin/jq --arg token "$DISCORD_TOKEN" '.channels.discord = {
      "enabled": true,
      "token": $token,
      "dm": {
        "enabled": true,
        "policy": "allowlist",
        "allowFrom": ["176610489202245632"]
      },
      "guilds": {
        "1465291627760455879": {
          "channels": {
            "*": { "allow": true, "requireMention": true }
          }
        }
      }
    }' "$CONFIG_FILE" > "$CONFIG_FILE.tmp" && mv "$CONFIG_FILE.tmp" "$CONFIG_FILE"
  fi
'';

Suggested Solution

Add module options like:

services.clawdbot.channels.discord = {
  enable = mkEnableOption "Discord integration";
  
  tokenFile = mkOption {
    type = types.path;
    description = "Path to file containing Discord bot token";
  };
  
  dm = {
    enable = mkEnableOption "Direct messages";
    policy = mkOption {
      type = types.enum [ "allowlist" "blocklist" ];
      default = "allowlist";
    };
    allowFrom = mkOption {
      type = types.listOf types.str;
      default = [];
      description = "Discord user IDs allowed to DM the bot";
    };
  };
  
  guilds = mkOption {
    type = types.attrsOf (types.submodule { ... });
    default = {};
    description = "Per-guild configuration";
  };
};

This would allow fully declarative Discord configuration while keeping secrets out of the nix store (via tokenFile).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions