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