From 6ef1eb9ce1e649727f3c113354e7ac204b5c56ba Mon Sep 17 00:00:00 2001 From: emilylange Date: Sat, 21 Jun 2025 20:15:46 +0200 Subject: [PATCH] assertions: fix eval error when `mailserver.stateVersion` is unset (null) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ~~~ --- docs/howto-develop.rst | 2 +- mail-server/assertions.nix | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/howto-develop.rst b/docs/howto-develop.rst index dbf3024..700f9d0 100644 --- a/docs/howto-develop.rst +++ b/docs/howto-develop.rst @@ -85,7 +85,7 @@ section on the migration page in the documentation. { assertions = [ { - assertion = config.mailserver.stateVersion >= 1; + assertion = config.mailserver.stateVersion != null -> config.mailserver.stateVersion >= 1; message = '' Problem: The home directory for the foobar service is snafu. Remediation: diff --git a/mail-server/assertions.nix b/mail-server/assertions.nix index 929f592..c606bda 100644 --- a/mail-server/assertions.nix +++ b/mail-server/assertions.nix @@ -26,7 +26,7 @@ lib.optionals (config.mailserver.ldap.enable && config.mailserver.mailDirectory != "/var/vmail") [ { - assertion = config.mailserver.stateVersion >= 2; + assertion = config.mailserver.stateVersion != null -> config.mailserver.stateVersion >= 2; message = '' Issue: The dovecot homedir for LDAP users was previously not respecting `mailserver.mailDirectory`. Remediation: @@ -40,7 +40,7 @@ ] ++ [ { - assertion = config.mailserver.stateVersion >= 3; + 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.