1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.lighttpd.collectd;
7
8 collectionConf = pkgs.writeText "collection.conf" ''
9 datadir: "${config.services.collectd.dataDir}"
10 libdir: "${config.services.collectd.package}/lib/collectd"
11 '';
12
13 defaultCollectionCgi = config.services.collectd.package.overrideDerivation(old: {
14 name = "collection.cgi";
15 configurePhase = "true";
16 buildPhase = "true";
17 installPhase = ''
18 substituteInPlace contrib/collection.cgi --replace '"/etc/collection.conf"' '$ENV{COLLECTION_CONF}'
19 cp contrib/collection.cgi $out
20 '';
21 });
22in
23{
24
25 options.services.lighttpd.collectd = {
26
27 enable = mkEnableOption "collectd subservice accessible at http://yourserver/collectd";
28
29 collectionCgi = mkOption {
30 type = types.path;
31 default = defaultCollectionCgi;
32 description = ''
33 Path to collection.cgi script from (collectd sources)/contrib/collection.cgi
34 This option allows to use a customized version
35 '';
36 };
37 };
38
39 config = mkIf cfg.enable {
40 services.lighttpd.enableModules = [ "mod_cgi" "mod_alias" "mod_setenv" ];
41
42 services.lighttpd.extraConfig = ''
43 $HTTP["url"] =~ "^/collectd" {
44 cgi.assign = (
45 ".cgi" => "${pkgs.perl}/bin/perl"
46 )
47 alias.url = (
48 "/collectd" => "${cfg.collectionCgi}"
49 )
50 setenv.add-environment = (
51 "PERL5LIB" => "${with pkgs; lib.makePerlPath [ perlPackages.CGI perlPackages.HTMLParser perlPackages.URI rrdtool ]}",
52 "COLLECTION_CONF" => "${collectionConf}"
53 )
54 }
55 '';
56 };
57
58}