From 9864a2f421e859d9784b6c413ec25d1415ddfe08 Mon Sep 17 00:00:00 2001 From: Nathan Felber Date: Wed, 9 Apr 2025 16:18:26 +0200 Subject: [PATCH] thunderbird: add accountsOrder option (#6310) Fixes #5031 and adds accountsOrder option for declarative account ordering in Thunderbird's folder pane as discussed in the issue. --- modules/programs/thunderbird.nix | 50 ++++++++++++++++++- .../thunderbird-expected-first-darwin.js | 2 +- .../thunderbird-expected-first-linux.js | 2 +- .../thunderbird-expected-second-darwin.js | 2 +- .../thunderbird-expected-second-linux.js | 2 +- .../programs/thunderbird/thunderbird.nix | 8 +++ 6 files changed, 60 insertions(+), 6 deletions(-) diff --git a/modules/programs/thunderbird.nix b/modules/programs/thunderbird.nix index c7e47ef5..333ca39b 100644 --- a/modules/programs/thunderbird.nix +++ b/modules/programs/thunderbird.nix @@ -320,6 +320,33 @@ in ''; }; + accountsOrder = mkOption { + type = types.listOf types.str; + default = [ ]; + description = '' + Custom ordering of accounts and local folders in + Thunderbird's folder pane. The accounts are specified + by their name. For declarative accounts, it must be the name + of their attribute in `config.accounts.email.accounts` (or + `config.programs.thunderbird.profiles..feedAccounts` + for feed accounts). The local folders name can be found in + the `mail.accountmanager.accounts` Thunderbird preference, + for example with Settings > Config Editor ("account1" by + default). Enabled accounts and local folders that aren't + listed here appear in an arbitrary order after the ordered + accounts. + ''; + example = '' + [ + "my-awesome-account" + "private" + "work" + "rss" + /* Other accounts in arbitrary order */ + ] + ''; + }; + withExternalGnupg = mkOption { type = types.bool; default = false; @@ -659,14 +686,33 @@ in ); accounts = emailAccounts ++ feedAccounts; + + orderedAccounts = + let + accountNameToId = builtins.listToAttrs ( + map (a: { + name = a.name; + value = "account_${a.id}"; + }) accounts + ); + + accountsOrderIds = map (a: accountNameToId."${a}" or a) profile.accountsOrder; + + # Append the default local folder name "account1". + # See https://github.com/nix-community/home-manager/issues/5031. + enabledAccountsIds = (lib.attrsets.mapAttrsToList (name: value: value) accountNameToId) ++ [ + "account1" + ]; + in + accountsOrderIds ++ (lib.lists.subtractLists accountsOrderIds enabledAccountsIds); in { text = mkUserJs (builtins.foldl' (a: b: a // b) { } ( [ cfg.settings - (optionalAttrs (length accounts != 0) { - "mail.accountmanager.accounts" = concatStringsSep "," (map (a: "account_${a.id}") accounts); + (optionalAttrs (length orderedAccounts != 0) { + "mail.accountmanager.accounts" = concatStringsSep "," orderedAccounts; }) (optionalAttrs (length smtp != 0) { diff --git a/tests/modules/programs/thunderbird/thunderbird-expected-first-darwin.js b/tests/modules/programs/thunderbird/thunderbird-expected-first-darwin.js index 2fe2fa39..f967de98 100644 --- a/tests/modules/programs/thunderbird/thunderbird-expected-first-darwin.js +++ b/tests/modules/programs/thunderbird/thunderbird-expected-first-darwin.js @@ -6,7 +6,7 @@ user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da user_pref("mail.account.account_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab.server", "server_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab"); user_pref("mail.account.account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.identities", "id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f,id_8bbcff78f53202c0bfaa490a2068e3e5d6e36872144c659952ecc0ada47d7562"); user_pref("mail.account.account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.server", "server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); -user_pref("mail.accountmanager.accounts", "account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc,account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f,account_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab"); +user_pref("mail.accountmanager.accounts", "account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f,account_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab,imperative_account,account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc,account1"); user_pref("mail.accountmanager.defaultaccount", "account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); user_pref("mail.identity.id_8bbcff78f53202c0bfaa490a2068e3e5d6e36872144c659952ecc0ada47d7562.attachPgpKey", false); user_pref("mail.identity.id_8bbcff78f53202c0bfaa490a2068e3e5d6e36872144c659952ecc0ada47d7562.autoEncryptDrafts", true); diff --git a/tests/modules/programs/thunderbird/thunderbird-expected-first-linux.js b/tests/modules/programs/thunderbird/thunderbird-expected-first-linux.js index 6d5f5727..3ff844fc 100644 --- a/tests/modules/programs/thunderbird/thunderbird-expected-first-linux.js +++ b/tests/modules/programs/thunderbird/thunderbird-expected-first-linux.js @@ -6,7 +6,7 @@ user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da user_pref("mail.account.account_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab.server", "server_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab"); user_pref("mail.account.account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.identities", "id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f,id_8bbcff78f53202c0bfaa490a2068e3e5d6e36872144c659952ecc0ada47d7562"); user_pref("mail.account.account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.server", "server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); -user_pref("mail.accountmanager.accounts", "account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc,account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f,account_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab"); +user_pref("mail.accountmanager.accounts", "account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f,account_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab,imperative_account,account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc,account1"); user_pref("mail.accountmanager.defaultaccount", "account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); user_pref("mail.identity.id_8bbcff78f53202c0bfaa490a2068e3e5d6e36872144c659952ecc0ada47d7562.attachPgpKey", false); user_pref("mail.identity.id_8bbcff78f53202c0bfaa490a2068e3e5d6e36872144c659952ecc0ada47d7562.autoEncryptDrafts", true); diff --git a/tests/modules/programs/thunderbird/thunderbird-expected-second-darwin.js b/tests/modules/programs/thunderbird/thunderbird-expected-second-darwin.js index d634568c..bda3cde0 100644 --- a/tests/modules/programs/thunderbird/thunderbird-expected-second-darwin.js +++ b/tests/modules/programs/thunderbird/thunderbird-expected-second-darwin.js @@ -3,7 +3,7 @@ user_pref("general.useragent.override", ""); user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.identities", "id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.server", "server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); -user_pref("mail.accountmanager.accounts", "account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); +user_pref("mail.accountmanager.accounts", "account1,account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.autoEncryptDrafts", false); user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.fullName", "H. M. Test Jr."); user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.htmlSigText", ""); diff --git a/tests/modules/programs/thunderbird/thunderbird-expected-second-linux.js b/tests/modules/programs/thunderbird/thunderbird-expected-second-linux.js index e4e9296a..636edbe5 100644 --- a/tests/modules/programs/thunderbird/thunderbird-expected-second-linux.js +++ b/tests/modules/programs/thunderbird/thunderbird-expected-second-linux.js @@ -3,7 +3,7 @@ user_pref("general.useragent.override", ""); user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.identities", "id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.server", "server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); -user_pref("mail.accountmanager.accounts", "account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); +user_pref("mail.accountmanager.accounts", "account1,account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.autoEncryptDrafts", false); user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.fullName", "H. M. Test Jr."); user_pref("mail.identity.id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.htmlSigText", ""); diff --git a/tests/modules/programs/thunderbird/thunderbird.nix b/tests/modules/programs/thunderbird/thunderbird.nix index 570e88ae..c900cdeb 100644 --- a/tests/modules/programs/thunderbird/thunderbird.nix +++ b/tests/modules/programs/thunderbird/thunderbird.nix @@ -77,6 +77,13 @@ ''; feedAccounts.rss = { }; + + accountsOrder = [ + "hm@example.com" + "rss" + "imperative_account" + "hm-account" + ]; }; second.settings = { @@ -87,6 +94,7 @@ 3 ]; }; + second.accountsOrder = [ "account1" ]; }; settings = {