summaryrefslogtreecommitdiffstats
path: root/nixos
diff options
context:
space:
mode:
authorGuillaume Girol <symphorien+git@xlumurb.eu>2021-12-22 12:00:00 +0000
committerBjørn Forsman <bjorn.forsman@gmail.com>2021-12-23 00:08:43 +0100
commitd96a3994cc9b032778a3d3f3a29f660332ef91bc (patch)
tree93febaf7d9329ffba237b52231d66cd465ae5dc9 /nixos
parentb55a253e154160d2fde0db1e05ea3a16b46bcb18 (diff)
nixos/collectd: validate config file syntax at build time
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/monitoring/collectd.nix21
1 files changed, 20 insertions, 1 deletions
diff --git a/nixos/modules/services/monitoring/collectd.nix b/nixos/modules/services/monitoring/collectd.nix
index 660d108587de..8d81737a3ef0 100644
--- a/nixos/modules/services/monitoring/collectd.nix
+++ b/nixos/modules/services/monitoring/collectd.nix
@@ -5,7 +5,7 @@ with lib;
let
cfg = config.services.collectd;
- conf = pkgs.writeText "collectd.conf" ''
+ unvalidated_conf = pkgs.writeText "collectd-unvalidated.conf" ''
BaseDir "${cfg.dataDir}"
AutoLoadPlugin ${boolToString cfg.autoLoadPlugin}
Hostname "${config.networking.hostName}"
@@ -30,6 +30,15 @@ let
${cfg.extraConfig}
'';
+ conf = if cfg.validateConfig then
+ pkgs.runCommand "collectd.conf" {} ''
+ echo testing ${unvalidated_conf}
+ # collectd -t fails if BaseDir does not exist.
+ sed '1s/^BaseDir.*$/BaseDir "."/' ${unvalidated_conf} > collectd.conf
+ ${package}/bin/collectd -t -C collectd.conf
+ cp ${unvalidated_conf} $out
+ '' else unvalidated_conf;
+
package =
if cfg.buildMinimalPackage
then minimalPackage
@@ -43,6 +52,16 @@ in {
options.services.collectd = with types; {
enable = mkEnableOption "collectd agent";
+ validateConfig = mkOption {
+ default = true;
+ description = ''
+ Validate the syntax of collectd configuration file at build time.
+ Disable this if you use the Include directive on files unavailable in
+ the build sandbox, or when cross-compiling.
+ '';
+ type = types.bool;
+ };
+
package = mkOption {
default = pkgs.collectd;
defaultText = literalExpression "pkgs.collectd";