1{ config, pkgs, lib, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.syslog-ng;
8
9 syslogngConfig = pkgs.writeText "syslog-ng.conf" ''
10 ${cfg.configHeader}
11 ${cfg.extraConfig}
12 '';
13
14 ctrlSocket = "/run/syslog-ng/syslog-ng.ctl";
15 pidFile = "/run/syslog-ng/syslog-ng.pid";
16 persistFile = "/var/syslog-ng/syslog-ng.persist";
17
18 syslogngOptions = [
19 "--foreground"
20 "--module-path=${concatStringsSep ":" (["${cfg.package}/lib/syslog-ng"] ++ cfg.extraModulePaths)}"
21 "--cfgfile=${syslogngConfig}"
22 "--control=${ctrlSocket}"
23 "--persist-file=${persistFile}"
24 "--pidfile=${pidFile}"
25 ];
26
27in {
28 imports = [
29 (mkRemovedOptionModule [ "services" "syslog-ng" "serviceName" ] "")
30 (mkRemovedOptionModule [ "services" "syslog-ng" "listenToJournal" ] "")
31 ];
32
33 options = {
34
35 services.syslog-ng = {
36 enable = mkOption {
37 type = types.bool;
38 default = false;
39 description = ''
40 Whether to enable the syslog-ng daemon.
41 '';
42 };
43 package = mkPackageOption pkgs "syslogng" { };
44 extraModulePaths = mkOption {
45 type = types.listOf types.str;
46 default = [];
47 description = ''
48 A list of paths that should be included in syslog-ng's
49 `--module-path` option. They should usually
50 end in `/lib/syslog-ng`
51 '';
52 };
53 extraConfig = mkOption {
54 type = types.lines;
55 default = "";
56 description = ''
57 Configuration added to the end of `syslog-ng.conf`.
58 '';
59 };
60 configHeader = mkOption {
61 type = types.lines;
62 default = ''
63 @version: 4.4
64 @include "scl.conf"
65 '';
66 description = ''
67 The very first lines of the configuration file. Should usually contain
68 the syslog-ng version header.
69 '';
70 };
71 };
72 };
73
74 config = mkIf cfg.enable {
75 systemd.services.syslog-ng = {
76 description = "syslog-ng daemon";
77 preStart = "mkdir -p /{var,run}/syslog-ng";
78 wantedBy = [ "multi-user.target" ];
79 after = [ "multi-user.target" ]; # makes sure hostname etc is set
80 serviceConfig = {
81 Type = "notify";
82 PIDFile = pidFile;
83 StandardOutput = "null";
84 Restart = "on-failure";
85 ExecStart = "${cfg.package}/sbin/syslog-ng ${concatStringsSep " " syslogngOptions}";
86 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
87 };
88 };
89 };
90
91}