nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.69k stars 1.75k forks source link

bug: Thunderbird creates new local folders account on every launch #5031

Open nfelber opened 7 months ago

nfelber commented 7 months ago

Are you following the right branch?

Is there an existing issue for this?

Issue description

Issue

On every launch, Thunderbird adds a new line user_pref("mail.account.account<N>.server", "server1"); to prefs.js of the profile being used, with <N> a value incrementing in steps of 1. The parameter mail.account.lastKey is also incremented to be equal to the largest <N>. It doesn't affect the accounts declared in the home-manager nix config.

Example

prefs.js after launching and closing Thunderbird 5 times:

// ...
// Lines weirdly added on each launch
user_pref("mail.account.account1.server", "server1");
user_pref("mail.account.account2.server", "server1");
user_pref("mail.account.account3.server", "server1");
user_pref("mail.account.account4.server", "server1");
user_pref("mail.account.account5.server", "server1");
// Accounts normally declared in the home-manager nix config
user_pref("mail.account.account_576ba7c2e4abb7184ca409154dbbbd5306c1a80747fbce4148ea6271fd21e776.identities", "id_576ba7c2e4abb7184ca409154dbbbd5306c1a80747fbce4148ea6271fd21e776");
user_pref("mail.account.account_576ba7c2e4abb7184ca409154dbbbd5306c1a80747fbce4148ea6271fd21e776.server", "server_576ba7c2e4abb7184ca409154dbbbd5306c1a80747fbce4148ea6271fd21e776");
user_pref("mail.account.account_6f0a53fb760ead798eff28586351f9cda5211f8d18df529aaca8391c814ba87a.identities", "id_6f0a53fb760ead798eff28586351f9cda5211f8d18df529aaca8391c814ba87a");
user_pref("mail.account.account_6f0a53fb760ead798eff28586351f9cda5211f8d18df529aaca8391c814ba87a.server", "server_6f0a53fb760ead798eff28586351f9cda5211f8d18df529aaca8391c814ba87a");
user_pref("mail.account.account_8758902c10feb2ee51fb2a4a0afcde74fd6b11057e0be55d98d4d85335e8deee.identities", "id_8758902c10feb2ee51fb2a4a0afcde74fd6b11057e0be55d98d4d85335e8deee");
user_pref("mail.account.account_8758902c10feb2ee51fb2a4a0afcde74fd6b11057e0be55d98d4d85335e8deee.server", "server_8758902c10feb2ee51fb2a4a0afcde74fd6b11057e0be55d98d4d85335e8deee");
// lastKey equals largest account number
user_pref("mail.account.lastKey", 5);
// ...

Possible explanation

The thunderbird.nix module sets the mail.accountmanager.accounts parameter in the user.js file of the profile as the comma separated concatenation of the names of the accounts declared in the home-manager nix config (these names are based on hashes of the actual account names). This parameter controls which accounts show up in Thunderbird's folder pane and in which order[^1]. On startup, Thunderbird reads the user.js file and copies all its parameters to prefs.js (overwriting existing ones).

In my understanding: as no local folders account is listed in mail.accountmanager.accounts, Thunderbird creates a new one (with an incrementally increasing number in the name to avoid conflicts with existing ones) and appends it to mail.accountmanager.accounts in prefs.js to make the local folders appear in the folder pane. On subsequent launches, the value of mail.accountmanager.accounts in prefs.js will be overwritten by the value from user.js, resulting in a cycle.

Workaround

I was able to solve both the automatic local folders account creation and the ordering issues by manually setting the mail.accountmanager.accounts value (with desired ordering and account1 appended) using the settings option of the thunderbird.nix module.

{
  programs.thunderbird = {
    enable = true;
    profiles = {
      nf = {
        isDefault = true;
        settings = let
          toHashedName = x: "account_" + (builtins.hashString "sha256" x);
          # List accounts in the order they will appear in the folder pane
          accounts = [
            "pascaline"
            "gmail"
            "epfl"
          ];
        in {
          "mail.accountmanager.accounts" = lib.concatStringsSep "," ((map toHashedName accounts) ++ ["account1"]); 
        };
      };
    };
  };
}

[^1]: A related issue is that there is currently no way to declare the order in which the accounts should appear using the thunderbird.nix module, and any modification to this order made in the UI (i.e. written to prefs.js) will be overwritten (by user.js) on the next launch.

Maintainer CC

meta.maintainers: @d-dervishi @jkarlson

Thanks!

System information

- system: `"x86_64-linux"`
 - host os: `Linux 6.1.77, NixOS, 24.05 (Uakari), 24.05.20240211.f9d39fb`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(root): `"nixos-23.11"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
stale[bot] commented 3 months ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.