1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8
9 cfg = config.services.rsyslogd;
10
11 syslogConf = pkgs.writeText "syslog.conf" ''
12 $ModLoad imuxsock
13 $SystemLogSocketName /run/systemd/journal/syslog
14 $WorkDirectory /var/spool/rsyslog
15
16 ${cfg.defaultConfig}
17 ${cfg.extraConfig}
18 '';
19
20 defaultConf = ''
21 # "local1" is used for dhcpd messages.
22 local1.* -/var/log/dhcpd
23
24 mail.* -/var/log/mail
25
26 *.=warning;*.=err -/var/log/warn
27 *.crit /var/log/warn
28
29 *.*;mail.none;local1.none -/var/log/messages
30 '';
31
32in
33
34{
35 ###### interface
36
37 options = {
38
39 services.rsyslogd = {
40
41 enable = lib.mkOption {
42 type = lib.types.bool;
43 default = false;
44 description = ''
45 Whether to enable syslogd. Note that systemd also logs
46 syslog messages, so you normally don't need to run syslogd.
47 '';
48 };
49
50 defaultConfig = lib.mkOption {
51 type = lib.types.lines;
52 default = defaultConf;
53 description = ''
54 The default {file}`syslog.conf` file configures a
55 fairly standard setup of log files, which can be extended by
56 means of {var}`extraConfig`.
57 '';
58 };
59
60 extraConfig = lib.mkOption {
61 type = lib.types.lines;
62 default = "";
63 example = "news.* -/var/log/news";
64 description = ''
65 Additional text appended to {file}`syslog.conf`,
66 i.e. the contents of {var}`defaultConfig`.
67 '';
68 };
69
70 extraParams = lib.mkOption {
71 type = lib.types.listOf lib.types.str;
72 default = [ ];
73 example = [ "-m 0" ];
74 description = ''
75 Additional parameters passed to {command}`rsyslogd`.
76 '';
77 };
78
79 };
80
81 };
82
83 ###### implementation
84
85 config = lib.mkIf cfg.enable {
86
87 environment.systemPackages = [ pkgs.rsyslog ];
88
89 systemd.services.syslog = {
90 description = "Syslog Daemon";
91
92 requires = [ "syslog.socket" ];
93
94 wantedBy = [ "multi-user.target" ];
95
96 serviceConfig = {
97 ExecStart = "${pkgs.rsyslog}/sbin/rsyslogd ${toString cfg.extraParams} -f ${syslogConf} -n";
98 ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p /var/spool/rsyslog";
99 # Prevent syslogd output looping back through journald.
100 StandardOutput = "null";
101 };
102 };
103
104 };
105
106}