diff --git a/README.md b/README.md index 84c4bdc..2cc94ef 100644 --- a/README.md +++ b/README.md @@ -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 :: ( -> attrs)` `eachSystem` pre-populated with `defaultSystems`. diff --git a/lib.nix b/lib.nix index c007888..94e0a45 100644 --- a/lib.nix +++ b/lib.nix @@ -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 { }) @@ -50,7 +50,8 @@ let eachDefaultSystemMap = eachSystemMap defaultSystems; # Builds a map from =value to . = 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. @@ -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