-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdefault.nix
163 lines (137 loc) · 3.71 KB
/
default.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
{ lib, linkFarm, writeText
, stdenv, stdenvMirage
, icecapSrc
, icecap-ocaml-runtime
, libsel4, musl
, platformInfo, icecapExternalSrc
, root-task-tls-lds
}:
let
_stdenv = stdenv;
mk =
{ name, root ? null, roots ? [ root ]
, extraCFlagsCompile ? []
, extraCFlagsLink ? []
, buildInputs ? [], propagatedBuildInputs ? []
, passthru ? {}
, extra ? {}
, stdenv ? _stdenv
}:
let
makefile = icecapSrc.relativeSplit "c/Makefile";
f = attr: stdenv.mkDerivation ({
inherit name;
phases = [ "buildPhase" "installPhase" "fixupPhase" ];
dontStrip = true;
dontPatchELF = true;
NIX_CFLAGS_COMPILE = extraCFlagsCompile;
NIX_CFLAGS_LINK = extraCFlagsLink;
inherit buildInputs propagatedBuildInputs;
makeFlags = [
"-f" makefile.${attr}
"ROOTS=${lib.concatMapStringsSep " " (x: "${x.${attr}}/icecap.mk") roots}"
"OUT=$(out)"
"CROSS_COMPILE=${stdenv.cc.targetPrefix}"
];
passthru = {
env = f "env";
} // passthru;
shellHook = ''
m() {
make -j$NIX_BUILD_CORES SHELL=$SHELL $makeFlags $buildFlags "$@"
}
b() {
buildPhase
}
'';
} // extra);
in f "store";
mkRoot = attrs: mk (attrs // {
extraCFlagsLink = (attrs.extraCFlagsLink or []) ++ [
"-T" root-task-tls-lds
];
});
mkBasic = { name, path ? name, inputs ? [], extra ? {} }:
mk {
inherit name;
root = icecapSrc.relativeSplit "c/${path}";
propagatedBuildInputs = [
libsel4
] ++ inputs;
inherit extra;
};
mkLibs = isRoot: lib.fix (self: with self; {
compiler-some-libc = linkFarm "compiler-some-libc" [
{ name = "include"; path = "${stdenv.cc.cc}/lib/gcc/${stdenv.cc.cc.targetConfig}/${stdenv.cc.cc.version}/include"; }
];
icecap-runtime = mkBasic {
name = "icecap-runtime";
extra.ICECAP_RUNTIME_CONFIG_IN = writeText "config_in.h" (''
#pragma once
'' + lib.optionalString isRoot ''
#define ICECAP_RUNTIME_ROOT
'');
};
icecap-utils = mkBasic {
name = "icecap-utils";
inputs = [
icecap-runtime
];
};
icecap-some-libc = mkBasic {
name = "icecap-some-libc";
inputs = [
icecap-runtime
icecap-utils
compiler-some-libc
];
};
cpio = mkBasic rec {
name = "cpio";
path = "boot/${name}";
};
} // lib.optionalAttrs (!isRoot) {
icecap-mirage-glue = mk {
stdenv = stdenvMirage;
name = "icecap-mirage-glue";
root = icecapSrc.relativeSplit "c/icecap-mirage-glue";
propagatedBuildInputs = [
stdenvMirage.cc.libc # HACK
libsel4
icecap-runtime
icecap-ocaml-runtime
icecap-utils # HACK
];
};
} // lib.optionalAttrs isRoot {
capdl-loader-shim = mkBasic rec {
name = "capdl-loader-shim";
path = "boot/${name}";
inputs = [
icecap-utils
icecap-some-libc
];
};
capdl-loader-core = mkBasic rec {
name = "capdl-loader-core";
path = "boot/${name}";
inputs = [
icecap-runtime
icecap-some-libc
icecap-utils
cpio
capdl-loader-shim
];
extra.CAPDL_LOADER_EXTERNAL_SOURCE = icecapExternalSrc.capdl.extendInnerSuffix "capdl-loader-app";
extra.CAPDL_LOADER_PLATFORM_INFO_H = platformInfo;
extra.CAPDL_LOADER_CONFIG_IN_H = writeText "config_in.h" ''
#pragma once
#define CONFIG_CAPDL_LOADER_MAX_OBJECTS 10000
'';
};
});
rootLibs = mkLibs true;
nonRootLibs = mkLibs false;
in {
inherit mk mkRoot rootLibs nonRootLibs;
}