| 
									
										
										
										
											2014-08-11 15:05:59 +02:00
										 |  |  | { config, pkgs, lib, ... }: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | with lib; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   cfg = config.services.syslog-ng; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   syslogngConfig = pkgs.writeText "syslog-ng.conf" ''
 | 
					
						
							| 
									
										
										
										
											2014-10-16 07:58:54 +02:00
										 |  |  |     ${cfg.configHeader} | 
					
						
							| 
									
										
										
										
											2014-08-11 15:05:59 +02:00
										 |  |  |     ${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" | 
					
						
							| 
									
										
										
										
											2014-09-08 22:17:56 +02:00
										 |  |  |     "--module-path=${concatStringsSep ":" (["${cfg.package}/lib/syslog-ng"] ++ cfg.extraModulePaths)}" | 
					
						
							| 
									
										
										
										
											2014-08-11 15:05:59 +02:00
										 |  |  |     "--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. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2014-09-08 22:17:56 +02:00
										 |  |  |       package = mkOption { | 
					
						
							|  |  |  |         type = types.package; | 
					
						
							|  |  |  |         default = pkgs.syslogng; | 
					
						
							| 
									
										
										
										
											2016-01-17 19:34:55 +01:00
										 |  |  |         defaultText = "pkgs.syslogng"; | 
					
						
							| 
									
										
										
										
											2014-09-08 22:17:56 +02:00
										 |  |  |         description = ''
 | 
					
						
							|  |  |  |           The package providing syslog-ng binaries. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2014-08-11 15:05:59 +02:00
										 |  |  |       extraModulePaths = mkOption { | 
					
						
							|  |  |  |         type = types.listOf types.str; | 
					
						
							|  |  |  |         default = []; | 
					
						
							| 
									
										
										
										
											2014-08-27 23:41:15 +02:00
										 |  |  |         example = literalExample ''
 | 
					
						
							|  |  |  |           [ "''${pkgs.syslogng_incubator}/lib/syslog-ng" ] | 
					
						
							|  |  |  |         '';
 | 
					
						
							| 
									
										
										
										
											2014-08-11 15:05:59 +02:00
										 |  |  |         description = ''
 | 
					
						
							|  |  |  |           A list of paths that should be included in syslog-ng's | 
					
						
							|  |  |  |           <literal>--module-path</literal> option. They should usually | 
					
						
							|  |  |  |           end in <literal>/lib/syslog-ng</literal> | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |       extraConfig = mkOption { | 
					
						
							|  |  |  |         type = types.lines; | 
					
						
							|  |  |  |         default = ""; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Configuration added to the end of <literal>syslog-ng.conf</literal>. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2014-10-16 07:58:54 +02:00
										 |  |  |       configHeader = mkOption { | 
					
						
							|  |  |  |         type = types.lines; | 
					
						
							|  |  |  |         default = ''
 | 
					
						
							| 
									
										
										
										
											2014-11-06 21:47:02 +01:00
										 |  |  |           @version: 3.6 | 
					
						
							| 
									
										
										
										
											2014-10-16 07:58:54 +02:00
										 |  |  |           @include "scl.conf" | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           The very first lines of the configuration file. Should usually contain | 
					
						
							|  |  |  |           the syslog-ng version header. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2014-08-11 15:05:59 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   config = mkIf cfg.enable { | 
					
						
							| 
									
										
										
										
											2014-10-14 15:20:27 +02:00
										 |  |  |     systemd.services.syslog-ng = { | 
					
						
							|  |  |  |       description = "syslog-ng daemon"; | 
					
						
							| 
									
										
										
										
											2014-08-11 15:05:59 +02:00
										 |  |  |       preStart = "mkdir -p /{var,run}/syslog-ng"; | 
					
						
							| 
									
										
										
										
											2014-11-06 21:47:02 +01:00
										 |  |  |       wantedBy = [ "multi-user.target" ]; | 
					
						
							| 
									
										
										
										
											2014-10-14 15:20:27 +02:00
										 |  |  |       after = [ "multi-user.target" ]; # makes sure hostname etc is set | 
					
						
							| 
									
										
										
										
											2014-08-11 15:05:59 +02:00
										 |  |  |       serviceConfig = { | 
					
						
							|  |  |  |         Type = "notify"; | 
					
						
							| 
									
										
										
										
											2018-08-16 08:13:36 +03:00
										 |  |  |         PIDFile = pidFile; | 
					
						
							| 
									
										
										
										
											2014-08-11 15:05:59 +02:00
										 |  |  |         StandardOutput = "null"; | 
					
						
							|  |  |  |         Restart = "on-failure"; | 
					
						
							| 
									
										
										
										
											2014-09-08 22:17:56 +02:00
										 |  |  |         ExecStart = "${cfg.package}/sbin/syslog-ng ${concatStringsSep " " syslogngOptions}"; | 
					
						
							| 
									
										
										
										
											2018-08-16 08:13:36 +03:00
										 |  |  |         ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; | 
					
						
							| 
									
										
										
										
											2014-08-11 15:05:59 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |