forked from TraceMachina/nativelink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake-module.nix
More file actions
101 lines (93 loc) · 3.19 KB
/
flake-module.nix
File metadata and controls
101 lines (93 loc) · 3.19 KB
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
{
lib,
flake-parts-lib,
...
}: {
options.perSystem = flake-parts-lib.mkPerSystemOption (
{
config,
options,
pkgs,
...
}: let
namespace = "nativelink";
cfg = config.${namespace};
in {
options.${namespace} = {
enable = lib.mkOption {
type = lib.types.bool;
default = true;
};
installationScript = lib.mkOption {
type = lib.types.str;
default = "";
description = lib.mkDoc ''
A bash snippet that creates a nixos.bazelrc file in the repository.
'';
};
api-key = lib.mkOption {
type = lib.types.str;
description = lib.mdDoc ''
The API key to connect to the NativeLink Cloud.
You should only use read-only keys here to prevent cache-poisoning and
malicious artifact extractions.
Defaults to NativeLink's shared read-only api key.
'';
default = "065f02f53f26a12331d5cfd00a778fb243bfb4e857b8fcd4c99273edfb15deae";
};
endpoint = lib.mkOption {
type = lib.types.str;
description = lib.mdDoc ''
The NativeLink Cloud endpoint.
Defaults to NativeLink's shared cache.
'';
default = "grpcs://cas-tracemachina-shared.build-faster.nativelink.net";
};
prefix = lib.mkOption {
type = lib.types.str;
description = lib.mdDoc ''
An optional Bazel config prefix for the flags in `nativelink.bazelrc`.
If set, builds need to explicitly enable the nativelink config via
`--config=<prefix>`.
Defaults to an empty string, enabling the cache by default.
'';
default = "";
};
};
config.${namespace} = {
installationScript = let
bazelrcContent = lib.concatLines maybePrefixedConfig;
# These flags cause Bazel builds to connect to NativeLink's read-only cache.
#
# ```nix
# devShells.default = pkgs.mkShell {
# shellHook = ''
# # Generate the `lre.bazelrc` config file.
# ${config.nativelink.installationScript}
# '';
# };
# ```
defaultConfig = [
"--remote_cache=${cfg.endpoint}"
"--remote_header=x-nativelink-api-key=${cfg.api-key}"
"--remote_header=x-nativelink-project=nativelink-ci"
"--nogenerate_json_trace_profile"
"--remote_upload_local_results=false"
"--remote_cache_async"
];
# If the `nativelink.prefix` is set to a nonempty string,
# prefix the Bazel build commands with that string. This will disable
# connecting to the nativelink-cloud by default and require adding
# `--config=<prefix>` to Bazel invocations.
maybePrefixedConfig =
if (cfg.prefix == "")
then map (x: "build " + x) defaultConfig
else map (x: "build:" + cfg.prefix + " " + x) defaultConfig;
in
import ./tools/installation-script.nix {
inherit bazelrcContent namespace pkgs;
};
};
}
);
}