Skip to content

Commit 78b3158

Browse files
committed
each{,Default}System: accept binary functions
closes: #78
1 parent ff7b65b commit 78b3158

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ eachSystem allSystems (system: { hello = 42; })
8383
}
8484
```
8585

86+
If you pass a function rather than an attribute set after the `system` argument,
87+
it will receive as its argument the final attribute set. For example:
88+
89+
```nix
90+
eachSystem [ system.x86_64-linux ] (system: self: { a = 2; b = self.a + 3; })
91+
```
92+
93+
`self` is not that useful in this case, as it can be replaced with the `rec`
94+
keyword but there can be situations where it is preferred.
95+
8696
### `eachDefaultSystem :: (<system> -> attrs)`
8797

8898
`eachSystem` pre-populated with `defaultSystems`.

lib.nix

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ let
3333
# Merge together the outputs for all systems.
3434
op = attrs: system:
3535
let
36-
ret = f system;
36+
ret =
37+
let
38+
retOrFunc = f system;
39+
in
40+
if builtins.isFunction retOrFunc
41+
then retOrFunc ret
42+
else retOrFunc;
3743
op = attrs: key: attrs //
3844
{
3945
${key} = (attrs.${key} or { })

0 commit comments

Comments
 (0)