-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
50 lines (46 loc) · 2.03 KB
/
flake.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{
description = "Small library for flakes with derivations per CPU architecture";
inputs = {
cpu-architectures.url = "github:litxio/cpu-architectures";
};
outputs = { self, cpu-architectures}: {
lib =
let genAttrs = names: f: builtins.listToAttrs (map (n: nameValuePair n (f n)) names);
nameValuePair = name: value: { inherit name value; };
cpus = cpu-architectures.cpu-architectures;
eachCpuFlattened = tree:
let
op = sum: path: val:
let
pathStr = builtins.concatStringsSep "/" path;
in
if (builtins.typeOf val) == "lambda" then
# builtins.trace "${pathStr} is a lambda
sum // (builtins.listToAttrs (map (cpu: nameValuePair "${pathStr}/${cpu}" (val cpu))
cpus))
else if (builtins.typeOf val) == "set"
&& ! (val ? type && val.type == "derivation" ) then
#builtins.trace "${pathStr} is a recursive"
# recurse into that attribute set
(recurse sum path val)
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;
}) ;
recurse = sum: path: val:
builtins.foldl'
(sum: key: op sum (path ++ [ key ]) val.${key})
sum
(builtins.attrNames val)
;
in recurse { } [ ] tree;
in {
eachCpu = f: genAttrs cpu-architectures.cpu-architectures f;
# Takes a nested attrset where each leaf node is a function taking an architecture
inherit eachCpuFlattened;
};
};
}