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
29 options = {
30
31 services.syslog-ng = {
32 enable = mkOption {
33 type = types.bool;
34 default = false;
35 description = ''
36 Whether to enable the syslog-ng daemon.
37 '';
38 };
39 package = mkOption {
40 type = types.package;
41 default = pkgs.syslogng;
42 description = ''
43 The package providing syslog-ng binaries.
44 '';
45 };
46 extraModulePaths = mkOption {
47 type = types.listOf types.str;
48 default = [];
49 example = literalExample ''
50 [ "''${pkgs.syslogng_incubator}/lib/syslog-ng" ]
51 '';
52 description = ''
53 A list of paths that should be included in syslog-ng's
54 <literal>--module-path</literal> option. They should usually
55 end in <literal>/lib/syslog-ng</literal>
56 '';
57 };
58 extraConfig = mkOption {
59 type = types.lines;
60 default = "";
61 description = ''
62 Configuration added to the end of <literal>syslog-ng.conf</literal>.
63 '';
64 };
65 configHeader = mkOption {
66 type = types.lines;
67 default = ''
68 @version: 3.6
69 @include "scl.conf"
70 '';
71 description = ''
72 The very first lines of the configuration file. Should usually contain
73 the syslog-ng version header.
74 '';
75 };
76 };
77 };
78
79 config = mkIf cfg.enable {
80 systemd.services.syslog-ng = {
81 description = "syslog-ng daemon";
82 preStart = "mkdir -p /{var,run}/syslog-ng";
83 wantedBy = [ "multi-user.target" ];
84 after = [ "multi-user.target" ]; # makes sure hostname etc is set
85 serviceConfig = {
86 Type = "notify";
87 StandardOutput = "null";
88 Restart = "on-failure";
89 ExecStart = "${cfg.package}/sbin/syslog-ng ${concatStringsSep " " syslogngOptions}";
90 };
91 };
92 };
93
94}