2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.rsyslogd;
|
|
|
|
|
|
|
|
syslogConf = pkgs.writeText "syslog.conf" ''
|
|
|
|
$ModLoad imuxsock
|
|
|
|
$SystemLogSocketName /run/systemd/journal/syslog
|
|
|
|
$WorkDirectory /var/spool/rsyslog
|
|
|
|
|
|
|
|
${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;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Whether to enable syslogd. Note that systemd also logs
|
|
|
|
syslog messages, so you normally don't need to run syslogd.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
defaultConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = defaultConf;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-09-09 14:08:57 +00:00
|
|
|
The default {file}`syslog.conf` file configures a
|
2020-04-24 23:36:52 +00:00
|
|
|
fairly standard setup of log files, which can be extended by
|
2022-09-09 14:08:57 +00:00
|
|
|
means of {var}`extraConfig`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = "news.* -/var/log/news";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-09-09 14:08:57 +00:00
|
|
|
Additional text appended to {file}`syslog.conf`,
|
|
|
|
i.e. the contents of {var}`defaultConfig`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraParams = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "-m 0" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
Additional parameters passed to {command}`rsyslogd`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.rsyslog ];
|
|
|
|
|
|
|
|
systemd.services.syslog =
|
|
|
|
{ description = "Syslog Daemon";
|
|
|
|
|
|
|
|
requires = [ "syslog.socket" ];
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig =
|
|
|
|
{ ExecStart = "${pkgs.rsyslog}/sbin/rsyslogd ${toString cfg.extraParams} -f ${syslogConf} -n";
|
|
|
|
ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p /var/spool/rsyslog";
|
|
|
|
# Prevent syslogd output looping back through journald.
|
|
|
|
StandardOutput = "null";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|