You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.3 KiB
Nix

{pkgs, config, lib, ...}@args: {applicationName, application, errorPath}:
with pkgs.stdenv.lib;
let
createJsonConfiguration = (import ../build/json-configuration.nix) args;
optionalValue = (import ../util/optional-value.nix);
in let
serviceName = "node-${applicationName}-error-reporter";
cfg = config.services."node-${applicationName}".errorReporting;
configurationFile = createJsonConfiguration {
name = "error-reporter-configuration.json";
contents = (lib.filterAttrs (key: value: key != "enable") cfg) // {
errorPath = errorPath;
# The following is to make sure we don't end up with {hostname: null, user: null}, etc., which makes report-errors incorrectly conclude that we want to use a local SMTP server.
smtp = optionalValue (cfg.smtp.hostname != null) cfg.smtp;
};
};
in
{
options.services."node-${applicationName}".errorReporting = {
enable = mkEnableOption "${name} Error Reporter";
stackFilter = mkOption {
description = ''
What modules to filter out of the simplified stacktraces
shown in the e-mail report. This can either be the
string "*" (to filter out every third-party module), or
an array of module names to filter.
Note that the e-mail will always include a JSON
attachment containing the full stacktrace - this setting
purely affects the e-mail body.
'';
default = "*";
type = types.either types.str (types.listOf types.str);
};
subjectFormat = mkOption {
description = ''
The format for the subject line of the report e-mail. In
this string, `$type` will be replaced with the error
type/name, and `$message` will be replaced with the
error message.
'';
default = "UNHANDLED ERROR: $type - $message";
type = types.str;
};
metadata = {
from = mkOption {
description = ''
The sender address displayed on the e-mail report.
'';
type = types.str;
};
to = mkOption {
description = ''
The address to e-mail reports to.
'';
type = types.str;
};
};
smtp = {
hostname = mkOption {
description = ''
The hostname on which the SMTP server can be
reached.
'';
default = null;
type = types.nullOr types.str;
};
port = mkOption {
description = ''
The port number that the SMTP server is accessible
on.
'';
default = null;
type = types.nullOr types.str;
};
username = mkOption {
description = ''
Your username for the SMTP server.
'';
default = null;
type = types.nullOr types.str;
};
password = mkOption {
description = ''
Your password for the SMTP server.
'';
default = null;
type = types.nullOr types.str;
};
};
};
config = {
systemd.services."${serviceName}" = mkIf cfg.enable {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
ExecStart = "${application}/lib/node_modules/pastebin-stream/node_modules/.bin/report-errors ${configurationFile}";
# FIXME: Is the below the ideal approach?
User = config.systemd.services."node-${applicationName}".serviceConfig.User;
};
};
};
}