-
Notifications
You must be signed in to change notification settings - Fork 365
/
overlay.nix
189 lines (162 loc) · 6.62 KB
/
overlay.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
{
withCcache, # Enable ccache. Requires correct permissions, see below.
smp, # Enable multicore support (SMP)
} :
final: prev: {
stdenvIncludeOS = prev.pkgsStatic.lib.makeScope prev.pkgsStatic.newScope (self: {
llvmPkgs = prev.pkgsStatic.llvmPackages_18;
stdenv = self.llvmPkgs.libcxxStdenv; # Use this as base stdenv
# Import unpatched musl for building libcxx. Libcxx needs some linux headers to be passed through.
musl-unpatched = self.callPackage ./deps/musl-unpatched/default.nix { linuxHeaders = prev.linuxHeaders; };
# Import IncludeOS musl which will be built and linked with IncludeOS services
musl-includeos = self.callPackage ./deps/musl/default.nix { };
# Clang with unpatched musl for building libcxx
clang_musl_unpatched_nolibcxx = self.llvmPkgs.clangNoLibcxx.override (old: {
bintools = prev.pkgsStatic.bintools.override {
# Disable hardening flags while we work on the build
defaultHardeningFlags = [];
libc = self.musl-unpatched;
};
libc = self.musl-unpatched;
});
# Libcxx which will be built with unpatched musl
libcxx_musl_unpatched = self.llvmPkgs.libcxx.override (old: {
stdenv = (prev.overrideCC self.llvmPkgs.libcxxStdenv self.clang_musl_unpatched_nolibcxx);
});
# Final stdenv, use libcxx w/unpatched musl + includeos musl as libc
clang_musl_includeos_libcxx = self.llvmPkgs.libcxxClang.override (old: {
bintools = prev.pkgsStatic.bintools.override {
# Disable hardening flags while we work on the build
defaultHardeningFlags = [];
libc = self.musl-includeos;
};
libc = self.musl-includeos;
libcxx = self.libcxx_musl_unpatched;
});
musl_includeos_stdenv_libcxx = (prev.overrideCC self.llvmPkgs.libcxxStdenv self.clang_musl_includeos_libcxx);
includeos_stdenv = self.musl_includeos_stdenv_libcxx;
libraries = {
libc = self.musl-includeos;
libcxx = {
# There doesn't seem to be a single package containing both libc++ headers and libs.
lib = "${self.libcxx_musl_unpatched}/lib";
include = "${self.libcxx_musl_unpatched.dev}/include/c++/v1";
};
libunwind = self.llvmPkgs.libraries.libunwind;
libgcc = self.llvmPkgs.compiler-rt;
};
});
pkgsIncludeOS = prev.pkgsStatic.lib.makeScope prev.pkgsStatic.newScope (self: {
# self.callPackage will use this stdenv.
stdenv = final.stdenvIncludeOS.includeos_stdenv;
# Deps
uzlib = self.callPackage ./deps/uzlib/default.nix { };
botan2 = self.callPackage ./deps/botan/default.nix { };
s2n-tls = self.callPackage ./deps/s2n/default.nix { };
http-parser = self.callPackage ./deps/http-parser/default.nix { };
vmbuild = self.callPackage ./vmbuild.nix { };
ccacheWrapper = prev.ccacheWrapper.override {
inherit (self.stdenv) cc;
extraConfig = ''
export CCACHE_COMPRESS=1
export CCACHE_DIR="/nix/var/cache/ccache"
export CCACHE_UMASK=007
export CCACHE_SLOPPINESS=random_seed
if [ ! -d "$CCACHE_DIR" ]; then
echo "====="
echo "Directory '$CCACHE_DIR' does not exist"
echo "Please create it with:"
echo " sudo mkdir -m0770 '$CCACHE_DIR'"
echo " sudo chown root:nixbld '$CCACHE_DIR'"
echo "====="
exit 1
fi
if [ ! -w "$CCACHE_DIR" ]; then
echo "====="
echo "Directory '$CCACHE_DIR' is not accessible for user $(whoami)"
echo "Please verify its access permissions"
echo "====="
exit 1
fi
'';
};
# IncludeOS
includeos = self.stdenv.mkDerivation rec {
enableParallelBuilding = true;
pname = "includeos";
version = "dev";
# Convenient access to libc, libcxx etc
passthru.libraries = final.stdenvIncludeOS.libraries;
src = prev.pkgsStatic.lib.fileset.toSource {
root = ./.;
# Only include files needed by IncludeOS (not examples, docs etc)
fileset = prev.pkgsStatic.lib.fileset.unions [
./src
./api
./cmake
./deps
./userspace
./lib
./CMakeLists.txt
];
};
# If you need to patch, this is the place
postPatch = '''';
nativeBuildInputs = [
prev.buildPackages.cmake
prev.buildPackages.nasm
] ++ prev.lib.optionals withCcache [self.ccacheWrapper];
buildInputs = [
self.botan2
self.http-parser
prev.pkgsStatic.openssl
prev.pkgsStatic.rapidjson
#self.s2n-tls 👈 This is postponed until we can fix the s2n build.
self.uzlib
self.vmbuild
];
postInstall = ''
echo Copying vmbuild binaries to tools/vmbuild
mkdir -p "$out/tools/vmbuild"
cp -v ${self.vmbuild}/bin/* "$out/tools/vmbuild"
cp -r -v ${final.stdenvIncludeOS.libraries.libc} $out/libc
mkdir $out/libcxx
cp -r -v ${final.stdenvIncludeOS.libraries.libcxx.lib} $out/libcxx/lib
cp -r -v ${final.stdenvIncludeOS.libraries.libcxx.include} $out/libcxx/include
cp -r -v ${final.stdenvIncludeOS.libraries.libunwind} $out/libunwind
cp -r -v ${final.stdenvIncludeOS.libraries.libgcc} $out/libgcc
'';
archFlags = if self.stdenv.targetPlatform.system == "i686-linux" then
[
"-DARCH=i686"
"-DPLATFORM=nano" # we currently only support nano platform on i686
]
else
[ "-DARCH=x86_64"];
smpFlags = if smp then [ "-DSMP=ON" ] else [];
cmakeFlags = archFlags ++ smpFlags;
# Add some pasthroughs, for easily building the dependencies (for debugging):
# $ nix-build -A NAME
passthru.vmrunner = prev.callPackage (builtins.fetchGit {
url = "https://github.com/includeos/vmrunner";
}) {};
passthru.chainloader = import ./chainloader.nix { inherit withCcache; };
passthru.lest = self.callPackage ./deps/lest {};
passthru.pkgsStatic = prev.pkgsStatic; # this is for convenience for other packages that depend on includeos
passthru.pkgs = prev.pkgs; # this is for convenience for other packages that depend on includeos
passthru = {
inherit (self) uzlib;
inherit (self) http-parser;
inherit (self) botan2;
#inherit (self) s2n-tls;
inherit (self) cmake;
inherit (self) vmbuild;
};
meta = {
description = "Run your application with zero overhead";
homepage = "https://www.includeos.org/";
license = prev.pkgsStatic.lib.licenses.asl20;
};
};
});
}