From 5973a46a752db79b4da746c5b6fcf3c6e37ff98b Mon Sep 17 00:00:00 2001 From: zimbatm Date: Wed, 22 Jul 2020 11:29:59 +0200 Subject: [PATCH] oops, add the flattenTree.nix file --- flattenTree.nix | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 flattenTree.nix diff --git a/flattenTree.nix b/flattenTree.nix new file mode 100644 index 0000000..a535f86 --- /dev/null +++ b/flattenTree.nix @@ -0,0 +1,35 @@ +tree: +let + op = sum: path: val: + let + pathStr = builtins.concatStringsSep "_" path; + in + if (builtins.typeOf val) != "set" then + # ignore that value + # builtins.trace "${pathStr} is not of type set" + sum + else if val ? type && val.type == "derivation" then + # builtins.trace "${pathStr} is a derivation" + # we used to use the derivation outPath as the key, but that crashes Nix + # so fallback on constructing a static key + (sum // { + "${pathStr}" = val; + }) + else if val ? recurseForDerivations && val.recurseForDerivations == true then + # builtins.trace "${pathStr} is a recursive" + # recurse into that attribute set + (recurse sum path val) + else + # ignore that value + # builtins.trace "${pathStr} is something else" + sum + ; + + recurse = sum: path: val: + builtins.foldl' + (sum: key: op sum (path ++ [ key ]) val.${key}) + sum + (builtins.attrNames val) + ; +in +recurse { } [ ] tree