Alright, this is all very specific so I’m gonna light a candle for this one. Hope someone can help me out.
I’m migrating away from a multi-system Funtoo setup to a properly managed NixOS infrastructure. One of the systems I am not yet ready to migrate to NixOS, is my email server. That one is still running on an older Funtoo LXC container, and for now it is okay to keep it that way. However, postfixadmin used to run on the old Funtoo host, and that part does have to be migrated to the new NixOS host.
When the host was still running Funtoo, I had postfixadmin running in a way that wasn’t ideal, but worked. It had postgresql and had nginx for postfixadmin’s front end, it used certain tools to ensure it would be able to add and remove virtual email accounts that in turn would be accessible by the lxc mail server guest. One of those tools was a dovecotpw.sh wrapper script that would call dovecotadm pw
in a certain way. The script “Rebuilds dovecotpw’s original command line options”:
/usr/bin/doveadm pw ${list}${plaintext}${scheme}${user}${verify}
I don’t know how to include this script in a way that can function. In my postfixadmin flake, I have a line under services.postfixadmin.extraConfig
as follows:
$CONF['dovecotpw'] = '${./postfixadmin/dovecotpw.sh}';
Grasping for straws I tried to edit this script so now it reads the following, please bear with me:
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p dovecot
# MPeXnetworks - Lars Braeuer 11/2011
# Rebuild dovecotpw's original command line options, which are:
#usage: dovecotpw [-l] [-p plaintext] [-s scheme] [-u user] [-V]
# -l List known password schemes
# -p plaintext New password
# -s scheme Password scheme
# -u user Username (if scheme uses it)
# -V Internally verify the hash
while getopts ":l:p:s:u:V:" opt; do
case "$opt" in
l) list=" -l" ;;
p) plaintext=" -p $OPTARG" ;;
s) scheme=" -s $OPTARG" ;;
u) user=" -u $OPTARG" ;;
V) verify=" -V" ;;
esac
done
logger "doveadm args '$*' pw ${list}${plaintext}${scheme}${user}${verify}"
/usr/bin/env doveadm pw ${list}${plaintext}${scheme}${user}${verify}
exit $?
The postfixadmin setup.php file says:
Password Hashing - attempted to use configured encrypt backend (dovecot:CRAM-MD5) triggered an error: /nix/store/5idpzz8nsbzgy461algqyfy9j2pb39i8-dovecotpw.sh failed, see error log for details`
In the errorlog (syslog) we can see (anonymized a bit):
nginx[2217282]: 2023/06/15 23:45:31 [error] 2217282#2217282: *140374 FastCGI sent in stderr: "PHP message: Failed to read password from /nix/store/5idpzz8nsbzgy461algqyfy9j2pb39i8-dovecotpw.sh ... stderr: error:
file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
nginx[2217282]: at «string»:1:25:
nginx[2217282]: 1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (dovecot) ]; } ""
nginx[2217282]: | ^
nginx[2217282]: (use '--show-trace' to show detailed location information)
nginx[2217282]: , password:" while reading upstream, client: <MYIP>, server: postfixadmin.example.com, request: "GET /setup.php HTTP/2.0", upstream: "fastcgi://unix:/run/phpfpm/postfixadmin.sock:", host:
"postfixadmin.example.com"
nginx[2217282]: 2023/06/15 23:45:43 [error] 2217282#2217282: *140374 FastCGI sent in stderr: "PHP message: Failed to read password from /nix/store/5idpzz8nsbzgy461algqyfy9j2pb39i8-dovecotpw.sh ... stderr: error:
file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
nginx[2217282]: at «string»:1:25:
nginx[2217282]: 1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (dovecot) ]; } ""
nginx[2217282]: | ^
nginx[2217282]: (use '--show-trace' to show detailed location information)
nginx[2217282]: , password:" while reading response header from upstream, client: <MYIP>, server: postfixadmin.example.com, request: "POST /setup.php HTTP/2.0", upstream:
"fastcgi://unix:/run/phpfpm/postfixadmin.sock:", host: "postfixadmin.example.com", referrer: "https://postfixadmin.example.com/setup.php"
I’m also fairly certain that doveadm needs a working dovecot.conf, but, dovecot is not running on the host but on the guest. So how should I deal with this?
This story can be continued - to create / destroy mailboxes, it needs to run commands on the lxc guest. I plan to use ssh for that but that’s for a later time. First I’d really like to get this working and all insights are very much appreciated. Thanks. If I get any breakthrough myself, I’ll be sure to add it to this thread as well.