nixos/mautrix-whatsapp: fix merging of default settings
This implements proper merging of user-provided values and default values for the settings option. Without this, the user must provide a complete configuration file, as changing a single setting replaces the entire JSON value, rendering the default values completely useless. In fact, the bridge won't even start using the default settings.
This commit is contained in:
parent
9e0457115e
commit
035f905124
|
@ -11,53 +11,51 @@
|
||||||
settingsFileUnsubstituted = settingsFormat.generate "mautrix-whatsapp-config-unsubstituted.json" cfg.settings;
|
settingsFileUnsubstituted = settingsFormat.generate "mautrix-whatsapp-config-unsubstituted.json" cfg.settings;
|
||||||
settingsFormat = pkgs.formats.json {};
|
settingsFormat = pkgs.formats.json {};
|
||||||
appservicePort = 29318;
|
appservicePort = 29318;
|
||||||
|
|
||||||
|
mkDefaults = lib.mapAttrsRecursive (n: v: lib.mkDefault v);
|
||||||
|
defaultConfig = {
|
||||||
|
appservice = {
|
||||||
|
hostname = "[::]";
|
||||||
|
port = appservicePort;
|
||||||
|
database.type = "sqlite3";
|
||||||
|
database.uri = "${dataDir}/mautrix-whatsapp.db";
|
||||||
|
id = "whatsapp";
|
||||||
|
bot.username = "whatsappbot";
|
||||||
|
bot.displayname = "WhatsApp Bridge Bot";
|
||||||
|
as_token = "";
|
||||||
|
hs_token = "";
|
||||||
|
};
|
||||||
|
bridge = {
|
||||||
|
username_template = "whatsapp_{{.}}";
|
||||||
|
displayname_template = "{{if .BusinessName}}{{.BusinessName}}{{else if .PushName}}{{.PushName}}{{else}}{{.JID}}{{end}} (WA)";
|
||||||
|
double_puppet_server_map = {};
|
||||||
|
login_shared_secret_map = {};
|
||||||
|
command_prefix = "!wa";
|
||||||
|
permissions."*" = "relay";
|
||||||
|
relay.enabled = true;
|
||||||
|
};
|
||||||
|
logging = {
|
||||||
|
min_level = "info";
|
||||||
|
writers = [
|
||||||
|
{
|
||||||
|
type = "stdout";
|
||||||
|
format = "pretty-colored";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
type = "file";
|
||||||
|
format = "json";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
in {
|
in {
|
||||||
imports = [];
|
|
||||||
options.services.mautrix-whatsapp = {
|
options.services.mautrix-whatsapp = {
|
||||||
enable = lib.mkEnableOption (lib.mdDoc "mautrix-whatsapp, a puppeting/relaybot bridge between Matrix and WhatsApp.");
|
enable = lib.mkEnableOption (lib.mdDoc "mautrix-whatsapp, a puppeting/relaybot bridge between Matrix and WhatsApp.");
|
||||||
|
|
||||||
settings = lib.mkOption {
|
settings = lib.mkOption {
|
||||||
type = settingsFormat.type;
|
type = settingsFormat.type;
|
||||||
default = {
|
default = defaultConfig;
|
||||||
appservice = {
|
|
||||||
address = "http://localhost:${toString appservicePort}";
|
|
||||||
hostname = "[::]";
|
|
||||||
port = appservicePort;
|
|
||||||
database = {
|
|
||||||
type = "sqlite3";
|
|
||||||
uri = "${dataDir}/mautrix-whatsapp.db";
|
|
||||||
};
|
|
||||||
id = "whatsapp";
|
|
||||||
bot = {
|
|
||||||
username = "whatsappbot";
|
|
||||||
displayname = "WhatsApp Bridge Bot";
|
|
||||||
};
|
|
||||||
as_token = "";
|
|
||||||
hs_token = "";
|
|
||||||
};
|
|
||||||
bridge = {
|
|
||||||
username_template = "whatsapp_{{.}}";
|
|
||||||
displayname_template = "{{if .BusinessName}}{{.BusinessName}}{{else if .PushName}}{{.PushName}}{{else}}{{.JID}}{{end}} (WA)";
|
|
||||||
double_puppet_server_map = {};
|
|
||||||
login_shared_secret_map = {};
|
|
||||||
command_prefix = "!wa";
|
|
||||||
permissions."*" = "relay";
|
|
||||||
relay.enabled = true;
|
|
||||||
};
|
|
||||||
logging = {
|
|
||||||
min_level = "info";
|
|
||||||
writers = [
|
|
||||||
{
|
|
||||||
type = "stdout";
|
|
||||||
format = "pretty-colored";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
type = "file";
|
|
||||||
format = "json";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
description = lib.mdDoc ''
|
description = lib.mdDoc ''
|
||||||
{file}`config.yaml` configuration as a Nix attribute set.
|
{file}`config.yaml` configuration as a Nix attribute set.
|
||||||
Configuration options should match those described in
|
Configuration options should match those described in
|
||||||
|
@ -127,9 +125,11 @@ in {
|
||||||
|
|
||||||
users.groups.mautrix-whatsapp = {};
|
users.groups.mautrix-whatsapp = {};
|
||||||
|
|
||||||
services.mautrix-whatsapp.settings = {
|
services.mautrix-whatsapp.settings = lib.mkMerge (map mkDefaults [
|
||||||
homeserver.domain = lib.mkDefault config.services.matrix-synapse.settings.server_name;
|
defaultConfig
|
||||||
};
|
# Note: this is defined here to avoid the docs depending on `config`
|
||||||
|
{ homeserver.domain = config.services.matrix-synapse.settings.server_name; }
|
||||||
|
]);
|
||||||
|
|
||||||
systemd.services.mautrix-whatsapp = {
|
systemd.services.mautrix-whatsapp = {
|
||||||
description = "Mautrix-WhatsApp Service - A WhatsApp bridge for Matrix";
|
description = "Mautrix-WhatsApp Service - A WhatsApp bridge for Matrix";
|
||||||
|
|
Loading…
Reference in a new issue