-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
matrix-appservice-discord: init at 0.5.2 (#62744)
* matrix-appservice-discord: init at 0.5.2 * nixos/matrix-appservice-discord: add module
- Loading branch information
Showing
8 changed files
with
5,475 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
nixos/modules/services/misc/matrix-appservice-discord.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
{ config, pkgs, lib, ... }: | ||
|
||
with lib; | ||
|
||
let | ||
dataDir = "/var/lib/matrix-appservice-discord"; | ||
registrationFile = "${dataDir}/discord-registration.yaml"; | ||
appDir = "${pkgs.matrix-appservice-discord}/lib/node_modules/matrix-appservice-discord"; | ||
cfg = config.services.matrix-appservice-discord; | ||
# TODO: switch to configGen.json once RFC42 is implemented | ||
settingsFile = pkgs.writeText "matrix-appservice-discord-settings.json" (builtins.toJSON cfg.settings); | ||
|
||
in { | ||
options = { | ||
services.matrix-appservice-discord = { | ||
enable = mkEnableOption "a bridge between Matrix and Discord"; | ||
|
||
settings = mkOption rec { | ||
# TODO: switch to types.config.json as prescribed by RFC42 once it's implemented | ||
type = types.attrs; | ||
apply = recursiveUpdate default; | ||
default = { | ||
database = { | ||
filename = "${dataDir}/discord.db"; | ||
|
||
# TODO: remove those old config keys once the following issues are solved: | ||
# * https://github.com/Half-Shot/matrix-appservice-discord/issues/490 | ||
# * https://github.com/Half-Shot/matrix-appservice-discord/issues/498 | ||
userStorePath = "${dataDir}/user-store.db"; | ||
roomStorePath = "${dataDir}/room-store.db"; | ||
}; | ||
|
||
# empty values necessary for registration file generation | ||
# actual values defined in environmentFile | ||
auth = { | ||
clientID = ""; | ||
botToken = ""; | ||
}; | ||
}; | ||
example = literalExample '' | ||
{ | ||
bridge = { | ||
domain = "public-domain.tld"; | ||
homeserverUrl = "http://public-domain.tld:8008"; | ||
}; | ||
} | ||
''; | ||
description = '' | ||
<filename>config.yaml</filename> configuration as a Nix attribute set. | ||
</para> | ||
<para> | ||
Configuration options should match those described in | ||
<link xlink:href="https://github.com/Half-Shot/matrix-appservice-discord/blob/master/config/config.sample.yaml"> | ||
config.sample.yaml</link>. | ||
</para> | ||
<para> | ||
<option>config.bridge.domain</option> and <option>config.bridge.homeserverUrl</option> | ||
should be set to match the public host name of the Matrix homeserver for webhooks and avatars to work. | ||
</para> | ||
<para> | ||
Secret tokens should be specified using <option>environmentFile</option> | ||
instead of this world-readable attribute set. | ||
''; | ||
}; | ||
|
||
environmentFile = mkOption { | ||
type = types.nullOr types.path; | ||
default = null; | ||
description = '' | ||
File containing environment variables to be passed to the matrix-appservice-discord service, | ||
in which secret tokens can be specified securely by defining values for | ||
<literal>APPSERVICE_DISCORD_AUTH_CLIENT_I_D</literal> and | ||
<literal>APPSERVICE_DISCORD_AUTH_BOT_TOKEN</literal>. | ||
''; | ||
}; | ||
|
||
url = mkOption { | ||
type = types.str; | ||
default = "http://localhost:${toString cfg.port}"; | ||
description = '' | ||
The URL where the application service is listening for HS requests. | ||
''; | ||
}; | ||
|
||
port = mkOption { | ||
type = types.port; | ||
default = 9005; # from https://github.com/Half-Shot/matrix-appservice-discord/blob/master/package.json#L11 | ||
description = '' | ||
Port number on which the bridge should listen for internal communication with the Matrix homeserver. | ||
''; | ||
}; | ||
|
||
localpart = mkOption { | ||
type = with types; nullOr str; | ||
default = null; | ||
description = '' | ||
The user_id localpart to assign to the AS. | ||
''; | ||
}; | ||
|
||
serviceDependencies = mkOption { | ||
type = with types; listOf str; | ||
default = optional config.services.matrix-synapse.enable "matrix-synapse.service"; | ||
description = '' | ||
List of Systemd services to require and wait for when starting the application service, | ||
such as the Matrix homeserver if it's running on the same host. | ||
''; | ||
}; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
systemd.services.matrix-appservice-discord = { | ||
description = "A bridge between Matrix and Discord."; | ||
|
||
wantedBy = [ "multi-user.target" ]; | ||
wants = [ "network-online.target" ] ++ cfg.serviceDependencies; | ||
after = [ "network-online.target" ] ++ cfg.serviceDependencies; | ||
|
||
preStart = '' | ||
if [ ! -f '${registrationFile}' ]; then | ||
${pkgs.matrix-appservice-discord}/bin/matrix-appservice-discord \ | ||
--generate-registration \ | ||
--url=${escapeShellArg cfg.url} \ | ||
${optionalString (cfg.localpart != null) "--localpart=${escapeShellArg cfg.localpart}"} \ | ||
--config='${settingsFile}' \ | ||
--file='${registrationFile}' | ||
fi | ||
''; | ||
|
||
serviceConfig = { | ||
Type = "simple"; | ||
Restart = "always"; | ||
|
||
ProtectSystem = "strict"; | ||
ProtectHome = true; | ||
ProtectKernelTunables = true; | ||
ProtectKernelModules = true; | ||
ProtectControlGroups = true; | ||
|
||
DynamicUser = true; | ||
PrivateTmp = true; | ||
WorkingDirectory = appDir; | ||
StateDirectory = baseNameOf dataDir; | ||
UMask = 0027; | ||
EnvironmentFile = cfg.environmentFile; | ||
|
||
ExecStart = '' | ||
${pkgs.matrix-appservice-discord}/bin/matrix-appservice-discord \ | ||
--file='${registrationFile}' \ | ||
--config='${settingsFile}' \ | ||
--port='${toString cfg.port}' | ||
''; | ||
}; | ||
}; | ||
}; | ||
|
||
meta.maintainers = with maintainers; [ pacien ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ pkgs, nodejs, stdenv }: | ||
|
||
let | ||
nodePackages = import ./node-composition.nix { | ||
inherit pkgs nodejs; | ||
inherit (stdenv.hostPlatform) system; | ||
}; | ||
|
||
in nodePackages."matrix-appservice-discord-git+https://github.com/Half-Shot/matrix-appservice-discord.git#v0.5.2".override { | ||
nativeBuildInputs = [ pkgs.makeWrapper ]; | ||
|
||
postInstall = '' | ||
# compile Typescript sources | ||
npm run build | ||
# server wrapper | ||
makeWrapper '${nodejs}/bin/node' "$out/bin/matrix-appservice-discord" \ | ||
--add-flags "$out/lib/node_modules/matrix-appservice-discord/build/src/discordas.js" | ||
# admin tools wrappers | ||
for toolPath in $out/lib/node_modules/matrix-appservice-discord/build/tools/*; do | ||
makeWrapper '${nodejs}/bin/node' "$out/bin/matrix-appservice-discord-$(basename $toolPath .js)" \ | ||
--add-flags "$toolPath" | ||
done | ||
''; | ||
|
||
# other metadata generated and inherited from ./node-package.nix | ||
meta.maintainers = with stdenv.lib.maintainers; [ pacien ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
##!/usr/bin/env nix-shell | ||
##! nix-shell -i bash -p nodePackages.node2nix | ||
|
||
node2nix \ | ||
--nodejs-12 \ | ||
--node-env ../../development/node-packages/node-env.nix \ | ||
--development \ | ||
--input package.json \ | ||
--output node-packages.nix \ | ||
--composition node-composition.nix |
17 changes: 17 additions & 0 deletions
17
pkgs/servers/matrix-appservice-discord/node-composition.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# This file has been generated by node2nix 1.8.0. Do not edit! | ||
|
||
{pkgs ? import <nixpkgs> { | ||
inherit system; | ||
}, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-12_x"}: | ||
|
||
let | ||
nodeEnv = import ../../development/node-packages/node-env.nix { | ||
inherit (pkgs) stdenv python2 utillinux runCommand writeTextFile; | ||
inherit nodejs; | ||
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null; | ||
}; | ||
in | ||
import ./node-packages.nix { | ||
inherit (pkgs) fetchurl fetchgit; | ||
inherit nodeEnv; | ||
} |
Oops, something went wrong.