From 7b5829c314d08a8f8a6c2b49bb3a8740602c0572 Mon Sep 17 00:00:00 2001 From: Rickard Nilsson Date: Mon, 11 Aug 2014 15:05:59 +0200 Subject: [PATCH] Add NixOS module for syslog-ng --- nixos/modules/module-list.nix | 1 + nixos/modules/services/logging/syslog-ng.nix | 83 ++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 nixos/modules/services/logging/syslog-ng.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index ea647b43c9d..4806c0e9331 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -135,6 +135,7 @@ ./services/logging/logstash.nix ./services/logging/rsyslogd.nix ./services/logging/syslogd.nix + ./services/logging/syslog-ng.nix ./services/mail/dovecot.nix ./services/mail/freepops.nix ./services/mail/mail.nix diff --git a/nixos/modules/services/logging/syslog-ng.nix b/nixos/modules/services/logging/syslog-ng.nix new file mode 100644 index 00000000000..8b892a33bb7 --- /dev/null +++ b/nixos/modules/services/logging/syslog-ng.nix @@ -0,0 +1,83 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + + cfg = config.services.syslog-ng; + + syslogngConfig = pkgs.writeText "syslog-ng.conf" '' + @version: 3.5 + @include "scl.conf" + ${cfg.extraConfig} + ''; + + ctrlSocket = "/run/syslog-ng/syslog-ng.ctl"; + pidFile = "/run/syslog-ng/syslog-ng.pid"; + persistFile = "/var/syslog-ng/syslog-ng.persist"; + + syslogngOptions = [ + "--foreground" + "--module-path=${concatStringsSep ":" (["${pkgs.syslogng}/lib/syslog-ng"] ++ cfg.extraModulePaths)}" + "--cfgfile=${syslogngConfig}" + "--control=${ctrlSocket}" + "--persist-file=${persistFile}" + "--pidfile=${pidFile}" + ]; + +in { + + options = { + + services.syslog-ng = { + enable = mkOption { + type = types.bool; + default = false; + description = '' + Whether to enable the syslog-ng daemon. + ''; + }; + serviceName = mkOption { + type = types.str; + default = "syslog-ng"; + description = '' + The name of the systemd service that runs syslog-ng. Set this to + syslog if you want journald to automatically + forward all logs to syslog-ng. + ''; + }; + extraModulePaths = mkOption { + type = types.listOf types.str; + default = []; + example = [ "${pkgs.syslogng_incubator}/lib/syslog-ng" ]; + description = '' + A list of paths that should be included in syslog-ng's + --module-path option. They should usually + end in /lib/syslog-ng + ''; + }; + extraConfig = mkOption { + type = types.lines; + default = ""; + description = '' + Configuration added to the end of syslog-ng.conf. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + systemd.services."${cfg.serviceName}" = { + wantedBy = [ "multi-user.target" ]; + preStart = "mkdir -p /{var,run}/syslog-ng"; + serviceConfig = { + Type = "notify"; + Sockets = "syslog.socket"; + StandardOutput = "null"; + Restart = "on-failure"; + ExecStart = "${pkgs.syslogng}/sbin/syslog-ng ${concatStringsSep " " syslogngOptions}"; + }; + }; + }; + +}