1
0
Fork 0
mirror of https://github.com/numtide/flake-utils.git synced 2025-03-13 20:28:42 +00:00

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.
This commit is contained in:
NAHO 2024-09-11 19:45:32 +02:00
parent 274ed073aa
commit ce5c962a8c
No known key found for this signature in database
GPG key ID: 229CB671D09B95F5

53
lib.nix
View file

@ -29,37 +29,38 @@ let
# Builds a map from <attr>=value to <attr>.<system>=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;