Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ eachSystem allSystems (system: { hello = 42; })
}
```

If you pass a function rather than an attribute set after the `system` argument,
it will receive as its argument the final attribute set. For example:

```nix
eachSystem [ system.x86_64-linux ] (system: self: { a = 2; b = self.a + 3; })
```

`self` is not that useful in this case, as it can be replaced with the `rec`
keyword but there can be situations where it is preferred.

### `eachDefaultSystem :: (<system> -> attrs)`

`eachSystem` pre-populated with `defaultSystems`.
Expand Down
11 changes: 9 additions & 2 deletions lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let
# Merge together the outputs for all systems.
op = attrs: system:
let
ret = f system;
ret = maybeFix (f system);
op = attrs: key: attrs //
{
${key} = (attrs.${key} or { })
Expand All @@ -50,7 +50,8 @@ let
eachDefaultSystemMap = eachSystemMap defaultSystems;

# Builds a map from <attr>=value to <system>.<attr> = value.
eachSystemMap = systems: f: builtins.listToAttrs (builtins.map (system: { name = system; value = f system; }) systems);
eachSystemMap = systems: f:
builtins.listToAttrs (builtins.map (system: { name = system; value = maybeFix (f system); }) systems);

# Nix flakes insists on having a flat attribute set of derivations in
# various places like the `packages` and `checks` attributes.
Expand Down Expand Up @@ -201,5 +202,11 @@ let
system
;
};

maybeFix = arg:
let
fix = f: let x = f x; in x;
in
if builtins.isFunction arg then fix arg else arg;
in
lib