From ce5c962a8c847c67cf066f054237d0163eb1649d Mon Sep 17 00:00:00 2001 From: NAHO <90870942+trueNAHO@users.noreply.github.com> Date: Wed, 11 Sep 2024 19:45:32 +0200 Subject: [PATCH] lib: eachSystem: inline single-use local variables Inline single-use local variables to minimize cognitive load while reading the code, unless they cache computational results. --- lib.nix | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/lib.nix b/lib.nix index a3eeecd..2d40b43 100644 --- a/lib.nix +++ b/lib.nix @@ -29,37 +29,38 @@ let # Builds a map from =value to .=value for each system. eachSystem = systems: f: - let - # Merge outputs for each system. - op = + builtins.foldl' + ( + # Merge outputs for each system. attrs: system: let ret = f system; - op = - attrs: key: - attrs - // { - ${key} = (attrs.${key} or { }) // { - ${system} = ret.${key}; - }; - }; in - builtins.foldl' op attrs (builtins.attrNames ret); - in - builtins.foldl' op { } ( - systems - ++ - # Add the current system if the --impure flag is used. - ( - if builtins ? currentSystem then - if builtins.elem builtins.currentSystem systems then - [ ] + builtins.foldl' ( + attrs: key: + attrs + // { + ${key} = (attrs.${key} or { }) // { + ${system} = ret.${key}; + }; + } + ) attrs (builtins.attrNames ret) + ) + { } + ( + systems + ++ + # Add the current system if the --impure flag is used. + ( + if builtins ? currentSystem then + if builtins.elem builtins.currentSystem systems then + [ ] + else + [ builtins.currentSystem ] else - [ builtins.currentSystem ] - else - [ ] - ) - ); + [ ] + ) + ); # eachSystemMap using defaultSystems eachDefaultSystemMap = eachSystemMap defaultSystems;