diff --git a/modules/programs/thunderbird.nix b/modules/programs/thunderbird.nix index d567ab44f..7382ae829 100644 --- a/modules/programs/thunderbird.nix +++ b/modules/programs/thunderbird.nix @@ -277,6 +277,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; @@ -575,13 +602,31 @@ in { (attrValues profile.feedAccounts); 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 = + (attrsets.mapAttrsToList (name: value: value) accountNameToId) + ++ [ "account1" ]; + in accountsOrderIds + ++ (lists.subtractLists accountsOrderIds enabledAccountsIds); + in { text = mkUserJs (builtins.foldl' (a: b: a // b) { } ([ cfg.settings - (optionalAttrs (length accounts != 0) { + (optionalAttrs (length orderedAccounts != 0) { "mail.accountmanager.accounts" = - concatStringsSep "," (map (a: "account_${a.id}") 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 2fe2fa39f..f967de98d 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 6d5f57274..3ff844fcf 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 d634568c8..bda3cde07 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 e4e9296a8..636edbe53 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 35e87d452..dacfc7d45 100644 --- a/tests/modules/programs/thunderbird/thunderbird.nix +++ b/tests/modules/programs/thunderbird/thunderbird.nix @@ -76,12 +76,16 @@ ''; feedAccounts.rss = { }; + + accountsOrder = + [ "hm@example.com" "rss" "imperative_account" "hm-account" ]; }; second.settings = { "second.setting" = "some-test-setting"; second.nested.evenFurtherNested = [ 1 2 3 ]; }; + second.accountsOrder = [ "account1" ]; }; settings = {