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