Files
4DBug 7de90b5b7c v2: watch-party Activity
The Activity is now the full bug.tv site plus a small Discord overlay. Whoever
starts the instance hosts and controls everything; everyone else mirrors the
host's page and playback. The server is a relay keyed by activity instance and
checks membership through Discord's activity-instances API, so it works in DM
and group calls. The bot gateway, slash commands and control message are gone.
2026-10-27 10:00:34 -05:00

133 lines
3.8 KiB
Nix

self:
{
config,
lib,
pkgs,
...
}:
let
inherit (lib) mkOption mkEnableOption types;
cfg = config.services.bug-tv-discord;
system = pkgs.stdenv.hostPlatform.system;
credDir = "/run/credentials/bug-tv-discord.service";
appConfig = lib.recursiveUpdate {
inherit (cfg) host port applicationId;
activityDir = "${cfg.activityPackage}";
tokenFile = "${credDir}/token";
clientSecretFile = "${credDir}/client-secret";
} cfg.extraConfig;
configFile = pkgs.writeText "bug-tv-discord-config.json" (builtins.toJSON appConfig);
in
{
options.services.bug-tv-discord = {
enable = mkEnableOption "the bug.tv Discord Activity server (static site + watch-party relay)";
package = mkOption {
type = types.package;
default = self.packages.${system}.default;
defaultText = lib.literalExpression "bug-tv-discord.packages.\${system}.default";
description = "The server package.";
};
activityPackage = mkOption {
type = types.package;
default = self.packages.${system}.activity;
defaultText = lib.literalExpression "bug-tv-discord.packages.\${system}.activity";
description = "Static Activity files (bug.tv site + overlay) served by the HTTP server.";
};
host = mkOption {
type = types.str;
default = "127.0.0.1";
description = "Interface the HTTP/WS server binds to (cloudflared connects locally).";
};
port = mkOption {
type = types.port;
default = 8791;
description = "HTTP/WS server TCP port.";
};
applicationId = mkOption {
type = types.str;
example = "123456789012345678";
description = "Discord application id (not secret).";
};
tokenFile = mkOption {
type = types.path;
description = "File holding the Discord bot token, used to check Activity instance membership (passed via systemd LoadCredential).";
};
clientSecretFile = mkOption {
type = types.path;
description = "File holding the Discord OAuth2 client secret (passed via systemd LoadCredential).";
};
extraConfig = mkOption {
type = types.attrsOf types.json;
default = { };
description = "Extra keys recursively merged last into the generated config JSON.";
};
};
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.applicationId != "";
message = "services.bug-tv-discord: set applicationId";
}
];
systemd.services.bug-tv-discord = {
description = "bug.tv Discord Activity server";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
environment = {
BUG_TV_DISCORD_CONFIG = toString configFile;
NODE_ENV = "production";
};
serviceConfig = {
ExecStart = lib.getExe cfg.package;
LoadCredential = [
"token:${toString cfg.tokenFile}"
"client-secret:${toString cfg.clientSecretFile}"
];
DynamicUser = true;
NoNewPrivileges = true;
PrivateTmp = true;
PrivateDevices = true;
ProtectSystem = "strict";
ProtectHome = true;
ProtectHostname = true;
ProtectClock = true;
ProtectProc = "invisible";
ProtectKernelTunables = true;
ProtectKernelModules = true;
ProtectKernelLogs = true;
ProtectControlGroups = true;
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
LockPersonality = true;
MemoryDenyWriteExecute = false; # node's JIT
SystemCallArchitectures = "native";
CapabilityBoundingSet = "";
AmbientCapabilities = "";
UMask = "0077";
Restart = "always";
RestartSec = 5;
};
};
};
}