accounts.email: introduce accounts.email.order
Nix does not preserve attrset order, instead sorting attributes by alphabetical order. However, aerc display's accounts based on their order in `.config/aerc/accounts.conf`. This commit introduces a `accounts.email.order` list that provides an optional order for accounts in `accounts.email.accounts`. Support for this is implemeted in the `aerc` module. If a partial order is provided those will be ordered after the primary account, and any unordered accounts will be included with the previous alphabetical behavior after.
This commit is contained in:
parent
cd88671199
commit
0e78a207ea
|
@ -509,6 +509,13 @@ in {
|
|||
default = { };
|
||||
description = "List of email accounts.";
|
||||
};
|
||||
|
||||
order = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description =
|
||||
"Order of email accounts from [](#opt-accounts.email.accounts).";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf (cfg.accounts != { }) {
|
||||
|
|
|
@ -23,6 +23,9 @@ let
|
|||
|
||||
aerc-accounts =
|
||||
attrsets.filterAttrs (_: v: v.aerc.enable) config.accounts.email.accounts;
|
||||
aerc-accounts-order =
|
||||
builtins.filter (n: config.accounts.email.accounts.${n}.aerc.enable)
|
||||
config.accounts.email.order;
|
||||
|
||||
configDir = if (pkgs.stdenv.isDarwin && !config.xdg.enable) then
|
||||
"Library/Preferences/aerc"
|
||||
|
@ -136,11 +139,15 @@ in {
|
|||
});
|
||||
|
||||
primaryAccount = attrsets.filterAttrs (_: v: v.primary) aerc-accounts;
|
||||
otherAccounts = attrsets.filterAttrs (_: v: !v.primary) aerc-accounts;
|
||||
orderedAccountsList =
|
||||
builtins.map (n: { ${n} = aerc-accounts."${n}"; }) aerc-accounts-order;
|
||||
unorderedAccounts = attrsets.filterAttrs
|
||||
(n: v: !v.primary && !builtins.elem n aerc-accounts-order) aerc-accounts;
|
||||
|
||||
primaryAccountAccounts = mapAttrs accounts.mkAccount primaryAccount;
|
||||
|
||||
accountsExtraAccounts = mapAttrs accounts.mkAccount otherAccounts;
|
||||
orderedAccountsAccountsList =
|
||||
builtins.map (mapAttrs accounts.mkAccount) orderedAccountsList;
|
||||
unorderedAccountsAccounts = mapAttrs accounts.mkAccount unorderedAccounts;
|
||||
|
||||
accountsExtraConfig = mapAttrs accounts.mkAccountConfig aerc-accounts;
|
||||
|
||||
|
@ -155,7 +162,9 @@ in {
|
|||
false;
|
||||
|
||||
genAccountsConf = ((cfg.extraAccounts != "" && cfg.extraAccounts != { })
|
||||
|| !(isRecursivelyEmpty accountsExtraAccounts)
|
||||
|| !(isRecursivelyEmpty unorderedAccountsAccounts)
|
||||
|| !(builtins.all (v: v)
|
||||
(builtins.map isRecursivelyEmpty orderedAccountsAccountsList))
|
||||
|| !(isRecursivelyEmpty primaryAccountAccounts));
|
||||
|
||||
genAercConf = ((cfg.extraConfig != "" && cfg.extraConfig != { })
|
||||
|
@ -197,12 +206,10 @@ in {
|
|||
|
||||
home.file = {
|
||||
"${configDir}/accounts.conf" = mkIf genAccountsConf {
|
||||
text = joinCfg [
|
||||
header
|
||||
(mkINI cfg.extraAccounts)
|
||||
(mkINI primaryAccountAccounts)
|
||||
(mkINI accountsExtraAccounts)
|
||||
];
|
||||
text = joinCfg
|
||||
([ header (mkINI cfg.extraAccounts) (mkINI primaryAccountAccounts) ]
|
||||
++ (builtins.map mkINI orderedAccountsAccountsList)
|
||||
++ [ (mkINI unorderedAccountsAccounts) ]);
|
||||
};
|
||||
|
||||
"${configDir}/aerc.conf" = mkIf genAercConf {
|
||||
|
|
Loading…
Reference in a new issue