anchor.diff:        { assertion = cfg.database.createLocally -> cfg.database.passwordFile == null;
           message = "a password cannot be specified if services.zabbixProxy.database.createLocally is set to true";
         }
  +    ];
  +
  +    services.zabbixProxy.settings = mkMerge [
  +      {
  +        LogType = "console";
  +        ListenIP = cfg.listen.ip;
  +        ListenPort = cfg.listen.port;
  +        Server = cfg.server;
  +        # TODO: set to cfg.database.socket if database type is pgsql?
  +        DBHost = optionalString (cfg.database.createLocally != true) cfg.database.host;
  +        DBName = cfg.database.name;
  +        DBUser = cfg.database.user;
  +        SocketDir = runtimeDir;
  +        FpingLocation = "/run/wrappers/bin/fping";
  +        LoadModule = builtins.attrNames cfg.modules;
  +      }
  +      (mkIf (cfg.database.createLocally != true) { DBPort = cfg.database.port; })
  +      (mkIf (cfg.database.passwordFile != null) { Include = [ "${passwordFile}" ]; })
  +      (mkIf (mysqlLocal && cfg.database.socket != null) { DBSocket = cfg.database.socket; })
  +      (mkIf (cfg.modules != {}) { LoadModulePath = "${moduleEnv}/lib"; })
       ];
   
       networking.firewall = mkIf cfg.openFirewall {
  
positive.code:         '';
        };
  
        # TODO: for bonus points migrate this to https://github.com/NixOS/rfcs/pull/42
        extraConfig = mkOption {
          default = "";
          type = types.lines;
          description = ''
            Configuration that is injected verbatim into the configuration file. Refer to
            <link xlink:href="https://www.zabbix.com/documentation/current/manual/appendix/config/zabbix_proxy"/>
            for details on supported values.
          '';
        };
  
      };
  
negative.code:     paths = attrValues cfg.modules;
    };
  
    configFile = pkgs.writeText "zabbix_proxy.conf" (toKeyValue { listsAsDuplicateKeys = true; } cfg.settings);
  
    mysqlLocal = cfg.database.createLocally && cfg.database.type == "mysql";
    pgsqlLocal = cfg.database.createLocally && cfg.database.type == "pgsql";
  