summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/matrix
diff options
context:
space:
mode:
authorSophie Tauchert <sophie.tauchert@relaxdays.de>2023-07-31 11:34:56 +0200
committerSophie Tauchert <sophie@999eagle.moe>2023-09-18 08:24:36 +0200
commit53ab84cf49a6146de35f31f81960185ff6075d55 (patch)
treee989689437ec88632bdfc15c84a83d55ca35646d /nixos/modules/services/matrix
parent857b4932eca927df0f2cb1ac8bbbae72a0960c0b (diff)
nixos/synapse: automatically configure logging for synapse and workers
Diffstat (limited to 'nixos/modules/services/matrix')
-rw-r--r--nixos/modules/services/matrix/synapse-log_config.yaml19
-rw-r--r--nixos/modules/services/matrix/synapse.nix62
2 files changed, 58 insertions, 23 deletions
diff --git a/nixos/modules/services/matrix/synapse-log_config.yaml b/nixos/modules/services/matrix/synapse-log_config.yaml
deleted file mode 100644
index c4b2b0d8acf5..000000000000
--- a/nixos/modules/services/matrix/synapse-log_config.yaml
+++ /dev/null
@@ -1,19 +0,0 @@
-version: 1
-
-# In systemd's journal, loglevel is implicitly stored, so let's omit it
-# from the message text.
-formatters:
- journal_fmt:
- format: '%(name)s: [%(request)s] %(message)s'
-
-handlers:
- journal:
- class: systemd.journal.JournalHandler
- formatter: journal_fmt
- SYSLOG_IDENTIFIER: synapse
-
-root:
- level: INFO
- handlers: [journal]
-
-disable_existing_loggers: False
diff --git a/nixos/modules/services/matrix/synapse.nix b/nixos/modules/services/matrix/synapse.nix
index 52074f1d9a62..f7ae3fa89536 100644
--- a/nixos/modules/services/matrix/synapse.nix
+++ b/nixos/modules/services/matrix/synapse.nix
@@ -69,6 +69,48 @@ let
extras = wantedExtras;
inherit (cfg) plugins;
};
+
+ logConfig = logName: {
+ version = 1;
+ formatters.journal_fmt.format = "%(name)s: [%(request)s] %(message)s";
+ handlers.journal = {
+ class = "systemd.journal.JournalHandler";
+ formatter = "journal_fmt";
+ SYSLOG_IDENTIFIER = logName;
+ };
+ root = {
+ level = "INFO";
+ handlers = [ "journal" ];
+ };
+ disable_existing_loggers = false;
+ };
+ logConfigText = logName:
+ let
+ expr = ''
+ {
+ version = 1;
+ formatters.journal_fmt.format = "%(name)s: [%(request)s] %(message)s";
+ handlers.journal = {
+ class = "systemd.journal.JournalHandler";
+ formatter = "journal_fmt";
+ SYSLOG_IDENTIFIER = "${logName}";
+ };
+ root = {
+ level = "INFO";
+ handlers = [ "journal" ];
+ };
+ disable_existing_loggers = false;
+ };
+ '';
+ in
+ lib.literalMD ''
+ Path to a yaml file generated from this Nix expression:
+
+ ```
+ ${expr}
+ ```
+ '';
+ genLogConfigFile = logName: format.generate "synapse-log-${logName}.yaml" (logConfig logName);
in {
imports = [
@@ -448,8 +490,8 @@ in {
log_config = mkOption {
type = types.path;
- default = ./synapse-log_config.yaml;
- defaultText = lib.literalExpression "nixos/modules/services/matrix/synapse-log_config.yaml";
+ default = genLogConfigFile "synapse";
+ defaultText = logConfigText "synapse";
description = lib.mdDoc ''
The file that holds the logging configuration.
'';
@@ -814,7 +856,7 @@ in {
'';
};
config = lib.mkOption {
- type = types.attrsOf (types.submodule {
+ type = types.attrsOf (types.submodule ({name, ...}: {
freeformType = format.type;
options = {
worker_app = lib.mkOption {
@@ -832,8 +874,20 @@ in {
List of ports that this worker should listen on, their purpose and their configuration.
'';
};
+ worker_log_config = lib.mkOption {
+ type = types.path;
+ default = genLogConfigFile "synapse-${name}";
+ defaultText = logConfigText "synapse-${name}";
+ description = lib.mdDoc ''
+ The file for log configuration.
+
+ See the [python documentation](https://docs.python.org/3/library/logging.config.html#configuration-dictionary-schema)
+ for the schema and the [upstream repository](https://github.com/matrix-org/synapse/blob/v${pkgs.matrix-synapse-unwrapped.version}/docs/sample_log_config.yaml)
+ for an example.
+ '';
+ };
};
- });
+ }));
default = { };
description = lib.mdDoc ''
List of workers to configure. See the