mirror of
https://github.com/numtide/flake-utils.git
synced 2025-03-15 04:58:05 +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:
parent
274ed073aa
commit
ce5c962a8c
1 changed files with 27 additions and 26 deletions
53
lib.nix
53
lib.nix
|
@ -29,37 +29,38 @@ let
|
||||||
# Builds a map from <attr>=value to <attr>.<system>=value for each system.
|
# Builds a map from <attr>=value to <attr>.<system>=value for each system.
|
||||||
eachSystem =
|
eachSystem =
|
||||||
systems: f:
|
systems: f:
|
||||||
let
|
builtins.foldl'
|
||||||
# Merge outputs for each system.
|
(
|
||||||
op =
|
# Merge outputs for each system.
|
||||||
attrs: system:
|
attrs: system:
|
||||||
let
|
let
|
||||||
ret = f system;
|
ret = f system;
|
||||||
op =
|
|
||||||
attrs: key:
|
|
||||||
attrs
|
|
||||||
// {
|
|
||||||
${key} = (attrs.${key} or { }) // {
|
|
||||||
${system} = ret.${key};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
builtins.foldl' op attrs (builtins.attrNames ret);
|
builtins.foldl' (
|
||||||
in
|
attrs: key:
|
||||||
builtins.foldl' op { } (
|
attrs
|
||||||
systems
|
// {
|
||||||
++
|
${key} = (attrs.${key} or { }) // {
|
||||||
# Add the current system if the --impure flag is used.
|
${system} = ret.${key};
|
||||||
(
|
};
|
||||||
if builtins ? currentSystem then
|
}
|
||||||
if builtins.elem builtins.currentSystem systems then
|
) 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
|
else
|
||||||
[ builtins.currentSystem ]
|
[ ]
|
||||||
else
|
)
|
||||||
[ ]
|
);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
# eachSystemMap using defaultSystems
|
# eachSystemMap using defaultSystems
|
||||||
eachDefaultSystemMap = eachSystemMap defaultSystems;
|
eachDefaultSystemMap = eachSystemMap defaultSystems;
|
||||||
|
|
Loading…
Add table
Reference in a new issue