summary refs log tree commit diff
path: root/nixos/modules/services/web-servers/apache-httpd/zabbix.nix
blob: cab16593bcbc7054b6ca1313b5342b12ba8f6a9e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{ config, lib, pkgs, serverInfo, ... }:

with lib;

let

  # The Zabbix PHP frontend needs to be able to write its
  # configuration settings (the connection info to the database) to
  # the "conf" subdirectory.  So symlink $out/conf to some directory
  # outside of the Nix store where we want to keep this stateful info.
  # Note that different instances of the frontend will therefore end
  # up with their own copies of the PHP sources.  !!! Alternatively,
  # we could generate zabbix.conf.php declaratively.
  zabbixPHP = pkgs.runCommand "${pkgs.zabbix.server.name}-php" {}
    ''
      cp -rs ${pkgs.zabbix.server}/share/zabbix/php "$out"
      chmod -R u+w $out
      ln -s "${if config.configFile == null
               then "${config.stateDir}/zabbix.conf.php"
               else config.configFile}" "$out/conf/zabbix.conf.php"
    '';

in

{

  enablePHP = true;

  phpOptions =
    ''
      post_max_size = 32M
      max_execution_time = 300
      max_input_time = 300
    '';

  extraConfig = ''
    Alias ${config.urlPrefix}/ ${zabbixPHP}/

    <Directory ${zabbixPHP}>
      DirectoryIndex index.php
      Order deny,allow
      Allow from *
    </Directory>
  '';

  startupScript = pkgs.writeScript "zabbix-startup-hook" ''
    mkdir -p ${config.stateDir}
    chown -R ${serverInfo.serverConfig.user} ${config.stateDir}
  '';

  # The frontend needs "ps" to find out whether zabbix_server is running.
  extraServerPath = [ pkgs.procps ];

  options = {

    urlPrefix = mkOption {
      default = "/zabbix";
      description = "
        The URL prefix under which the Zabbix service appears.
        Use the empty string to have it appear in the server root.
      ";
    };

    configFile = mkOption {
      default = null;
      type = types.nullOr types.path;
      description = ''
        The configuration file (zabbix.conf.php) which contains the database
        connection settings. If not set, the configuration settings will created
        by the web installer.
      '';
    };

    stateDir = mkOption {
      default = "/var/lib/zabbix/frontend";
      description = "
        Directory where the dynamically generated configuration data
        of the PHP frontend will be stored.
      ";
    };

  };

}