at 23.11-pre 1.8 kB view raw
1{ config, lib, options, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.lighttpd.collectd; 7 opt = options.services.lighttpd.collectd; 8 9 collectionConf = pkgs.writeText "collection.conf" '' 10 datadir: "${config.services.collectd.dataDir}" 11 libdir: "${config.services.collectd.package}/lib/collectd" 12 ''; 13 14 defaultCollectionCgi = config.services.collectd.package.overrideDerivation(old: { 15 name = "collection.cgi"; 16 dontConfigure = true; 17 buildPhase = "true"; 18 installPhase = '' 19 substituteInPlace contrib/collection.cgi --replace '"/etc/collection.conf"' '$ENV{COLLECTION_CONF}' 20 cp contrib/collection.cgi $out 21 ''; 22 }); 23in 24{ 25 26 options.services.lighttpd.collectd = { 27 28 enable = mkEnableOption (lib.mdDoc "collectd subservice accessible at http://yourserver/collectd"); 29 30 collectionCgi = mkOption { 31 type = types.path; 32 default = defaultCollectionCgi; 33 defaultText = literalMD '' 34 `config.${options.services.collectd.package}` configured for lighttpd 35 ''; 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 39 ''; 40 }; 41 }; 42 43 config = mkIf cfg.enable { 44 services.lighttpd.enableModules = [ "mod_cgi" "mod_alias" "mod_setenv" ]; 45 46 services.lighttpd.extraConfig = '' 47 $HTTP["url"] =~ "^/collectd" { 48 cgi.assign = ( 49 ".cgi" => "${pkgs.perl}/bin/perl" 50 ) 51 alias.url = ( 52 "/collectd" => "${cfg.collectionCgi}" 53 ) 54 setenv.add-environment = ( 55 "PERL5LIB" => "${with pkgs.perlPackages; makePerlPath [ CGI HTMLParser URI pkgs.rrdtool ]}", 56 "COLLECTION_CONF" => "${collectionConf}" 57 ) 58 } 59 ''; 60 }; 61 62}