Modoboa is a free and open-source mail hosting and management platform. It allows you to manage multiple mail domains, users and aliases through an easy-to-use web interface. This tutorial will guide you through the process of installing Modoboa on NixOS Latest.
If you have not already installed NixOS on your server, follow the official installation guide.
Before installing any new packages, it is a good practice to update the system:
$ sudo nix-channel --update
$ sudo nixos-rebuild switch
Modoboa requires several dependencies to be installed on your system. Run the following command to install them:
$ sudo nix-env -iA \
nixos.python \
nixos.postgresql \
nixos.nginx \
nixos.git \
nixos.openssl \
nixos.libjpeg \
nixos.libxml2 \
nixos.libxslt \
nixos.pkgconfig \
nixos.tzdata
To install Modoboa, run the following command:
$ sudo nix-env -iA nixos.modoboa
Modoboa needs to be configured before it can be used. Copy the sample configuration file:
$ sudo cp /nix/store/*-modoboa-*/modoboa/settings.py.sample /etc/modoboa/settings.py
Edit the file /etc/modoboa/settings.py
and make the following changes:
SECRET_KEY = 'change_me'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'modoboa',
'USER': 'modoboa',
'PASSWORD': 'change_me',
'HOST': 'localhost',
'PORT': '5432',
}
}
Replace change_me
with your own values for SECRET_KEY
and PASSWORD
.
Save and close the file when you are done.
Run the following command to initialize the database:
$ sudo modoboa-admin.py migrate
Create an admin user by running:
$ sudo modoboa-admin.py createadmin --username=admin --password=change_me --email=admin@example.com --noinput
Replace change_me
with your own password.
Save and close the file when you are done.
To access Modoboa via a web browser, you will need to configure Nginx to act as a reverse proxy.
Create a new Nginx configuration file:
$ sudo nano /etc/nixos/nginx/modoboa.conf
Add the following configuration:
server {
listen 80;
server_name mail.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name mail.example.com;
ssl_certificate /etc/letsencrypt/live/mail.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mail.example.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
location /static/ {
alias /nix/store/*-modoboa-*/modoboa/instance/static/;
}
}
Replace mail.example.com
with your own domain name and SSL certificate paths.
Add the following line to your NixOS configuration file /etc/nixos/configuration.nix
to include the Modoboa Nginx configuration:
services.nginx.enable = true;
services.nginx.virtualHosts."mail.example.com" = { enableACME = true; forceSSL = true; config = /etc/nixos/nginx/modoboa.conf; };
Replace mail.example.com
with your own domain name.
Start and enable Modoboa with the following command:
$ sudo systemctl start modoboa
$ sudo systemctl enable modoboa
Open your web browser and go to https://mail.example.com
. You should be prompted to log in with the admin user that you created earlier.
Congratulations! You have successfully installed and configured Modoboa on NixOS Latest. You can now manage your mail domains, users and aliases via the web interface.
If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!
Alternatively, for the best virtual desktop, try Shells!