1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-16 08:09:45 +01:00
home-manager/modules/programs/aerc.nix

226 lines
7.1 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.aerc;
primitive = with types;
((type: either type (listOf type)) (nullOr (oneOf [ str int bool float ])))
// {
description =
aerc: add assertion to limit per-account extraConfig to UI config (#4196) * aerc: fix per-account extraConfig section names The aerc configuration file `aerc.conf` can contain 10 different sections, but only the UI section supports what the aerc manual calls contextual configuration. This works by appending to the section heading either `:account=name` or `:folder=bar`. The aerc-accounts module, however, applied `mkAccountConfig` to each section heading declared in `config.accounts.email.accounts.<name>.aerc.extraConfig.*`. This means home-manager will generate files with `[general:account=default]` and the options will not be recognized by aerc. To address this, and since it doesn't make sense for other sections to only be under a single account's scope, an assertion has been added to confirm that only sectons that support contextual config (i.e., only the UI section) is declared. This also addresses confusions like declaring `accounts.email.accounts.*.aerc.extraConfig.general.unsafe-accounts-conf = true` and triggering a warning message because `programs.aerc.extraConfig.general.unsafe-accounts-conf` was unset. This commit also updated documentation throughout the aerc modules to be in line with this change, and fixed minor typos/formatting therein. Co-authored-by: Genevieve <genevieve@sunlashed.garden> * aerc: make assertion plaintext and add test case This commit adds a test case to check both the warning on unset `unsafe-accounts-conf = true` when aerc accounts are configured with Nix, and the new assertion when per-account configuration contains unsupported subsections (i.e. general). It also fixes minor formatting issues and typos.
2023-07-14 20:34:28 +02:00
"values (null, bool, int, string, or float) or a list of values, that will be joined with a comma";
};
confSection = types.attrsOf primitive;
confSections = types.attrsOf confSection;
sectionsOrLines = types.either types.lines confSections;
accounts = import ./aerc-accounts.nix {
inherit config pkgs lib confSection confSections;
};
aerc-accounts =
attrsets.filterAttrs (_: v: v.aerc.enable) config.accounts.email.accounts;
configDir = if (pkgs.stdenv.isDarwin && !config.xdg.enable) then
2023-10-22 10:49:52 +02:00
"Library/Preferences/aerc"
else
"${config.xdg.configHome}/aerc";
in {
meta.maintainers = with lib.hm.maintainers; [ lukasngl ];
options.accounts.email.accounts = accounts.type;
options.programs.aerc = {
enable = mkEnableOption "aerc";
package = mkPackageOption pkgs "aerc" { };
2023-06-07 22:15:15 +02:00
extraAccounts = mkOption {
type = sectionsOrLines;
default = { };
example = literalExpression
''{ Work = { source = "maildir://~/Maildir/work"; }; }'';
description = ''
Extra lines added to {file}`$HOME/.config/aerc/accounts.conf`.
See {manpage}`aerc-config(5)`.
'';
};
extraBinds = mkOption {
type = sectionsOrLines;
default = { };
example = literalExpression ''{ messages = { q = ":quit<Enter>"; }; }'';
description = ''
Extra lines added to {file}`$HOME/.config/aerc/binds.conf`.
Global keybindings can be set in the `global` section.
See {manpage}`aerc-config(5)`.
'';
};
extraConfig = mkOption {
type = sectionsOrLines;
default = { };
example = literalExpression ''{ ui = { sort = "-r date"; }; }'';
description = ''
Extra lines added to {file}`$HOME/.config/aerc/aerc.conf`.
See {manpage}`aerc-config(5)`.
'';
};
stylesets = mkOption {
type = with types; attrsOf (either confSection lines);
default = { };
example = literalExpression ''
{ default = { ui = { "tab.selected.reverse" = toggle; }; }; };
'';
description = ''
Stylesets added to {file}`$HOME/.config/aerc/stylesets/`.
See {manpage}`aerc-stylesets(7)`.
'';
};
templates = mkOption {
type = with types; attrsOf lines;
default = { };
example = literalExpression ''
{ new_message = "Hello!"; };
'';
description = ''
Templates added to {file}`$HOME/.config/aerc/templates/`.
See {manpage}`aerc-templates(7)`.
'';
};
};
config = let
joinCfg = cfgs: concatStringsSep "\n" (filter (v: v != "") cfgs);
toINI = conf: # quirk: global section is prepended w/o section heading
let
global = conf.global or { };
local = removeAttrs conf [ "global" ];
mkValueString = v:
if isList v then # join with comma
concatStringsSep "," (map (generators.mkValueStringDefault { }) v)
else
generators.mkValueStringDefault { } v;
mkKeyValue =
generators.mkKeyValueDefault { inherit mkValueString; } " = ";
in joinCfg [
(generators.toKeyValue { inherit mkKeyValue; } global)
(generators.toINI { inherit mkKeyValue; } local)
];
mkINI = conf: if isString conf then conf else toINI conf;
mkStyleset = attrsets.mapAttrs' (k: v:
let value = if isString v then v else toINI { global = v; };
in {
2023-10-22 10:49:52 +02:00
name = "${configDir}/stylesets/${k}";
value.text = joinCfg [ header value ];
});
mkTemplates = attrsets.mapAttrs' (k: v: {
2023-10-22 10:49:52 +02:00
name = "${configDir}/templates/${k}";
value.text = v;
});
primaryAccount = attrsets.filterAttrs (_: v: v.primary) aerc-accounts;
otherAccounts = attrsets.filterAttrs (_: v: !v.primary) aerc-accounts;
primaryAccountAccounts = mapAttrs accounts.mkAccount primaryAccount;
accountsExtraAccounts = mapAttrs accounts.mkAccount otherAccounts;
accountsExtraConfig = mapAttrs accounts.mkAccountConfig aerc-accounts;
accountsExtraBinds = mapAttrs accounts.mkAccountBinds aerc-accounts;
joinContextual = contextual: joinCfg (map mkINI (attrValues contextual));
isRecursivelyEmpty = x:
if isAttrs x then
all (x: x == { } || isRecursivelyEmpty x) (attrValues x)
else
false;
genAccountsConf = ((cfg.extraAccounts != "" && cfg.extraAccounts != { })
|| !(isRecursivelyEmpty accountsExtraAccounts)
|| !(isRecursivelyEmpty primaryAccountAccounts));
genAercConf = ((cfg.extraConfig != "" && cfg.extraConfig != { })
|| !(isRecursivelyEmpty accountsExtraConfig));
genBindsConf = ((cfg.extraBinds != "" && cfg.extraBinds != { })
|| !(isRecursivelyEmpty accountsExtraBinds));
header = ''
# Generated by Home Manager.
'';
in mkIf cfg.enable {
warnings = if genAccountsConf
&& (cfg.extraConfig.general.unsafe-accounts-conf or false) == false then [''
aerc: add assertion to limit per-account extraConfig to UI config (#4196) * aerc: fix per-account extraConfig section names The aerc configuration file `aerc.conf` can contain 10 different sections, but only the UI section supports what the aerc manual calls contextual configuration. This works by appending to the section heading either `:account=name` or `:folder=bar`. The aerc-accounts module, however, applied `mkAccountConfig` to each section heading declared in `config.accounts.email.accounts.<name>.aerc.extraConfig.*`. This means home-manager will generate files with `[general:account=default]` and the options will not be recognized by aerc. To address this, and since it doesn't make sense for other sections to only be under a single account's scope, an assertion has been added to confirm that only sectons that support contextual config (i.e., only the UI section) is declared. This also addresses confusions like declaring `accounts.email.accounts.*.aerc.extraConfig.general.unsafe-accounts-conf = true` and triggering a warning message because `programs.aerc.extraConfig.general.unsafe-accounts-conf` was unset. This commit also updated documentation throughout the aerc modules to be in line with this change, and fixed minor typos/formatting therein. Co-authored-by: Genevieve <genevieve@sunlashed.garden> * aerc: make assertion plaintext and add test case This commit adds a test case to check both the warning on unset `unsafe-accounts-conf = true` when aerc accounts are configured with Nix, and the new assertion when per-account configuration contains unsupported subsections (i.e. general). It also fixes minor formatting issues and typos.
2023-07-14 20:34:28 +02:00
aerc: `programs.aerc.enable` is set, but `...extraConfig.general.unsafe-accounts-conf` is set to false or unset.
This will prevent aerc from starting; see `unsafe-accounts-conf` in the man page aerc-config(5):
> By default, the file permissions of accounts.conf must be restrictive and only allow reading by the file owner (0600).
> Set this option to true to ignore this permission check. Use this with care as it may expose your credentials.
aerc: add assertion to limit per-account extraConfig to UI config (#4196) * aerc: fix per-account extraConfig section names The aerc configuration file `aerc.conf` can contain 10 different sections, but only the UI section supports what the aerc manual calls contextual configuration. This works by appending to the section heading either `:account=name` or `:folder=bar`. The aerc-accounts module, however, applied `mkAccountConfig` to each section heading declared in `config.accounts.email.accounts.<name>.aerc.extraConfig.*`. This means home-manager will generate files with `[general:account=default]` and the options will not be recognized by aerc. To address this, and since it doesn't make sense for other sections to only be under a single account's scope, an assertion has been added to confirm that only sectons that support contextual config (i.e., only the UI section) is declared. This also addresses confusions like declaring `accounts.email.accounts.*.aerc.extraConfig.general.unsafe-accounts-conf = true` and triggering a warning message because `programs.aerc.extraConfig.general.unsafe-accounts-conf` was unset. This commit also updated documentation throughout the aerc modules to be in line with this change, and fixed minor typos/formatting therein. Co-authored-by: Genevieve <genevieve@sunlashed.garden> * aerc: make assertion plaintext and add test case This commit adds a test case to check both the warning on unset `unsafe-accounts-conf = true` when aerc accounts are configured with Nix, and the new assertion when per-account configuration contains unsupported subsections (i.e. general). It also fixes minor formatting issues and typos.
2023-07-14 20:34:28 +02:00
These permissions are not possible with home-manager, since the generated file is in the nix-store (permissions 0444).
Therefore, please set `programs.aerc.extraConfig.general.unsafe-accounts-conf = true`.
This option is safe; if `passwordCommand` is properly set, no credentials will be written to the nix store.
''] else
[ ];
aerc: add assertion to limit per-account extraConfig to UI config (#4196) * aerc: fix per-account extraConfig section names The aerc configuration file `aerc.conf` can contain 10 different sections, but only the UI section supports what the aerc manual calls contextual configuration. This works by appending to the section heading either `:account=name` or `:folder=bar`. The aerc-accounts module, however, applied `mkAccountConfig` to each section heading declared in `config.accounts.email.accounts.<name>.aerc.extraConfig.*`. This means home-manager will generate files with `[general:account=default]` and the options will not be recognized by aerc. To address this, and since it doesn't make sense for other sections to only be under a single account's scope, an assertion has been added to confirm that only sectons that support contextual config (i.e., only the UI section) is declared. This also addresses confusions like declaring `accounts.email.accounts.*.aerc.extraConfig.general.unsafe-accounts-conf = true` and triggering a warning message because `programs.aerc.extraConfig.general.unsafe-accounts-conf` was unset. This commit also updated documentation throughout the aerc modules to be in line with this change, and fixed minor typos/formatting therein. Co-authored-by: Genevieve <genevieve@sunlashed.garden> * aerc: make assertion plaintext and add test case This commit adds a test case to check both the warning on unset `unsafe-accounts-conf = true` when aerc accounts are configured with Nix, and the new assertion when per-account configuration contains unsupported subsections (i.e. general). It also fixes minor formatting issues and typos.
2023-07-14 20:34:28 +02:00
assertions = [{
assertion = let
extraConfigSections = (unique (flatten
(mapAttrsToList (_: v: attrNames v.aerc.extraConfig) aerc-accounts)));
in extraConfigSections == [ ] || extraConfigSections == [ "ui" ];
message = ''
Only the ui section of $XDG_CONFIG_HOME/aerc.conf supports contextual (per-account) configuration.
Please configure it with accounts.email.accounts._.aerc.extraConfig.ui and move any other
configuration to programs.aerc.extraConfig.
'';
}];
2023-06-07 22:15:15 +02:00
home.packages = [ cfg.package ];
2023-10-22 10:49:52 +02:00
home.file = {
"${configDir}/accounts.conf" = mkIf genAccountsConf {
text = joinCfg [
header
(mkINI cfg.extraAccounts)
(mkINI primaryAccountAccounts)
(mkINI accountsExtraAccounts)
];
};
2023-10-22 10:49:52 +02:00
"${configDir}/aerc.conf" = mkIf genAercConf {
text = joinCfg [
header
(mkINI cfg.extraConfig)
(joinContextual accountsExtraConfig)
];
};
2023-10-22 10:49:52 +02:00
"${configDir}/binds.conf" = mkIf genBindsConf {
text = joinCfg [
header
(mkINI cfg.extraBinds)
(joinContextual accountsExtraBinds)
];
};
} // (mkStyleset cfg.stylesets) // (mkTemplates cfg.templates);
};
}