1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8
9 cfg = config.services.syslogd;
10
11 syslogConf = pkgs.writeText "syslog.conf" ''
12 ${lib.optionalString (cfg.tty != "") "kern.warning;*.err;authpriv.none /dev/${cfg.tty}"}
13 ${cfg.defaultConfig}
14 ${cfg.extraConfig}
15 '';
16
17 defaultConf = ''
18 # Send emergency messages to all users.
19 *.emerg *
20
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.syslogd = {
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 tty = lib.mkOption {
51 type = lib.types.str;
52 default = "tty10";
53 description = ''
54 The tty device on which syslogd will print important log
55 messages. Leave this option blank to disable tty logging.
56 '';
57 };
58
59 defaultConfig = lib.mkOption {
60 type = lib.types.lines;
61 default = defaultConf;
62 description = ''
63 The default {file}`syslog.conf` file configures a
64 fairly standard setup of log files, which can be extended by
65 means of {var}`extraConfig`.
66 '';
67 };
68
69 enableNetworkInput = lib.mkOption {
70 type = lib.types.bool;
71 default = false;
72 description = ''
73 Accept logging through UDP. Option -r of {manpage}`syslogd(8)`.
74 '';
75 };
76
77 extraConfig = lib.mkOption {
78 type = lib.types.lines;
79 default = "";
80 example = "news.* -/var/log/news";
81 description = ''
82 Additional text appended to {file}`syslog.conf`,
83 i.e. the contents of {var}`defaultConfig`.
84 '';
85 };
86
87 extraParams = lib.mkOption {
88 type = lib.types.listOf lib.types.str;
89 default = [ ];
90 example = [ "-m 0" ];
91 description = ''
92 Additional parameters passed to {command}`syslogd`.
93 '';
94 };
95
96 };
97
98 };
99
100 ###### implementation
101
102 config = lib.mkIf cfg.enable {
103
104 assertions = [
105 {
106 assertion = !config.services.rsyslogd.enable;
107 message = "rsyslogd conflicts with syslogd";
108 }
109 ];
110
111 environment.systemPackages = [ pkgs.sysklogd ];
112
113 services.syslogd.extraParams = lib.optional cfg.enableNetworkInput "-r";
114
115 # FIXME: restarting syslog seems to break journal logging.
116 systemd.services.syslog = {
117 description = "Syslog Daemon";
118
119 requires = [ "syslog.socket" ];
120
121 wantedBy = [ "multi-user.target" ];
122
123 serviceConfig = {
124 ExecStart = "${pkgs.sysklogd}/sbin/syslogd ${toString cfg.extraParams} -f ${syslogConf} -n";
125 # Prevent syslogd output looping back through journald.
126 StandardOutput = "null";
127 };
128 };
129
130 };
131
132}