From 8217bcabaf9cb25361e1168a2c24089989ae98ac Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Sun, 7 Jun 2026 08:17:54 -0400 Subject: [PATCH] pkgs.formats.ini: add helper to coerce all lists more lazily Before, we would run a mapAttrs on every attribute, checking listToValue on each of them. But listToValue is known ahead of time. Instead, we can only run that map if listToValue isn't null in the first place. --- pkgs/pkgs-lib/formats.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkgs/pkgs-lib/formats.nix b/pkgs/pkgs-lib/formats.nix index 72586dca934d..5ed60f3bd05c 100644 --- a/pkgs/pkgs-lib/formats.nix +++ b/pkgs/pkgs-lib/formats.nix @@ -256,6 +256,12 @@ optionalAttrs allowAliases aliases mapAttrs (key: val: if isList val then listToValue val else val) else id; + maybeCoerceAllLists = + listToValue: + if listToValue != null then + mapAttrs (_: mapAttrs (key: val: if isList val then listToValue val else val)) + else + id; ignoredArgs = [ "listToValue" @@ -291,7 +297,7 @@ optionalAttrs allowAliases aliases generate = name: value: pipe value [ - (mapAttrs (_: maybeCoerceList listToValue)) + (maybeCoerceAllLists listToValue) (toINI (removeAttrs args ignoredArgs)) (pkgs.writeText name) ]; @@ -343,7 +349,7 @@ optionalAttrs allowAliases aliases pkgs.writeText name ( toINIWithGlobalSection (removeAttrs args ignoredArgs) { globalSection = maybeCoerceList listToValue globalSection; - sections = mapAttrs (_: maybeCoerceList listToValue) sections; + sections = maybeCoerceAllLists listToValue sections; } ); };