From 19d1236d54002dd4b14cdb7e76970b8475ed013a Mon Sep 17 00:00:00 2001 From: ilkecan Date: Wed, 7 Sep 2022 00:52:51 +0000 Subject: [PATCH] each{,Default}System: accept binary functions Closes: #78 --- README.md | 8 ++++++++ default.nix | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e2ac15e..46ca7dc 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,14 @@ 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 -> ( -> attrs)` `eachSystem` pre-populated with `defaultSystems`. diff --git a/default.nix b/default.nix index 8c2c729..8cf4892 100644 --- a/default.nix +++ b/default.nix @@ -125,7 +125,14 @@ let # Merge together the outputs for all systems. op = attrs: system: let - ret = f system; + ret = + let + retOrFunc = f system; + in + if builtins.isFunction retOrFunc + then retOrFunc ret + else retOrFunc; + op = attrs: key: let appendSystem = key: system: ret: