1 { config, lib, options, pkgs, ... }:
6 cfg = config.services.lighttpd.collectd;
7 opt = options.services.lighttpd.collectd;
9 collectionConf = pkgs.writeText "collection.conf" ''
10 datadir: "${config.services.collectd.dataDir}"
11 libdir: "${config.services.collectd.package}/lib/collectd"
14 defaultCollectionCgi = config.services.collectd.package.overrideDerivation(old: {
15 name = "collection.cgi";
19 substituteInPlace contrib/collection.cgi --replace '"/etc/collection.conf"' '$ENV{COLLECTION_CONF}'
20 cp contrib/collection.cgi $out
26 options.services.lighttpd.collectd = {
28 enable = mkEnableOption (lib.mdDoc "collectd subservice accessible at http://yourserver/collectd");
30 collectionCgi = mkOption {
32 default = defaultCollectionCgi;
33 defaultText = literalMD ''
34 `config.${options.services.collectd.package}` configured for lighttpd
36 description = lib.mdDoc ''
37 Path to collection.cgi script from (collectd sources)/contrib/collection.cgi
38 This option allows to use a customized version
43 config = mkIf cfg.enable {
44 services.lighttpd.enableModules = [ "mod_cgi" "mod_alias" "mod_setenv" ];
46 services.lighttpd.extraConfig = ''
47 $HTTP["url"] =~ "^/collectd" {
49 ".cgi" => "${pkgs.perl}/bin/perl"
52 "/collectd" => "${cfg.collectionCgi}"
54 setenv.add-environment = (
55 "PERL5LIB" => "${with pkgs.perlPackages; makePerlPath [ CGI HTMLParser URI pkgs.rrdtool ]}",
56 "COLLECTION_CONF" => "${collectionConf}"