forked from TraceMachina/nativelink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
330 lines (301 loc) · 12.1 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
324
325
326
327
328
329
330
{
description = "nativelink";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-utils.url = "github:numtide/flake-utils";
git-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
nix2container = {
url = "github:nlewo/nix2container";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs = inputs @ {
self,
flake-parts,
crane,
rust-overlay,
nix2container,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = [
"x86_64-linux"
"x86_64-darwin"
"apps.aarch64-linux.native"
"aarch64-darwin"
];
imports = [
inputs.git-hooks.flakeModule
./local-remote-execution/flake-module.nix
];
perSystem = {
config,
pkgs,
system,
...
}: let
stable-rust-version = "1.79.0";
nightly-rust-version = "2024-05-10";
# TODO(aaronmondal): Make musl builds work on Darwin.
# See: https://github.com/TraceMachina/nativelink/issues/751
stable-rust =
if pkgs.stdenv.isDarwin
then pkgs.rust-bin.stable.${stable-rust-version}
else pkgs.pkgsMusl.rust-bin.stable.${stable-rust-version};
nightly-rust =
if pkgs.stdenv.isDarwin
then pkgs.rust-bin.nightly.${nightly-rust-version}
else pkgs.pkgsMusl.rust-bin.nightly.${nightly-rust-version};
# TODO(aaronmondal): Tools like rustdoc don't work with the `pkgsMusl`
# package set because of missing libgcc_s. Fix this upstream and use the
# `stable-rust` toolchain in the devShell as well.
# See: https://github.com/oxalica/rust-overlay/issues/161
stable-rust-native = pkgs.rust-bin.stable.${stable-rust-version};
maybeDarwinDeps = pkgs.lib.optionals pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.Security
pkgs.libiconv
];
llvmPackages = pkgs.llvmPackages_18;
customStdenv = import ./tools/llvmStdenv.nix {inherit pkgs llvmPackages;};
# TODO(aaronmondal): This doesn't work with rules_rust yet.
# Tracked in https://github.com/TraceMachina/nativelink/issues/477.
customClang = pkgs.callPackage ./tools/customClang.nix {
inherit pkgs;
stdenv = customStdenv;
};
craneLib =
if pkgs.stdenv.isDarwin
then (crane.mkLib pkgs).overrideToolchain stable-rust.default
else
(crane.mkLib pkgs).overrideToolchain (stable-rust.default.override {
targets = ["x86_64-unknown-linux-musl"];
});
src = pkgs.lib.cleanSourceWith {
src = craneLib.path ./.;
filter = path: type:
(builtins.match "^.*(data/SekienSkashita\.jpg|nativelink-config/README\.md)" path != null)
|| (craneLib.filterCargoSources path type);
};
commonArgs =
{
inherit src;
stdenv =
if pkgs.stdenv.isDarwin
then customStdenv
else pkgs.pkgsMusl.stdenv;
strictDeps = true;
buildInputs = [pkgs.cacert] ++ maybeDarwinDeps;
nativeBuildInputs = maybeDarwinDeps;
}
// pkgs.lib.optionalAttrs (!pkgs.stdenv.isDarwin) {
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
};
# Additional target for external dependencies to simplify caching.
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
nativelink = craneLib.buildPackage (commonArgs
// {
inherit cargoArtifacts;
});
nativelink-debug = craneLib.buildPackage (commonArgs
// {
inherit cargoArtifacts;
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static --cfg tokio_unstable";
CARGO_PROFILE = "smol";
cargoExtraArgs = "--features enable_tokio_console";
});
hooks = import ./tools/pre-commit-hooks.nix {inherit pkgs nightly-rust;};
publish-ghcr = import ./tools/publish-ghcr.nix {inherit pkgs;};
local-image-test = import ./tools/local-image-test.nix {inherit pkgs nativelink;};
nativelink-is-executable-test = import ./tools/nativelink-is-executable-test.nix {inherit pkgs nativelink;};
generate-toolchains = import ./tools/generate-toolchains.nix {inherit pkgs;};
native-cli = import ./native-cli/default.nix {inherit pkgs;};
docs = pkgs.callPackage ./tools/docs.nix {rust = stable-rust.default;};
inherit (nix2container.packages.${system}.nix2container) pullImage;
inherit (nix2container.packages.${system}.nix2container) buildImage;
nativelink-image = buildImage {
name = "nativelink";
copyToRoot = [
(pkgs.buildEnv {
name = "nativelink-buildEnv";
paths = [nativelink];
pathsToLink = ["/bin"];
})
];
config = {
Entrypoint = [(pkgs.lib.getExe' nativelink "nativelink")];
Labels = {
"org.opencontainers.image.description" = "An RBE compatible, high-performance cache and remote executor.";
"org.opencontainers.image.documentation" = "https://github.com/TraceMachina/nativelink";
"org.opencontainers.image.licenses" = "Apache-2.0";
"org.opencontainers.image.revision" = "${self.rev or self.dirtyRev or "dirty"}";
"org.opencontainers.image.source" = "https://github.com/TraceMachina/nativelink";
"org.opencontainers.image.title" = "NativeLink";
"org.opencontainers.image.vendor" = "Trace Machina, Inc.";
};
};
};
nativelink-worker-init = pkgs.callPackage ./tools/nativelink-worker-init.nix {inherit buildImage self nativelink-image;};
rbe-autogen = import ./local-remote-execution/rbe-autogen.nix {inherit pkgs nativelink buildImage llvmPackages;};
createWorker = import ./tools/create-worker.nix {inherit pkgs buildImage self;};
siso-chromium = buildImage {
name = "siso-chromium";
fromImage = pullImage {
imageName = "gcr.io/chops-public-images-prod/rbe/siso-chromium/linux";
imageDigest = "sha256:26de99218a1a8b527d4840490bcbf1690ee0b55c84316300b60776e6b3a03fe1";
sha256 = "sha256-v2wctuZStb6eexcmJdkxKcGHjRk2LuZwyJvi/BerMyw=";
tlsVerify = true;
arch = "amd64";
os = "linux";
};
};
lre-cc = import ./local-remote-execution/lre-cc.nix {inherit pkgs buildImage llvmPackages;};
toolchain-drake = buildImage {
name = "toolchain-drake";
# imageDigest and sha256 are generated by toolchain-drake.sh for non-reproducible builds.
fromImage = pullImage {
imageName = "localhost:5001/toolchain-drake";
imageDigest = ""; # DO NOT COMMIT DRAKE IMAGE_DIGEST VALUE
sha256 = ""; # DO NOT COMMIT DRAKE SHA256 VALUE
tlsVerify = false;
arch = "amd64";
os = "linux";
};
};
in rec {
_module.args.pkgs = let
nixpkgs-patched = (import self.inputs.nixpkgs {inherit system;}).applyPatches {
name = "nixpkgs-patched";
src = self.inputs.nixpkgs;
patches = [
./tools/nixpkgs_link_libunwind_and_libcxx.diff
./tools/nixpkgs_disable_ratehammering_pulumi_tests.diff
./tools/nixpkgs_trivy_0_52_2.diff
./tools/nixpkgs_playwright.diff
];
};
in
import nixpkgs-patched {
inherit system;
overlays = [(import rust-overlay)];
};
apps = {
default = {
type = "app";
program = "${nativelink}/bin/nativelink";
};
native = {
type = "app";
program = "${native-cli}/bin/native";
};
};
packages = rec {
inherit publish-ghcr local-image-test nativelink-is-executable-test nativelink nativelink-debug native-cli lre-cc nativelink-worker-init;
default = nativelink;
rbe-autogen-lre-cc = rbe-autogen lre-cc;
nativelink-worker-lre-cc = createWorker lre-cc;
lre-java = import ./local-remote-execution/lre-java.nix {inherit pkgs buildImage;};
rbe-autogen-lre-java = rbe-autogen lre-java;
nativelink-worker-lre-java = createWorker lre-java;
nativelink-worker-siso-chromium = createWorker siso-chromium;
nativelink-worker-toolchain-drake = createWorker toolchain-drake;
image = nativelink-image;
};
checks = {
# TODO(aaronmondal): Fix the tests.
# tests = craneLib.cargoNextest (commonArgs
# // {
# inherit cargoArtifacts;
# cargoNextestExtraArgs = "--all";
# partitions = 1;
# partitionType = "count";
# });
};
pre-commit.settings = {inherit hooks;};
local-remote-execution.settings = {
Env =
if pkgs.stdenv.isDarwin
then [] # Doesn't support Darwin yet.
else lre-cc.meta.Env;
prefix = "lre";
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = let
bazel = pkgs.writeShellScriptBin "bazel" ''
unset TMPDIR TMP
exec ${pkgs.bazelisk}/bin/bazelisk "$@"
'';
in
[
# Development tooling goes here.
bazel
stable-rust-native.default
pkgs.pre-commit
pkgs.awscli2
pkgs.skopeo
pkgs.dive
pkgs.cosign
pkgs.kubectl
pkgs.kubernetes-helm
pkgs.cilium-cli
pkgs.vale
pkgs.trivy
pkgs.docker-client
pkgs.kind
pkgs.tektoncd-cli
(pkgs.pulumi.withPackages (ps: [ps.pulumi-language-go]))
pkgs.go
pkgs.kustomize
pkgs.nodePackages.pnpm
# Additional tools from within our development environment.
local-image-test
generate-toolchains
customClang
native-cli
docs
]
++ pkgs.lib.optionals (!pkgs.stdenv.isDarwin) [
# The docs on Mac require a manual setup outside the flake.
pkgs.playwright-driver.browsers
]
++ maybeDarwinDeps;
shellHook =
''
# Generate the .pre-commit-config.yaml symlink when entering the
# development shell.
${config.pre-commit.installationScript}
# Generate lre.bazelrc which configures LRE toolchains when running
# in the nix environment.
${config.local-remote-execution.installationScript}
# The Bazel and Cargo builds in nix require a Clang toolchain.
# TODO(aaronmondal): The Bazel build currently uses the
# irreproducible host C++ toolchain. Provide
# this toolchain via nix for bitwise identical
# binaries across machines.
export CC=clang
''
+ pkgs.lib.optionalString (!pkgs.stdenv.isDarwin) ''
export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers}
export PLAYWRIGHT_NODEJS_PATH=${pkgs.nodePackages_latest.nodejs}
'';
};
};
}
// {
flakeModule = ./local-remote-execution/flake-module.nix;
};
}