From 57d1027e1eaf1220342248ff18d34f42b0beea7b Mon Sep 17 00:00:00 2001 From: Lukas Nagel <69244516+lukasngl@users.noreply.github.com> Date: Sat, 5 Jul 2025 02:54:53 +0200 Subject: [PATCH] aerc: allow config sections to be lines (#7280) There are some sections that are order sensitive, e.g. filters, so just lines will preserve that order. Fixes: #6059 --- modules/programs/aerc/default.nix | 41 +++++++++++-------- .../programs/aerc/extraConfig.expected | 10 +++++ tests/modules/programs/aerc/settings.nix | 12 ++++++ 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/modules/programs/aerc/default.nix b/modules/programs/aerc/default.nix index 8ee5546a..0f70ef03 100644 --- a/modules/programs/aerc/default.nix +++ b/modules/programs/aerc/default.nix @@ -33,7 +33,7 @@ let confSection = types.attrsOf primitive; - confSections = types.attrsOf confSection; + confSections = types.attrsOf (types.either types.lines confSection); sectionsOrLines = types.either types.lines confSections; @@ -132,30 +132,39 @@ in let joinCfg = cfgs: lib.concatStringsSep "\n" (lib.filter (v: v != "") cfgs); - toINI = - conf: # quirk: global section is prepended w/o section heading + sectionsToINI = + conf: let global = conf.global or { }; local = removeAttrs conf [ "global" ]; - mkValueString = - v: - if lib.isList v then # join with comma - lib.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) - ]; + joinCfg ([ (sectionToINI "global" global) ] ++ (lib.mapAttrsToList sectionToINI local)); - mkINI = conf: if lib.isString conf then conf else toINI conf; + sectionToINI = + name: section: + let + # quirk: global section is prepended w/o section heading + header = if name == "global" then "" else "[${lib.escape [ "[" "]" ] name}]\n"; + content = + if lib.isString section then section else generators.toKeyValue { inherit mkKeyValue; } section; + in + if builtins.stringLength content > 0 then header + content else ""; + + mkValueString = + v: + if lib.isList v then # join with comma + lib.concatStringsSep "," (map (generators.mkValueStringDefault { }) v) + else + generators.mkValueStringDefault { } v; + + mkINI = conf: if lib.isString conf then conf else sectionsToINI conf; + + mkKeyValue = generators.mkKeyValueDefault { inherit mkValueString; } " = "; mkStyleset = attrsets.mapAttrs' ( k: v: let - value = if lib.isString v then v else toINI { global = v; }; + value = if lib.isString v then v else sectionsToINI { global = v; }; in { name = "${configDir}/stylesets/${k}"; diff --git a/tests/modules/programs/aerc/extraConfig.expected b/tests/modules/programs/aerc/extraConfig.expected index 416db406..b90fc075 100644 --- a/tests/modules/programs/aerc/extraConfig.expected +++ b/tests/modules/programs/aerc/extraConfig.expected @@ -1,5 +1,15 @@ # Generated by Home Manager. +[filters] +text/plain=colorize +text/calendar=calendar +message/delivery-status=colorize +message/rfc822=colorize +text/html=pandoc -f html -t plain | colorize +text/html=html | colorize +text/*=bat -fP --file-name="$AERC_FILENAME" +.headers=colorize + [general] unsafe-accounts-conf = true diff --git a/tests/modules/programs/aerc/settings.nix b/tests/modules/programs/aerc/settings.nix index 32682be5..a0318e64 100644 --- a/tests/modules/programs/aerc/settings.nix +++ b/tests/modules/programs/aerc/settings.nix @@ -72,6 +72,18 @@ "ui:account=Test" = { sidebar-width = 1337; }; + + # https://github.com/nix-community/home-manager/issues/6059 + filters = '' + text/plain=colorize + text/calendar=calendar + message/delivery-status=colorize + message/rfc822=colorize + text/html=pandoc -f html -t plain | colorize + text/html=html | colorize + text/*=bat -fP --file-name="$AERC_FILENAME" + .headers=colorize + ''; }; stylesets = {