at 16.09-beta 3.0 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.syslogd; 8 9 syslogConf = pkgs.writeText "syslog.conf" '' 10 ${if (cfg.tty != "") then "kern.warning;*.err;authpriv.none /dev/${cfg.tty}" else ""} 11 ${cfg.defaultConfig} 12 ${cfg.extraConfig} 13 ''; 14 15 defaultConf = '' 16 # Send emergency messages to all users. 17 *.emerg * 18 19 # "local1" is used for dhcpd messages. 20 local1.* -/var/log/dhcpd 21 22 mail.* -/var/log/mail 23 24 *.=warning;*.=err -/var/log/warn 25 *.crit /var/log/warn 26 27 *.*;mail.none;local1.none -/var/log/messages 28 ''; 29 30in 31 32{ 33 ###### interface 34 35 options = { 36 37 services.syslogd = { 38 39 enable = mkOption { 40 type = types.bool; 41 default = false; 42 description = '' 43 Whether to enable syslogd. Note that systemd also logs 44 syslog messages, so you normally don't need to run syslogd. 45 ''; 46 }; 47 48 tty = mkOption { 49 type = types.str; 50 default = "tty10"; 51 description = '' 52 The tty device on which syslogd will print important log 53 messages. Leave this option blank to disable tty logging. 54 ''; 55 }; 56 57 defaultConfig = mkOption { 58 type = types.lines; 59 default = defaultConf; 60 description = '' 61 The default <filename>syslog.conf</filename> file configures a 62 fairly standard setup of log files, which can be extended by 63 means of <varname>extraConfig</varname>. 64 ''; 65 }; 66 67 enableNetworkInput = mkOption { 68 type = types.bool; 69 default = false; 70 description = '' 71 Accept logging through UDP. Option -r of syslogd(8). 72 ''; 73 }; 74 75 extraConfig = mkOption { 76 type = types.lines; 77 default = ""; 78 example = "news.* -/var/log/news"; 79 description = '' 80 Additional text appended to <filename>syslog.conf</filename>, 81 i.e. the contents of <varname>defaultConfig</varname>. 82 ''; 83 }; 84 85 extraParams = mkOption { 86 type = types.listOf types.str; 87 default = [ ]; 88 example = [ "-m 0" ]; 89 description = '' 90 Additional parameters passed to <command>syslogd</command>. 91 ''; 92 }; 93 94 }; 95 96 }; 97 98 99 ###### implementation 100 101 config = mkIf cfg.enable { 102 103 environment.systemPackages = [ pkgs.sysklogd ]; 104 105 services.syslogd.extraParams = optional cfg.enableNetworkInput "-r"; 106 107 # FIXME: restarting syslog seems to break journal logging. 108 systemd.services.syslog = 109 { description = "Syslog Daemon"; 110 111 requires = [ "syslog.socket" ]; 112 113 wantedBy = [ "multi-user.target" ]; 114 115 serviceConfig = 116 { ExecStart = "${pkgs.sysklogd}/sbin/syslogd ${toString cfg.extraParams} -f ${syslogConf} -n"; 117 # Prevent syslogd output looping back through journald. 118 StandardOutput = "null"; 119 }; 120 }; 121 122 }; 123 124}