-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.nix
More file actions
143 lines (137 loc) · 4.48 KB
/
Copy pathmodule.nix
File metadata and controls
143 lines (137 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
{
lib,
config,
pkgs,
...
}:
with lib; let
cfg = config.services.pushlog;
unitType = types.submodule {
options = {
match = mkOption {
type = types.str;
default = ".*";
};
priorities = mkOption {
type = types.listOf types.int;
default = [0 1 2 3 4 5 6];
};
include = mkOption {
type = types.listOf types.str;
default = [];
};
exclude = mkOption {
type = types.listOf types.str;
default = [];
};
};
};
in {
options.services.pushlog = {
enable = mkEnableOption "Enable pushlog service to forward journald logs to Pushover";
package = mkOption {
type = types.package;
description = "pushlog package to use";
default = pkgs.callPackage ./default.nix {};
defaultText = "./pushlog.nix";
};
environmentFile = mkOption {
type = with types; nullOr str;
description = lib.mdDoc ''
File containing the Pushover API credentials, in the
format of an EnvironmentFile as described by systemd.exec(5)
PUSHLOG_PUSHOVER_TOKEN, PUSHLOG_PUSHOVER_USER_KEY
'';
default = null;
};
settings = {
collect-timeout = mkOption {
type = types.int;
description = "Wait n seconds before sendings logs to bundle multiple messages";
default = 5;
};
deduplication-window = mkOption {
type = types.int;
description = "Remember messages for n minutes and avoid sending duplicates";
default = 30;
};
fuzzy-threshold = mkOption {
type = types.int;
description = "Use fuzzy matching with the given threshold (similarity in percent) to detect duplicates, set to 100 to disable";
default = 95;
};
title = mkOption {
type = with types; nullOr str;
description = "Optional title to use for all Pushover notifications";
default = null;
};
priority-map = mkOption {
type = with types; attrsOf (enum [(-2) (-1) 0 1 2]);
description = "Optional mapping from journald priorities (0-7) to Pushover priorities (-2, -1, 0, 1, 2), unmapped priorities will be mapped to 0";
default = {};
example = literalExpression ''
{
"0" = 2; # emerg -> emergency (2)
"1" = 1; # alert -> high (1)
"2" = 1; # crit -> high (1)
"3" = 0; # err -> normal (0)
"4" = -1; # warning -> low (-1)
"5" = -2; # notice -> lowest (-2)
"6" = -2; # info -> lowest (-2)
"7" = -2; # debug -> lowest (-2)
}
'';
};
units = mkOption {
type = types.listOf unitType;
description = "List of units to care about";
};
};
};
config =
mkIf cfg.enable
(let
format = pkgs.formats.yaml {};
configFile = format.generate "pushlog.yaml" cfg.settings;
in {
systemd.services.pushlog = {
description = "Pushlog journal forwarder";
requires = ["network-online.target" "systemd-journald.service"];
after = ["network-online.target" "systemd-journald.service"];
wantedBy = ["multi-user.target"];
serviceConfig =
{
ExecStart = "${cfg.package}/bin/pushlog --config ${configFile}";
Type = "simple";
Restart = "always";
RestartSec = "5s";
# Hardening
CapabilityBoundingSet = "";
DynamicUser = true;
Group = "systemd-journal";
LockPersonality = true;
MemoryDenyWriteExecute = true;
NoNewPrivileges = true;
PrivateDevices = true;
PrivateTmp = true;
PrivateUsers = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectProc = "noaccess";
ProtectSystem = "strict";
RestrictAddressFamilies = ["AF_INET" "AF_INET6"];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallFilter = "~@aio @chown @clock @cpu-emulation @debug @keyring @ipc @module @mount @obsolete @raw-io @reboot @setuid @swap @privileged @resources";
UMask = "0077";
}
// optionalAttrs (cfg.environmentFile != null) {
EnvironmentFile = cfg.environmentFile;
};
};
});
}