Eval does not stop on the first assertion failure it encouters. Instead, it tries to evaluate all assertions and returns with a list of those that failed. This means our very top `config.mailserver.stateVersion != null` assertion does not gate against any other assertions trying to compare null against an integer. The error prior to this commit can be reproduced by removing `mailserver.stateVersion = 999;` in tests/lib/config.nix and then trying to evaluate any of the tests: ~~~bash # nix eval --raw .#checks.x86_64-linux.internal-unstable error: … while evaluating the attribute 'outPath' at /nix/store/syvnmj3hhckkbncm94kfkbl76qsdqqj3-source/lib/customisation.nix:421:7: 420| drv.drvPath; 421| outPath = | ^ 422| assert condition; … while calling the 'getAttr' builtin at «internal»:1:500: (stack trace truncated; use '--show-trace' to show the full trace) error: cannot compare null with an integer ~~~
58 lines
2.4 KiB
Nix
58 lines
2.4 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
...
|
|
}:
|
|
{
|
|
# We guard all assertions by requiring mailserver to be actually enabled
|
|
assertions = lib.optionals config.mailserver.enable (
|
|
[
|
|
{
|
|
assertion = config.mailserver.stateVersion != null;
|
|
message = "The `mailserver.stateVersion` option is not set. Check https://nixos-mailserver.readthedocs.io/en/latest/migrations.html to determine the proper value to initialize it at.";
|
|
}
|
|
]
|
|
++ lib.optionals config.mailserver.ldap.enable [
|
|
{
|
|
assertion = config.mailserver.loginAccounts == { };
|
|
message = "When the LDAP support is enable (mailserver.ldap.enable = true), it is not possible to define mailserver.loginAccounts";
|
|
}
|
|
{
|
|
assertion = config.mailserver.extraVirtualAliases == { };
|
|
message = "When the LDAP support is enable (mailserver.ldap.enable = true), it is not possible to define mailserver.extraVirtualAliases";
|
|
}
|
|
]
|
|
++
|
|
lib.optionals (config.mailserver.ldap.enable && config.mailserver.mailDirectory != "/var/vmail")
|
|
[
|
|
{
|
|
assertion = config.mailserver.stateVersion != null -> config.mailserver.stateVersion >= 2;
|
|
message = ''
|
|
Issue: The dovecot homedir for LDAP users was previously not respecting `mailserver.mailDirectory`.
|
|
Remediation:
|
|
- Stop the `dovecot2.service`
|
|
- Move `/var/vmail/ldap` below your `mailserver.mailDirectory`
|
|
- Increase the `stateVersion` to 2.
|
|
|
|
Check https://nixos-mailserver.readthedocs.io/en/latest/migrations.html#dovecot-ldap-home-directory-migration for more information.
|
|
'';
|
|
}
|
|
]
|
|
++ [
|
|
{
|
|
assertion = config.mailserver.stateVersion != null -> config.mailserver.stateVersion >= 3;
|
|
message = ''
|
|
Issue: The dovecot mail location for all users has changed and need to be migrated.
|
|
|
|
Check https://nixos-mailserver.readthedocs.io/en/latest/migrations.html#dovecot-mail-directory-migration for the required remediation steps.
|
|
'';
|
|
}
|
|
]
|
|
++ lib.optionals (config.mailserver.certificateScheme != "acme") [
|
|
{
|
|
assertion = config.mailserver.acmeCertificateName == config.mailserver.fqdn;
|
|
message = "When the certificate scheme is not 'acme' (mailserver.certificateScheme != \"acme\"), it is not possible to define mailserver.acmeCertificateName";
|
|
}
|
|
]
|
|
);
|
|
}
|