-
Notifications
You must be signed in to change notification settings - Fork 0
/
component.nix
114 lines (110 loc) · 4.25 KB
/
component.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
pkgs: mkCombinedDeployment: parseConfig:
rec {
mkComponentSet = mkComponent: name: nedrylandComponents:
mkComponent
({
inherit name;
nedrylandType = "component-set";
} // nedrylandComponents);
mkComponent =
path:
let
mkComponentInner = attrs@{ name, nedrylandType ? "component", ... }:
let
component =
attrs // {
inherit name path nedrylandType;
} // (pkgs.lib.optionalAttrs (nedrylandType != "component-set" && attrs ? deployment) {
# the deploy target is simply the sum of everything
# in the deployment set
deploy = mkCombinedDeployment "${name}-deploy" attrs.deployment;
deployment = attrs.deployment //
(pkgs.linkFarm
"${name}-deployment"
(pkgs.lib.mapAttrsToList (name: path: { inherit name path; }) attrs.deployment));
}) // (pkgs.lib.optionalAttrs (nedrylandType != "component-set" && attrs ? docs && !pkgs.lib.isDerivation attrs.docs) {
# the docs target is a symlinkjoin of all sub-derivations
docs =
let
resolvedDocDrvs = builtins.mapAttrs
(key: func: (func.docfunction name key))
(pkgs.lib.filterAttrs (_: v: builtins.isAttrs v && v ? docfunction) attrs.docs);
attrsWithResolvedDocDrvs = attrs.docs // resolvedDocDrvs;
in
pkgs.symlinkJoin {
name = "${name}-docs";
paths = builtins.attrValues resolvedDocDrvs ++ (builtins.filter pkgs.lib.isDerivation (builtins.attrValues attrs.docs));
passthru = attrsWithResolvedDocDrvs;
postBuild = ''
mkdir -p $out/share/doc/${name}/
echo '${builtins.toJSON attrsWithResolvedDocDrvs}' > $out/share/doc/${name}/metadata.json
'';
};
});
docsRequirement = (parseConfig {
key = "docs";
structure = { requirements = { "${component.nedrylandType}" = [ ]; }; };
}
).requirements."${component.nedrylandType}";
in
assert pkgs.lib.assertMsg
(docsRequirement != [ ] -> component ? docs && builtins.all
(e: builtins.elem e (builtins.attrNames attrs.docs))
docsRequirement)
''Projects config demands type "${component.nedrylandType}" to have at least: ${builtins.concatStringsSep ", " docsRequirement}.
"${component.name}" has: ${builtins.concatStringsSep "," (builtins.attrNames attrs.docs or { })}.'';
(
(pkgs.linkFarm
name
(pkgs.lib.mapAttrsToList
(name: path: { inherit name path; })
(pkgs.lib.filterAttrs (_: pkgs.lib.isDerivation) component)))
// (builtins.removeAttrs component [ "passthru" ])
// (component.passthru or { })
// {
isNedrylandComponent = true;
overrideAttrs = f: mkComponentInner (attrs // (f component));
override = arg: mkComponentInner (attrs // arg);
componentAttrs = component;
nedrylandComponents = pkgs.lib.filterAttrs (_: c: c.isNedrylandComponent or false) component;
}
);
in
mkComponentInner;
mapComponentsRecursive = f:
let
recurse = path:
let
g =
name: value:
if value.isNedrylandComponent or false then
recurse (path ++ [ name ]) (f (path ++ [ name ]) value)
else
value;
in
builtins.mapAttrs g;
in
recurse [ ];
collectComponentsRecursive =
let
recurse = path:
let
g =
name: value:
if value.isNedrylandComponent or false then
[
({
accessPath = path ++ [ name ];
} // value)
] ++ (recurse (path ++ [ name ]) value)
else
[ ];
in
set:
let
componentSet = set.nedrylandComponents or set;
in
builtins.concatMap (name: g name (builtins.getAttr name componentSet)) (builtins.attrNames componentSet);
in
recurse [ ];
}