3 nixosModule = self.nixosModules.naemon;
4 nixosModules.naemon = { config, lib, pkgs, ... }:
8 cfg = config.services.naemon;
10 naemonConfig = pkgs.runCommand "naemon-config" {
11 objectsFile = pkgs.writeText "naemon_objects.cfg" cfg.objectDefs;
12 resourceFile = config.secrets.fullPaths."naemon/resources.cfg";
13 extraConfig = pkgs.writeText "extra.cfg" cfg.extraConfig;
14 inherit (cfg) logDir varDir runDir cacheDir;
16 substituteAll ${./naemon.cfg} $out
17 cat $extraConfig >> $out
21 # Necessary for situations where flake gets included multiple times
22 key = builtins.hashString "sha256" (builtins.path { path = self.sourceInfo.outPath; name = "source"; });
30 xlink:href='http://www.naemon.org/'>Naemon</link> to monitor
31 your system or network.
35 objectDefs = mkOption {
39 A list of Naemon object configuration that must define
40 the hosts, host groups, services and contacts for the
41 network that you want Naemon to monitor.
45 extraResource = mkOption {
49 # Sets $USER2$ to be the path to event handlers
50 #$USER2$=/usr/lib/monitoring-plugins/eventhandlers
52 # Store some usernames and passwords (hidden from the CGIs)
57 Lines to add to the resource file
58 # You can define $USERx$ macros in this file, which can in turn be used
59 # in command definitions in your host config file(s). $USERx$ macros are
60 # useful for storing sensitive information such as usernames, passwords,
61 # etc. They are also handy for specifying the path to plugins and
62 # event handlers - if you decide to move the plugins or event handlers to
63 # a different directory in the future, you can just update one or two
64 # $USERx$ macros, instead of modifying a lot of command definitions.
66 # Naemon supports up to 256 $USERx$ macros ($USER1$ through $USER256$)
68 # Resource files may also be used to store configuration directives for
69 # external data sources like MySQL...
74 extraConfig = mkOption {
78 Extra config to append to main config
85 description = "User for naemon";
91 description = "Group for naemon";
96 default = "/var/lib/naemon";
97 description = "The directory where naemon stores its data";
100 cacheDir = mkOption {
102 default = "/var/cache/naemon";
103 description = "The directory where naemon stores its cache";
108 default = "/run/naemon";
109 description = "The directory where naemon stores its runtime files";
114 default = "/var/log/naemon";
115 description = "The directory where naemon stores its log files";
119 type = types.package;
120 default = pkgs.naemon.override {
121 inherit (cfg) varDir cacheDir logDir runDir user group;
124 Naemon package to use
131 config = mkIf cfg.enable {
133 "naemon/resources.cfg" = {
136 permissions = "0400";
138 $USER1$=${pkgs.monitoring-plugins}/libexec
141 keyDependencies = [ pkgs.monitoring-plugins ];
145 users.users = optionalAttrs (cfg.user == "naemon") {
148 uid = config.ids.uids.nagios;
149 extraGroups = [ "keys" ];
152 users.groups = optionalAttrs (cfg.user == "naemon") {
154 gid = config.ids.gids.nagios;
158 services.filesWatcher.naemon = {
159 paths = [ config.secrets.fullPaths."naemon/resources.cfg" ];
161 systemd.services.naemon = {
162 description = "Naemon monitoring daemon";
163 path = [ cfg.package ];
164 wantedBy = [ "multi-user.target" ];
165 after = [ "network.target" ];
167 preStart = "${cfg.package}/bin/naemon -vp ${naemonConfig}";
168 script = "${cfg.package}/bin/naemon --daemon ${naemonConfig}";
169 reload = "${pkgs.utillinux}/bin/kill -HUP $MAINPID";
174 StandardOutput = "journal";
175 StandardError = "inherit";
176 PIDFile = "${cfg.runDir}/naemon.pid";
177 LogsDirectory = assert lib.strings.hasPrefix "/var/log/" cfg.logDir;
178 lib.strings.removePrefix "/var/log/" cfg.logDir;
179 CacheDirectory = assert lib.strings.hasPrefix "/var/cache/" cfg.cacheDir;
180 let unprefixed = lib.strings.removePrefix "/var/cache/" cfg.cacheDir;
181 in [ unprefixed "${unprefixed}/checkresults" ];
182 StateDirectory = assert lib.strings.hasPrefix "/var/lib/" cfg.varDir;
183 lib.strings.removePrefix "/var/lib/" cfg.varDir;
184 RuntimeDirectory = assert lib.strings.hasPrefix "/run/" cfg.runDir;
185 lib.strings.removePrefix "/run/" cfg.runDir;