{ lib, config, pkgs, ... }: let cfg = config.services.postfixadmin; fpm = config.services.phpfpm.pools.postfixadmin; localDB = cfg.database.host == "localhost"; user = if localDB then cfg.database.username else "nginx"; in { options.services.postfixadmin = { enable = lib.mkOption { type = lib.types.bool; default = false; description = '' Whether to enable postfixadmin. Also enables nginx virtual host management. Further nginx configuration can be done by adapting `services.nginx.virtualHosts.`. See [](#opt-services.nginx.virtualHosts) for further information. ''; }; hostName = lib.mkOption { type = lib.types.str; example = "postfixadmin.example.com"; description = "Hostname to use for the nginx vhost"; }; adminEmail = lib.mkOption { type = lib.types.str; example = "postmaster@example.com"; description = '' Defines the Site Admin's email address. This will be used to send emails from to create mailboxes and from Send Email / Broadcast message pages. ''; }; setupPasswordFile = lib.mkOption { type = lib.types.path; description = '' Password file for the admin. Generate with `php -r "echo password_hash('some password here', PASSWORD_DEFAULT);"` ''; }; database = { username = lib.mkOption { type = lib.types.str; default = "postfixadmin"; description = '' Username for the postgresql connection. If `database.host` is set to `localhost`, a unix user and group of the same name will be created as well. ''; }; host = lib.mkOption { type = lib.types.str; default = "localhost"; description = '' Host of the postgresql server. If this is not set to `localhost`, you have to create the postgresql user and database yourself, with appropriate permissions. ''; }; passwordFile = lib.mkOption { type = lib.types.path; description = "Password file for the postgresql connection. Must be readable by user `nginx`."; }; dbname = lib.mkOption { type = lib.types.str; default = "postfixadmin"; description = "Name of the postgresql database"; }; }; extraConfig = lib.mkOption { type = lib.types.lines; default = ""; description = "Extra configuration for the postfixadmin instance, see postfixadmin's config.inc.php for available options."; }; }; config = lib.mkIf cfg.enable { environment.etc."postfixadmin/config.local.php".text = ''