refactor: reduce code duplication with merge-with-aliases helper

Add merge-with-aliases function to attrs module and use it across checks,
modules, packages, shells, and templates to eliminate repeated alias merging
logic. Also optimize get-libs by replacing filter+map with a fold operation.
This commit is contained in:
anntnzrb
2025-10-08 22:40:48 -05:00
parent a905b259d5
commit 973b06a645
8 changed files with 37 additions and 27 deletions

View File

@@ -97,12 +97,15 @@ rec {
#@ Attrs -> Attrs
get-libs =
attrs:
let
# @PERF(jakehamilton): Replace filter+map with a fold.
attrs-with-libs = filterAttrs (name: value: builtins.isAttrs (value.lib or null)) attrs;
libs = builtins.mapAttrs (name: input: input.lib) attrs-with-libs;
in
libs;
foldl
(acc: name:
let value = attrs.${name}; in
if builtins.isAttrs (value.lib or null)
then acc // { ${name} = value.lib; }
else acc
)
{ }
(builtins.attrNames attrs);
};
mkFlake =