-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistry.nix
88 lines (77 loc) · 2.98 KB
/
registry.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Adapted from https://github.com/replit/rippkgs/blob/main/lib/default.nix
{lib, ...}: let
in {
genRegistry = platform: pkgs: let
inherit (builtins) deepSeq filter listToAttrs map parseDrvName seq tryEval;
inherit (lib) filterAttrs flatten foldl isDerivation mapAttrsToList optional optionals removePrefix traceVal;
registerPackage = name: value: let
safeValue = tryEval value;
safeVal = safeValue.value;
safeRegistryValue = tryEval (deepSeq registryValue registryValue);
registryValue = {
version = safeVal.version or null;
storePaths = let
getOutput = out: {
name = out;
value = let
outPath = tryEval safeVal.${out}.outPath;
in if outPath.success then removePrefix "/nix/store/" outPath.value else "<broken>";
};
outputs-list = map getOutput (safeVal.outputs or []);
relevant-outputs = filter ({name, ...}: name == "out") outputs-list;
in
listToAttrs relevant-outputs;
};
platformForAvailability = {system = platform;};
isAvailableOn = tryEval (lib.meta.availableOn platformForAvailability safeValue.value);
available = safeValue.success && isDerivation value && isAvailableOn.success && isAvailableOn.value;
checkRegistryCondition = prev: {
reason,
ok,
}: let
isOk =
if !ok
then seq (traceVal "${name}: ${reason}") false
else true;
in
# change to `prev && isOk` to debug why a value isn't included
prev && ok;
shouldBeInRegistry = foldl checkRegistryCondition true [
{
reason = "not available on ${platformForAvailability.system}";
ok = available;
}
{
reason = "failed eval";
ok = safeRegistryValue.success;
}
{
reason = "broken outpath";
ok = safeRegistryValue.value.storePaths != { out = "<broken>"; } && safeRegistryValue.value.storePaths != {};
}
];
in
optional shouldBeInRegistry {
inherit name;
value = filterAttrs (_: v: v != null) safeRegistryValue.value;
};
registerScope = scope-name: scope: let
safeScope = tryEval scope;
list-of-scope-packages = mapAttrsToList registerPackage safeScope.value;
scope-registry-inner = flatten list-of-scope-packages;
scope-registry =
map (item: {
name = "${scope-name}.${item.name}";
value = item.value;
})
scope-registry-inner;
shouldBeInRegistry = safeScope.success && safeScope.value ? recurseForDerivations && safeScope.value.recurseForDerivations;
in
optionals shouldBeInRegistry scope-registry;
list-of-registry-packages = mapAttrsToList registerPackage pkgs;
registry-items = flatten list-of-registry-packages;
scoped-registries = flatten (mapAttrsToList registerScope pkgs);
registry = listToAttrs (registry-items ++ scoped-registries);
in
registry;
}