From 0eafc74d503ffb6973676cb225d73c09c0fc1a39 Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Tue, 18 May 2021 23:34:03 -0500 Subject: [PATCH 1/7] postfixadmin: init at 3.3.9 --- nixos/modules/module-list.nix | 1 + nixos/modules/services/mail/postfixadmin.nix | 164 +++++++++++++++++++ nixos/tests/all-tests.nix | 1 + nixos/tests/postfixadmin.nix | 31 ++++ pkgs/servers/postfixadmin/default.nix | 27 +++ pkgs/top-level/all-packages.nix | 2 + 6 files changed, 226 insertions(+) create mode 100644 nixos/modules/services/mail/postfixadmin.nix create mode 100644 nixos/tests/postfixadmin.nix create mode 100644 pkgs/servers/postfixadmin/default.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 2fbab4a68739..f07de862eacd 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -460,6 +460,7 @@ ./services/mail/opensmtpd.nix ./services/mail/pfix-srsd.nix ./services/mail/postfix.nix + ./services/mail/postfixadmin.nix ./services/mail/postsrsd.nix ./services/mail/postgrey.nix ./services/mail/spamassassin.nix diff --git a/nixos/modules/services/mail/postfixadmin.nix b/nixos/modules/services/mail/postfixadmin.nix new file mode 100644 index 000000000000..9fd6630ee368 --- /dev/null +++ b/nixos/modules/services/mail/postfixadmin.nix @@ -0,0 +1,164 @@ +{ lib, config, pkgs, ... }: + +with lib; + +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 = mkOption { + type = 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.<name>. + See for further information. + ''; + }; + + hostName = mkOption { + type = types.str; + example = "postfixadmin.example.com"; + description = "Hostname to use for the nginx vhost"; + }; + + adminEmail = mkOption { + type = types.str; + example = "postfixadmin.example.com"; + description = '' + Define the Site Admin's email address below. + This will be used to send emails from to create mailboxes and + from Send Email / Broadcast message pages. + ''; + }; + + setupPasswordFile = mkOption { + type = types.path; + description = '' + Password file for the admin. + Generate with php -r "echo password_hash('some password here', PASSWORD_DEFAULT);" + ''; + }; + + database = { + username = mkOption { + type = 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 = mkOption { + type = 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 = mkOption { + type = types.path; + description = "Password file for the postgresql connection. Must be readable by user nginx."; + }; + dbname = mkOption { + type = types.str; + default = "postfixadmin"; + description = "Name of the postgresql database"; + }; + }; + + extraConfig = mkOption { + type = types.lines; + default = ""; + description = "Extra configuration for the postfixadmin instance, see postfixadmin's config.inc.php for available options."; + }; + }; + + config = mkIf cfg.enable { + environment.etc."postfixadmin/config.local.php".text = '' + Date: Wed, 19 May 2021 15:33:23 -0500 Subject: [PATCH 2/7] postfixadmin: review additions Co-authored-by: Linus Heckemann --- nixos/modules/services/mail/postfixadmin.nix | 4 ++-- pkgs/servers/postfixadmin/default.nix | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/mail/postfixadmin.nix b/nixos/modules/services/mail/postfixadmin.nix index 9fd6630ee368..96aa24089870 100644 --- a/nixos/modules/services/mail/postfixadmin.nix +++ b/nixos/modules/services/mail/postfixadmin.nix @@ -30,9 +30,9 @@ in adminEmail = mkOption { type = types.str; - example = "postfixadmin.example.com"; + example = "postmaster@example.com"; description = '' - Define the Site Admin's email address below. + 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. ''; diff --git a/pkgs/servers/postfixadmin/default.nix b/pkgs/servers/postfixadmin/default.nix index e2da40bbc291..8425b57b34d8 100644 --- a/pkgs/servers/postfixadmin/default.nix +++ b/pkgs/servers/postfixadmin/default.nix @@ -20,6 +20,7 @@ stdenv.mkDerivation rec { meta = { description = "Web based virtual user administration interface for Postfix mail servers"; + homepage = "https://postfixadmin.sourceforge.io/"; maintainers = with stdenv.lib.maintainers; [ globin ]; license = stdenv.lib.licenses.gpl2Plus; platforms = stdenv.lib.platforms.all; From 8a0b6a42ee1b1199512a806d9c22617d7e09aeb1 Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Mon, 23 Aug 2021 20:16:23 +0200 Subject: [PATCH 3/7] postfixadmin: fix db owner --- nixos/modules/services/mail/postfixadmin.nix | 42 ++++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/nixos/modules/services/mail/postfixadmin.nix b/nixos/modules/services/mail/postfixadmin.nix index 96aa24089870..967e0e240550 100644 --- a/nixos/modules/services/mail/postfixadmin.nix +++ b/nixos/modules/services/mail/postfixadmin.nix @@ -125,14 +125,48 @@ in services.postgresql = mkIf localDB { enable = true; - ensureDatabases = [ cfg.database.dbname ]; ensureUsers = [ { name = cfg.database.username; - ensurePermissions = { - "DATABASE ${cfg.database.username}" = "ALL PRIVILEGES"; - }; } ]; }; + # The postgresql module doesn't currently support concepts like + # objects owners and extensions; for now we tack on what's needed + # here. + systemd.services.postfixadmin-postgres = let pgsql = config.services.postgresql; in mkIf localDB { + after = [ "postgresql.service" ]; + bindsTo = [ "postgresql.service" ]; + wantedBy = [ "multi-user.target" ]; + path = [ + pgsql.package + pkgs.utillinux + ]; + script = '' + set -eu + + PSQL() { + psql --port=${toString pgsql.port} "$@" + } + + PSQL -tAc "SELECT 1 FROM pg_database WHERE datname = '${cfg.database.dbname}'" | grep -q 1 || PSQL -tAc 'CREATE DATABASE "${cfg.database.dbname}" OWNER "${cfg.database.username}"' + current_owner=$(PSQL -tAc "SELECT pg_catalog.pg_get_userbyid(datdba) FROM pg_catalog.pg_database WHERE datname = '${cfg.database.dbname}'") + if [[ "$current_owner" != "${cfg.database.username}" ]]; then + PSQL -tAc 'ALTER DATABASE "${cfg.database.dbname}" OWNER TO "${cfg.database.username}"' + if [[ -e "${config.services.postgresql.dataDir}/.reassigning_${cfg.database.dbname}" ]]; then + echo "Reassigning ownership of database ${cfg.database.dbname} to user ${cfg.database.username} failed on last boot. Failing..." + exit 1 + fi + touch "${config.services.postgresql.dataDir}/.reassigning_${cfg.database.dbname}" + PSQL "${cfg.database.dbname}" -tAc "REASSIGN OWNED BY \"$current_owner\" TO \"${cfg.database.username}\"" + rm "${config.services.postgresql.dataDir}/.reassigning_${cfg.database.dbname}" + fi + ''; + + serviceConfig = { + User = pgsql.superUser; + Type = "oneshot"; + RemainAfterExit = true; + }; + }; users.users.${user} = mkIf localDB { group = user; From 9dabe2df7247c2241e35cda861fc1d71fd9ce38a Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Mon, 23 Aug 2021 20:24:49 +0200 Subject: [PATCH 4/7] postfixadmin: 3.3.9 -> 3.3.10 --- pkgs/servers/postfixadmin/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/servers/postfixadmin/default.nix b/pkgs/servers/postfixadmin/default.nix index 8425b57b34d8..186d8b5ef091 100644 --- a/pkgs/servers/postfixadmin/default.nix +++ b/pkgs/servers/postfixadmin/default.nix @@ -2,13 +2,13 @@ stdenv.mkDerivation rec { pname = "postfixadmin"; - version = "3.3.9"; + version = "3.3.10"; src = fetchFromGitHub { owner = pname; repo = pname; rev = "${pname}-${version}"; - sha256 = "178ibnz8cd8nalg98zifsrpvqhi1i3k9rq5fbdpwlikqvppk0h08"; + sha256 = "0xck6df96r4z8k2j8x20b8h2qvmzyrfsya82s4i7hfhrxii92d3w"; }; installPhase = '' From 13a5d7dc23969053764af01bbd1ee905a55a15e1 Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Mon, 23 Aug 2021 20:30:23 +0200 Subject: [PATCH 5/7] release-notes: add postfixadmin module addition --- .../doc/manual/from_md/release-notes/rl-2111.section.xml | 8 ++++++++ nixos/doc/manual/release-notes/rl-2111.section.md | 2 ++ 2 files changed, 10 insertions(+) diff --git a/nixos/doc/manual/from_md/release-notes/rl-2111.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2111.section.xml index b422c3cf058b..65abc8ac4820 100644 --- a/nixos/doc/manual/from_md/release-notes/rl-2111.section.xml +++ b/nixos/doc/manual/from_md/release-notes/rl-2111.section.xml @@ -199,6 +199,14 @@ services.xserver.displayManager.sx + + + postfixadmin, + a web based virtual user administration interface for Postfix + mail servers. Available as + postfixadmin. + +
diff --git a/nixos/doc/manual/release-notes/rl-2111.section.md b/nixos/doc/manual/release-notes/rl-2111.section.md index 548008fe24bc..ae6ccf932987 100644 --- a/nixos/doc/manual/release-notes/rl-2111.section.md +++ b/nixos/doc/manual/release-notes/rl-2111.section.md @@ -60,6 +60,8 @@ subsonic-compatible api. Available as [navidrome](#opt-services.navidrome.enable - [sx](https://github.com/earnestly/sx), a simple alternative to both xinit and startx for starting a Xorg server. Available as [services.xserver.displayManager.sx](#opt-services.xserver.displayManager.sx.enable) +- [postfixadmin](https://postfixadmin.sourceforge.io/), a web based virtual user administration interface for Postfix mail servers. Available as [postfixadmin](#opt-services.postfixadmin.enable). + ## Backward Incompatibilities {#sec-release-21.11-incompatibilities} - The `paperless` module and package have been removed. All users should migrate to the From 52a6502174b2d7cbdd29abf3c0faa2418b2c0cae Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Mon, 23 Aug 2021 21:13:04 +0200 Subject: [PATCH 6/7] postfixadmin: stdenv.lib -> lib --- pkgs/servers/postfixadmin/default.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/servers/postfixadmin/default.nix b/pkgs/servers/postfixadmin/default.nix index 186d8b5ef091..e561b3931f73 100644 --- a/pkgs/servers/postfixadmin/default.nix +++ b/pkgs/servers/postfixadmin/default.nix @@ -1,4 +1,4 @@ -{ fetchFromGitHub, stdenv }: +{ fetchFromGitHub, stdenv, lib }: stdenv.mkDerivation rec { pname = "postfixadmin"; @@ -21,8 +21,8 @@ stdenv.mkDerivation rec { meta = { description = "Web based virtual user administration interface for Postfix mail servers"; homepage = "https://postfixadmin.sourceforge.io/"; - maintainers = with stdenv.lib.maintainers; [ globin ]; - license = stdenv.lib.licenses.gpl2Plus; - platforms = stdenv.lib.platforms.all; + maintainers = with lib.maintainers; [ globin ]; + license = lib.licenses.gpl2Plus; + platforms = lib.platforms.all; }; } From 749caaef5bd6cfd2c843a4f2e9fc2d29952d2109 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Tue, 24 Aug 2021 23:44:50 +0200 Subject: [PATCH 7/7] nixos/postfixadmin: fix eval & pin to PHP 7.4 Even though some PHP8 compat fixes seem to be in the release that's packaged here, it seems as if there are still some minor issues[1]. [1] https://github.com/postfixadmin/postfixadmin/issues/395 --- nixos/modules/services/mail/postfixadmin.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/mail/postfixadmin.nix b/nixos/modules/services/mail/postfixadmin.nix index 967e0e240550..f5c8efb3076c 100644 --- a/nixos/modules/services/mail/postfixadmin.nix +++ b/nixos/modules/services/mail/postfixadmin.nix @@ -138,7 +138,7 @@ in wantedBy = [ "multi-user.target" ]; path = [ pgsql.package - pkgs.utillinux + pkgs.util-linux ]; script = '' set -eu @@ -177,6 +177,7 @@ in services.phpfpm.pools.postfixadmin = { user = user; + phpPackage = pkgs.php74; phpOptions = '' error_log = 'stderr' log_errors = on