Add native module options for Discord channel configuration #9

Open
opened 2026-02-15 17:04:27 -05:00 by yindo · 0 comments
Owner

Originally created by @schickling on GitHub (Jan 26, 2026).

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).

Originally created by @schickling on GitHub (Jan 26, 2026). ## 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 ```nix 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: ```nix 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`).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: openclaw/nix-openclaw#9