-
Notifications
You must be signed in to change notification settings - Fork 77
/
flattenTree.nix
35 lines (34 loc) · 982 Bytes
/
flattenTree.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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