Skip to content

Commit 9864a2f

Browse files
authored
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.
1 parent a1036d4 commit 9864a2f

6 files changed

+60
-6
lines changed

modules/programs/thunderbird.nix

+48-2
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,33 @@ in
320320
'';
321321
};
322322

323+
accountsOrder = mkOption {
324+
type = types.listOf types.str;
325+
default = [ ];
326+
description = ''
327+
Custom ordering of accounts and local folders in
328+
Thunderbird's folder pane. The accounts are specified
329+
by their name. For declarative accounts, it must be the name
330+
of their attribute in `config.accounts.email.accounts` (or
331+
`config.programs.thunderbird.profiles.<name>.feedAccounts`
332+
for feed accounts). The local folders name can be found in
333+
the `mail.accountmanager.accounts` Thunderbird preference,
334+
for example with Settings > Config Editor ("account1" by
335+
default). Enabled accounts and local folders that aren't
336+
listed here appear in an arbitrary order after the ordered
337+
accounts.
338+
'';
339+
example = ''
340+
[
341+
"my-awesome-account"
342+
"private"
343+
"work"
344+
"rss"
345+
/* Other accounts in arbitrary order */
346+
]
347+
'';
348+
};
349+
323350
withExternalGnupg = mkOption {
324351
type = types.bool;
325352
default = false;
@@ -659,14 +686,33 @@ in
659686
);
660687

661688
accounts = emailAccounts ++ feedAccounts;
689+
690+
orderedAccounts =
691+
let
692+
accountNameToId = builtins.listToAttrs (
693+
map (a: {
694+
name = a.name;
695+
value = "account_${a.id}";
696+
}) accounts
697+
);
698+
699+
accountsOrderIds = map (a: accountNameToId."${a}" or a) profile.accountsOrder;
700+
701+
# Append the default local folder name "account1".
702+
# See https://github.com/nix-community/home-manager/issues/5031.
703+
enabledAccountsIds = (lib.attrsets.mapAttrsToList (name: value: value) accountNameToId) ++ [
704+
"account1"
705+
];
706+
in
707+
accountsOrderIds ++ (lib.lists.subtractLists accountsOrderIds enabledAccountsIds);
662708
in
663709
{
664710
text = mkUserJs (builtins.foldl' (a: b: a // b) { } (
665711
[
666712
cfg.settings
667713

668-
(optionalAttrs (length accounts != 0) {
669-
"mail.accountmanager.accounts" = concatStringsSep "," (map (a: "account_${a.id}") accounts);
714+
(optionalAttrs (length orderedAccounts != 0) {
715+
"mail.accountmanager.accounts" = concatStringsSep "," orderedAccounts;
670716
})
671717

672718
(optionalAttrs (length smtp != 0) {

tests/modules/programs/thunderbird/thunderbird-expected-first-darwin.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/modules/programs/thunderbird/thunderbird-expected-first-linux.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/modules/programs/thunderbird/thunderbird-expected-second-darwin.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/modules/programs/thunderbird/thunderbird-expected-second-linux.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/modules/programs/thunderbird/thunderbird.nix

+8
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@
7777
'';
7878

7979
feedAccounts.rss = { };
80+
81+
accountsOrder = [
82+
83+
"rss"
84+
"imperative_account"
85+
"hm-account"
86+
];
8087
};
8188

8289
second.settings = {
@@ -87,6 +94,7 @@
8794
3
8895
];
8996
};
97+
second.accountsOrder = [ "account1" ];
9098
};
9199

92100
settings = {

0 commit comments

Comments
 (0)