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