How to Install Simple NixOS Mailserver on OpenBSD
In this tutorial, we will explain how to install Simple NixOS Mailserver on OpenBSD. Simple NixOS Mailserver is a suite of software that allows you to run your own mail server. This tutorial assumes that you have a basic understanding of OpenBSD and know how to access the command line.
Prerequisites
- A server running OpenBSD
- A domain name pointed to the server
- A valid SSL certificate
Step 1: Install required packages
The first step is to install the required packages on the OpenBSD server. Run the following command to install the packages:
doas pkg_add git gnupg curl postfix dovecot opendkim opendmarc rspamd certbot
Step 2: Install Simple NixOS Mailserver
Next, we need to install Simple NixOS Mailserver. Follow the steps below:
- Clone the Simple NixOS Mailserver repository using the command:
git clone https://gitlab.com/simple-nixos-mailserver/nixos-mailserver.git
- Change the directory to the cloned repository:
cd nixos-mailserver
- Import the Simple NixOS Mailserver public GPG key:
curl -sSL https://keybase.io/simple-nixos-mailserver/pgp_keys.asc | doas gpg --import
- Verify that the key has been imported correctly:
doas gpg --fingerprint BBE88A6FCB7E49A9C9B7CF319CFE6A9407F47B4E
- Run the Simple NixOS Mailserver installation script:
./install.sh
Step 3: Configure the Mailserver
After the installation is complete, we need to configure the mail server. Follow the steps below:
- Edit the
mail-config-example.nixfile:
doas vim mail-config-example.nix
- Modify the following settings in the file:
- Change
mydomain.comto your domain name - Modify the
usersblock to include the email addresses you want to use - Add any aliases in the
aliasesblock
Save and close the file
Generate the configuration file:
./generate-config.sh mail-config-example.nix > mail-config.nix
- Apply the configuration changes:
sudo nixos-rebuild switch
Step 4: Configure and Start Rspamd
Rspamd is the spam filter used by Simple NixOS Mailserver. We need to configure and start Rspamd using the following steps:
- Edit the
rspamd/local.d/worker-controller.incfile:
sudo vim /etc/rspamd/local.d/worker-controller.inc
- Modify the
bind_socketsetting to listen on localhost:
bind_socket = "localhost:11333";
Save and close the file
Enable the Rspamd service:
sudo systemctl enable rspamd.service
- Start the Rspamd service:
sudo systemctl start rspamd.service
Step 5: Configure and Start Postfix
Postfix is the SMTP server used by Simple NixOS Mailserver. We need to configure and start Postfix using the following steps:
- Edit the
mail-config.nixfile:
sudo vim /etc/nixos/mail-config.nix
- Modify the
smtpd_sasl_auth_enablesetting toyes:
smtpd_sasl_auth_enable = "yes";
Save and close the file
Enable the Postfix service:
sudo systemctl enable postfix.service
- Start the Postfix service:
sudo systemctl start postfix.service
Step 6: Configure and Start Dovecot
Dovecot is the IMAP and POP3 server used by Simple NixOS Mailserver. We need to configure and start Dovecot using the following steps:
- Edit the
mail-config.nixfile:
sudo vim /etc/nixos/mail-config.nix
- Modify the
protocolssetting to include IMAP and POP3:
protocols = [ "imap" "pop3" ];
Save and close the file
Enable the Dovecot service:
sudo systemctl enable dovecot.service
- Start the Dovecot service:
sudo systemctl start dovecot.service
Step 7: Configure DKIM and DMARC
DKIM and DMARC are email authentication mechanisms that help prevent email spoofing. We need to configure and start DKIM and DMARC using the following steps:
- Edit the
mail-config.nixfile:
sudo vim /etc/nixos/mail-config.nix
Add your DKIM selector and key file path under
opendkim.keysModify the
opendmarc.report_emailsetting to your email address:
opendmarc.report_email = "[email protected]";
Save and close the file
Enable the opendkim and opendmarc services:
sudo systemctl enable opendkim.service
sudo systemctl enable opendmarc.service
- Start the opendkim and opendmarc services:
sudo systemctl start opendkim.service
sudo systemctl start opendmarc.service
Step 8: Configure SSL Certificate
Simple NixOS Mailserver requires an SSL certificate to secure the email traffic. We need to configure the SSL certificate using the following steps:
Generate a new SSL certificate or obtain a trusted one
Edit the
mail-config.nixfile:
sudo vim /etc/nixos/mail-config.nix
- Modify the
sslCertificateandsslPrivateKeysettings to the path of your SSL certificate and private key respectively:
sslCertificate = "/path/to/ssl/cert";
sslPrivateKey = "/path/to/ssl/private/key";
Save and close the file
Apply the configuration changes:
sudo nixos-rebuild switch
Conclusion
Congratulations! You have successfully installed Simple NixOS Mailserver on OpenBSD and configured it to run a mail server. You can now start sending and receiving emails from your own mail server.