-
Notifications
You must be signed in to change notification settings - Fork 64
/
flake.nix
323 lines (314 loc) · 12 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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
{
inputs = {
fenix = {
url = "github:rvolosatovs/fenix/fix/rustc-patch";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
nixpkgs = {
url = "github:nixos/nixpkgs";
};
windows_sdk = {
url = "github:tangramdotdev/windows_sdk";
};
};
outputs =
inputs: inputs.flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
(self: super: {
abuild = super.abuild.overrideAttrs (old: {
patches = [
(pkgs.fetchpatch {
url = "https://gitlab.alpinelinux.org/alpine/abuild/-/merge_requests/130.patch";
sha256 = "sha256-9+MpH9HTNDzfRd7vwTD2yU7guIYScAuGMpsqSdvZ9p4=";
})
];
patchPhase = null;
postPatch = old.patchPhase;
propagatedBuildInputs = with self; [
apk-tools
fakeroot
libressl
pax-utils
];
});
rpm = super.rpm.overrideAttrs (_: {
patches = [
(pkgs.fetchpatch {
url = "https://github.com/rpm-software-management/rpm/pull/1775.patch";
sha256 = "sha256-WYlxPGcPB5lGQmkyJ/IpGoqVfAKtMxKzlr5flTqn638=";
})
];
});
rust-cbindgen = super.rust-cbindgen.overrideAttrs (_: {
doCheck = false;
});
zig = super.zig.overrideAttrs (_: {
src = self.fetchFromGitHub {
owner = "ziglang";
repo = "zig";
rev = "88d1258e08e668e620d5f8f4681315e555acbcd2";
hash = "sha256-zNPrze2XxF+4ZwTq0LN2Y9tmPHd7lY6Nb3Cy9KN2Il8=";
};
patches = [
(self.fetchpatch {
url = "https://github.com/ziglang/zig/pull/9771.patch";
sha256 = "sha256-AaMNNBET/x0f3a9oxpgBZXnUdKH4bydKMLJfXLBmvZo=";
})
];
});
})
];
};
x86_64_windows_node_import_lib = pkgs.runCommand "x86_64_windows_node_import_lib"
{
nativeBuildInputs = with pkgs; [
cacert
curl
];
outputHashMode = "recursive";
outputHash = "sha256-UDGJrdZHB1ZLKUKYWzU5DCnXNPOLjC9Elwzkhuit/OE=";
}
''
mkdir $out
curl https://nodejs.org/dist/v16.4.0/win-x64/node.lib --output $out/node.lib
'';
rust = inputs.fenix.packages.${system}.fromToolchainFile {
dir = ./.;
sha256 = "sha256-Sj1xHYLXoz+F38X6OYUH8GzphSUyHDnKefjw7CSQWaE=";
};
windows_sdk_manifest_url = "https://download.visualstudio.microsoft.com/download/pr/9a26f37e-6001-429b-a5db-c5455b93953c/25b853a26e065037b83c3dd6aac74bfbfd1f09c9639d1f8c877ecc8d11ea0feb/VisualStudio.vsman";
windows_sdk_manifest_sha256 = "6a2676b65e32c04db17e80d7d87ba60b0c75dd3465c7db5e76ae3db8ca409d85";
windows_sdk_manifest = pkgs.runCommand "manifest"
{
nativeBuildInputs = with pkgs; [
(inputs.windows_sdk.defaultPackage.${system})
];
outputHashMode = "recursive";
outputHash = "sha256-Y6bShDDL0kUsLslJxbPDFFOUOq0Y60TPDT1s4L3Gdgc=";
}
''
windows_sdk \
download-manifest \
--manifest-url ${windows_sdk_manifest_url} \
--sha256 ${windows_sdk_manifest_sha256} \
--output $out
'';
windows_sdk_packages = pkgs.runCommand "packages"
{
nativeBuildInputs = with pkgs; [
(inputs.windows_sdk.defaultPackage.${system})
];
outputHashMode = "recursive";
outputHash = "sha256-8j4LEopZUYs22Hl9y9+js5lVLVzG/ug0qOjeqbEY//Y=";
}
''
windows_sdk \
choose-packages \
--manifest ${windows_sdk_manifest} \
--package Microsoft.VisualStudio.VC.Llvm.Clang \
--package Microsoft.VisualStudio.Component.VC.Tools.x86.x64 \
--package Microsoft.VisualStudio.Component.Windows10SDK.19041 \
--output $out
'';
windows_sdk_cache = pkgs.runCommand "packages"
{
nativeBuildInputs = with pkgs; [
(inputs.windows_sdk.defaultPackage.${system})
];
outputHashMode = "recursive";
outputHash = "sha256-p7vhv81dccFS8krmo0wvoH0gVJRmyohk9M2tjhz23HA=";
}
''
windows_sdk \
download-packages \
--packages ${windows_sdk_packages} \
--cache $out
'';
windows_sdk = pkgs.runCommand "windows_sdk"
{
nativeBuildInputs = with pkgs; [
(inputs.windows_sdk.defaultPackage.${system})
];
outputHashMode = "recursive";
outputHash = "sha256-9NzAi6NKrUK0TgO5uyUjsI5IcrPEeC+csLcUrlWqIhM=";
}
''
windows_sdk \
extract-packages \
--packages ${windows_sdk_packages} \
--cache ${windows_sdk_cache} \
--output $out
'';
macos_sdk = builtins.fetchTarball {
url = "https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz";
sha256 = "sha256-BoFWhRSHaD0j3dzDOFtGJ6DiRrdzMJhkjxztxCluFKo=";
};
in
rec {
defaultApp = inputs.flake-utils.lib.mkApp {
drv = defaultPackage;
};
defaultPackage = (pkgs.makeRustPlatform {
rustc = rust;
cargo = rust;
}).buildRustPackage ({
name = "modelfox";
src = ./.;
doCheck = false;
cargoLock = { lockFile = ./Cargo.lock; };
cargoBuildFlags = "--package modelfox_cli";
});
apps.www = inputs.flake-utils.lib.mkApp {
drv = packages.www;
};
packages.www = (pkgs.makeRustPlatform {
rustc = rust;
cargo = rust;
}).buildRustPackage ({
name = "modelfox_www";
src = ./.;
doCheck = false;
cargoLock = { lockFile = ./Cargo.lock; };
cargoBuildFlags = "--package modelfox_www";
});
devShell = pkgs.mkShell {
packages = with pkgs; [
(inputs.windows_sdk.defaultPackage.${system})
abuild
cachix
cargo-insta
cargo-outdated
clang_12
createrepo_c
doxygen
dpkg
elixir
gnupg
go
lld_12
llvm_12
mold
nodejs
(php.withExtensions ({ all, ... }: with all; [
curl
dom
ffi
fileinfo
filter
iconv
mbstring
simplexml
tokenizer
]))
php.packages.composer
python3
rpm
ruby
rust
rust-cbindgen
sqlite
time
wasm-bindgen-cli
zig
];
# aarch64-linux-gnu
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = pkgs.writeShellScriptBin "linker" ''
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) zig cc -target aarch64-linux-gnu.2.28 $@
'' + /bin/linker;
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS = "-C target-feature=-outline-atomics";
CC_aarch64_unknown_linux_gnu = pkgs.writeShellScriptBin "cc" ''
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) zig cc -target aarch64-linux-gnu.2.28 $@
'' + /bin/cc;
# aarch64-linux-musl
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER = pkgs.writeShellScriptBin "linker" ''
for arg do
shift
[ "$arg" = "-lgcc_s" ] && set -- "$@" "-lunwind" && continue
set -- "$@" "$arg"
done
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) zig cc -target aarch64-linux-musl -dynamic $@
'' + /bin/linker;
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS = "-C target-feature=-crt-static";
CC_aarch64_unknown_linux_musl = pkgs.writeShellScriptBin "cc" ''
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) zig cc -target aarch64-linux-musl $@
'' + /bin/cc;
# aarch64-macos
CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER = pkgs.writeShellScriptBin "linker" ''
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) zig cc -target aarch64-macos.11 -L${inputs.nixpkgs.legacyPackages.aarch64-darwin.libiconv}/lib -F${macos_sdk}/System/Library/Frameworks -Wl,-undefined=dynamic_lookup $@
'' + /bin/linker;
CC_aarch64_apple_darwin = pkgs.writeShellScriptBin "cc" ''
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) zig cc -target aarch64-macos.11 $@
'' + /bin/cc;
# wasm32
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER = "lld";
# x86_64-linux-gnu
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER = pkgs.writeShellScriptBin "linker" ''
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) zig cc -target x86_64-linux-gnu.2.28 $@
'' + /bin/linker;
CC_x86_64_unknown_linux_gnu = pkgs.writeShellScriptBin "cc" ''
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) zig cc -target x86_64-linux-gnu.2.28 $@
'' + /bin/cc;
# x86_64-linux-musl
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER = pkgs.writeShellScriptBin "linker" ''
for arg do
shift
[ "$arg" = "-lgcc_s" ] && set -- "$@" "-lunwind" && continue
set -- "$@" "$arg"
done
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) zig cc -target x86_64-linux-musl -dynamic $@
'' + /bin/linker;
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGS = "-C target-feature=-crt-static";
CC_x86_64_unknown_linux_musl = pkgs.writeShellScriptBin "cc" ''
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) zig cc -target x86_64-linux-musl $@
'' + /bin/cc;
# x86_64-macos
CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER = pkgs.writeShellScriptBin "linker" ''
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) zig cc -target x86_64-macos.11 -L${inputs.nixpkgs.legacyPackages.x86_64-darwin.libiconv}/lib -F${macos_sdk}/System/Library/Frameworks -Wl,-undefined=dynamic_lookup $@
'' + /bin/linker;
CC_x86_64_apple_darwin = pkgs.writeShellScriptBin "cc" ''
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) zig cc -target x86_64-macos.11 $@
'' + /bin/cc;
# x86_64-windows-gnu
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER = pkgs.writeShellScriptBin "linker" ''
for arg do
shift
[ "$arg" = "-lgcc" ] && continue
[ "$arg" = "-lgcc_eh" ] && continue
[ "$arg" = "-l:libpthread.a" ] && continue
set -- "$@" "$arg"
done
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) zig cc -target x86_64-windows-gnu -lstdc++ $@
'' + /bin/linker;
CC_x86_64_pc_windows_gnu = pkgs.writeShellScriptBin "cc" ''
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) zig cc -target x86_64-windows-gnu $@
'' + /bin/cc;
# x86_64-windows-msvc
AR_x86_64_pc_windows_msvc = "llvm-lib";
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER = pkgs.writeShellScriptBin "linker" ''
lld-link \
/libpath:"${windows_sdk}/VC/Tools/Llvm/lib" \
/libpath:"${windows_sdk}/VC/Tools/MSVC/14.29.30133/lib/x64" \
/libpath:"${windows_sdk}/Program Files/Windows Kits/10/Lib/10.0.19041.0/ucrt/x64" \
/libpath:"${windows_sdk}/Program Files/Windows Kits/10/Lib/10.0.19041.0/um/x64" \
$@
'' + /bin/linker;
CC_x86_64_pc_windows_msvc = pkgs.writeShellScriptBin "cc" ''
clang-cl \
/I "${windows_sdk}/VC/Tools/Llvm/lib/clang/12.0.0/include" \
/I "${windows_sdk}/VC/Tools/MSVC/14.29.30133/include" \
/I "${windows_sdk}/Program Files/Windows Kits/10/Include/10.0.19041.0/ucrt" \
/I "${windows_sdk}/Program Files/Windows Kits/10/Include/10.0.19041.0/um" \
/I "${windows_sdk}/Program Files/Windows Kits/10/Include/10.0.19041.0/shared" \
$@
'' + /bin/cc;
X64_64_WINDOWS_NODE_API_LINK_SEARCH_PATH = x86_64_windows_node_import_lib;
};
}
);
}