Subject: Invalid 'location' field generated in dovecot configuration

From: Pierre Langlois <[email-masked]>
Date: Sun, 20 Nov 2022 21:53:01 +0000

Hi Guix!

After updating the system, the dovecot service got confused and started
moving around all mailboxes.  I looked up the configuration and noticed
strange invalid syntax for the location field:

--8<---------------cut here---------------start------------->8---
location=#<<location> file: "path/to/config.scm" line: 297 column: 20>
--8<---------------cut here---------------end--------------->8---

Because the # character is interpreted as a comment, dovecot doesn't
crash and instead moves mailboxes around in weird ways I don't quite
understand :-/.

This can actually be reproduced locally with the dovecot system test if
one dumps the following expression to check the configuration:

--8<---------------cut here---------------start------------->8---
(format #t "~a\n" (wait-for-file "/etc/dovecot/dovecot.conf"
                                 marionette
                                 #:read 'get-string-all))
--8<---------------cut here---------------end--------------->8---

Giving us the snippets like this in the config:

--8<---------------cut here---------------start------------->8---
$ make check-system TESTS="dovecot"  VERBOSE=1
...
namespace inbox {
type=private
separator=
prefix=
location=#<<location> file: "gnu/tests/mail.scm" line: 297 column: 20>
inbox=yes
hidden=no
list=yes
subscriptions=yes
mailbox "Drafts" {
auto=no
special_use=\Drafts
}
mailbox "Junk" {
auto=no
special_use=\Junk
}
mailbox "Trash" {
auto=no
special_use=\Trash
}
mailbox "Sent" {
auto=no
special_use=\Sent
}
mailbox "Sent Messages" {
auto=no
special_use=\Sent
}
mailbox "Drafts" {
auto=no
special_use=\Drafts
}
}
...
--8<---------------cut here---------------end--------------->8---

I did a `git bisect` with `guix time-machine` (this tool is invaluable)
and found the issue started with this commit:

--8<---------------cut here---------------start------------->8---
commit 543d971ed2a1d9eb934af1f51930741d7cc4e7ef
Author: Maxim Cournoyer <[email-masked]>
Date:   Fri Oct 28 17:06:16 2022 -0400
    services: configuration: Re-order generated record fields.
    
    This is so that the first field of the generated record matches the first one
    declared, which makes 'define-configuration' record API compatible with
    define-record-type* ones.
    
    * gnu/services/configuration.scm (define-configuration-helper): Move the
    %location field below the ones declared by the user.
    * gnu/services/monitoring.scm (zabbix-front-end-config): Adjust match pattern
    accordingly.
--8<---------------cut here---------------end--------------->8---

Sooo, I'm guessing this is something to do with the configuration field
being named "location", and /maybe/ we're patching it with the origin
location of the configuration, something like that? I don't understand
how this works well enough to be able to thing of any fixes.

Thanks,
Pierre