2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-03-15 12:55:49 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2013-03-15 12:55:49 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.rsyslogd;
|
|
|
|
|
|
|
|
syslogConf = pkgs.writeText "syslog.conf" ''
|
|
|
|
$ModLoad imuxsock
|
|
|
|
$SystemLogSocketName /run/systemd/journal/syslog
|
2013-03-17 21:36:25 +01:00
|
|
|
$WorkDirectory /var/spool/rsyslog
|
2013-03-15 12:55:49 +01:00
|
|
|
|
|
|
|
${cfg.defaultConfig}
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
|
|
|
defaultConf = ''
|
|
|
|
# "local1" is used for dhcpd messages.
|
|
|
|
local1.* -/var/log/dhcpd
|
|
|
|
|
|
|
|
mail.* -/var/log/mail
|
|
|
|
|
|
|
|
*.=warning;*.=err -/var/log/warn
|
|
|
|
*.crit /var/log/warn
|
|
|
|
|
|
|
|
*.*;mail.none;local1.none -/var/log/messages
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.rsyslogd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable syslogd. Note that systemd also logs
|
|
|
|
syslog messages, so you normally don't need to run syslogd.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
defaultConfig = mkOption {
|
2019-08-08 22:48:27 +02:00
|
|
|
type = types.lines;
|
2013-03-15 12:55:49 +01:00
|
|
|
default = defaultConf;
|
|
|
|
description = ''
|
|
|
|
The default <filename>syslog.conf</filename> file configures a
|
|
|
|
fairly standard setup of log files, which can be extended by
|
|
|
|
means of <varname>extraConfig</varname>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2019-08-08 22:48:27 +02:00
|
|
|
type = types.lines;
|
2013-03-15 12:55:49 +01:00
|
|
|
default = "";
|
|
|
|
example = "news.* -/var/log/news";
|
|
|
|
description = ''
|
|
|
|
Additional text appended to <filename>syslog.conf</filename>,
|
|
|
|
i.e. the contents of <varname>defaultConfig</varname>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraParams = mkOption {
|
2015-06-15 18:18:46 +02:00
|
|
|
type = types.listOf types.str;
|
2013-03-15 12:55:49 +01:00
|
|
|
default = [ ];
|
|
|
|
example = [ "-m 0" ];
|
|
|
|
description = ''
|
|
|
|
Additional parameters passed to <command>rsyslogd</command>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.rsyslog ];
|
|
|
|
|
|
|
|
systemd.services.syslog =
|
|
|
|
{ description = "Syslog Daemon";
|
|
|
|
|
|
|
|
requires = [ "syslog.socket" ];
|
|
|
|
|
2013-03-27 13:58:12 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2013-03-15 12:55:49 +01:00
|
|
|
|
|
|
|
serviceConfig =
|
|
|
|
{ ExecStart = "${pkgs.rsyslog}/sbin/rsyslogd ${toString cfg.extraParams} -f ${syslogConf} -n";
|
2013-03-17 21:36:25 +01:00
|
|
|
ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p /var/spool/rsyslog";
|
2013-03-15 12:55:49 +01:00
|
|
|
# Prevent syslogd output looping back through journald.
|
|
|
|
StandardOutput = "null";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|