2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-03-15 11:55:49 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2013-03-15 11:55:49 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.rsyslogd;
|
|
|
|
|
|
|
|
syslogConf = pkgs.writeText "syslog.conf" ''
|
|
|
|
$ModLoad imuxsock
|
|
|
|
$SystemLogSocketName /run/systemd/journal/syslog
|
2013-03-17 20:36:25 +00:00
|
|
|
$WorkDirectory /var/spool/rsyslog
|
2013-03-15 11:55:49 +00: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 = lib.mdDoc ''
|
|
|
|
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 20:48:27 +00:00
|
|
|
type = types.lines;
|
2013-03-15 11:55:49 +00:00
|
|
|
default = defaultConf;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
The default {file}`syslog.conf` file configures a
|
|
|
|
fairly standard setup of log files, which can be extended by
|
|
|
|
means of {var}`extraConfig`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.lines;
|
2013-03-15 11:55:49 +00:00
|
|
|
default = "";
|
|
|
|
example = "news.* -/var/log/news";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Additional text appended to {file}`syslog.conf`,
|
|
|
|
i.e. the contents of {var}`defaultConfig`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraParams = mkOption {
|
2015-06-15 16:18:46 +00:00
|
|
|
type = types.listOf types.str;
|
2013-03-15 11:55:49 +00:00
|
|
|
default = [ ];
|
|
|
|
example = [ "-m 0" ];
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Additional parameters passed to {command}`rsyslogd`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.rsyslog ];
|
|
|
|
|
|
|
|
systemd.services.syslog =
|
|
|
|
{ description = "Syslog Daemon";
|
|
|
|
|
|
|
|
requires = [ "syslog.socket" ];
|
|
|
|
|
2013-03-27 12:58:12 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2013-03-15 11:55:49 +00:00
|
|
|
|
|
|
|
serviceConfig =
|
|
|
|
{ ExecStart = "${pkgs.rsyslog}/sbin/rsyslogd ${toString cfg.extraParams} -f ${syslogConf} -n";
|
2013-03-17 20:36:25 +00:00
|
|
|
ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p /var/spool/rsyslog";
|
2013-03-15 11:55:49 +00:00
|
|
|
# Prevent syslogd output looping back through journald.
|
|
|
|
StandardOutput = "null";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|