1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7let
8
9 cfg = config.services.syslog-ng;
10
11 syslogngConfig = pkgs.writeText "syslog-ng.conf" ''
12 ${cfg.configHeader}
13 ${cfg.extraConfig}
14 '';
15
16 ctrlSocket = "/run/syslog-ng/syslog-ng.ctl";
17 pidFile = "/run/syslog-ng/syslog-ng.pid";
18 persistFile = "/var/syslog-ng/syslog-ng.persist";
19
20 syslogngOptions = [
21 "--foreground"
22 "--module-path=${
23 lib.concatStringsSep ":" ([ "${cfg.package}/lib/syslog-ng" ] ++ cfg.extraModulePaths)
24 }"
25 "--cfgfile=${syslogngConfig}"
26 "--control=${ctrlSocket}"
27 "--persist-file=${persistFile}"
28 "--pidfile=${pidFile}"
29 ];
30
31in
32{
33 imports = [
34 (lib.mkRemovedOptionModule [ "services" "syslog-ng" "serviceName" ] "")
35 (lib.mkRemovedOptionModule [ "services" "syslog-ng" "listenToJournal" ] "")
36 ];
37
38 options = {
39
40 services.syslog-ng = {
41 enable = lib.mkOption {
42 type = lib.types.bool;
43 default = false;
44 description = ''
45 Whether to enable the syslog-ng daemon.
46 '';
47 };
48 package = lib.mkPackageOption pkgs "syslogng" { };
49 extraModulePaths = lib.mkOption {
50 type = lib.types.listOf lib.types.str;
51 default = [ ];
52 description = ''
53 A list of paths that should be included in syslog-ng's
54 `--module-path` option. They should usually
55 end in `/lib/syslog-ng`
56 '';
57 };
58 extraConfig = lib.mkOption {
59 type = lib.types.lines;
60 default = "";
61 description = ''
62 Configuration added to the end of `syslog-ng.conf`.
63 '';
64 };
65 configHeader = lib.mkOption {
66 type = lib.types.lines;
67 default = ''
68 @version: 4.4
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 = lib.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 PIDFile = pidFile;
88 StandardOutput = "null";
89 Restart = "on-failure";
90 ExecStart = "${cfg.package}/sbin/syslog-ng ${lib.concatStringsSep " " syslogngOptions}";
91 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
92 };
93 };
94 };
95
96}