-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
219 lines (194 loc) · 7.34 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
{
description = "rules_mojo";
nixConfig = {
bash-prompt-prefix = "(rules_mojo) ";
bash-prompt = ''\[\033]0;\u@\h:\w\007\]\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]'';
bash-prompt-suffix = " ";
};
inputs = {
nixpkgs = {
url = "github:nixos/nixpkgs";
# This needs to follow the `nixpkgs` from nativelink so that the local LRE
# toolchains are in sync with the remote toolchains.
follows = "nativelink/nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
nativelink = {
# Note: Keep this commit in sync with the LRE commit in `MODULE.bazel`.
url = "github:TraceMachina/nativelink/2adda2475eed578d610a66b98f965922656061af";
# This repository provides the autogenerated LRE toolchains which are
# dependent on the nixpkgs version in the nativelink repository. To keep
# the local LRE toolchains aligned with remote LRE, we need to use the
# nixpkgs used by nativelink as the the "global" nixpkgs. We do this by
# setting `nixpkgs.follows = "nativelink/nixpkgs"` above.
inputs = {
flake-utils.follows = "flake-utils";
flake-parts.follows = "flake-parts";
git-hooks.follows = "pre-commit-hooks";
};
};
rules_ll = {
url = "github:eomii/rules_ll/a8a26cc78c43896b179caaa263857bd6c88a1da9";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
flake-parts.follows = "flake-parts";
git-hooks.follows = "pre-commit-hooks";
nativelink.follows = "nativelink";
};
};
nix2container = {
follows = "nativelink/nix2container";
};
};
outputs =
{ self
, nixpkgs
, pre-commit-hooks
, flake-parts
, nativelink
, rules_ll
, nix2container
, ...
} @ inputs:
flake-parts.lib.mkFlake { inherit inputs; }
{
systems = [
"x86_64-linux"
];
imports = [
inputs.nativelink.flakeModule
inputs.pre-commit-hooks.flakeModule
inputs.rules_ll.flakeModule
./flake-module.nix
];
perSystem =
{ config
, pkgs
, system
, lib
, ...
}:
let
inherit (inputs.nativelink.packages.${system}) native-cli lre-cc nativelink-debug;
tinfo6-bin = pkgs.callPackage ./tinfo6-bin.nix { };
ncurses6-bin = pkgs.callPackage ./ncurses6-bin.nix { };
lre-mojo-cluster = pkgs.callPackage ./local-remote-execution/lre-mojo-cluster.nix {
inherit native-cli;
};
inherit (nix2container.packages.${system}.nix2container) buildImage;
mojo = pkgs.callPackage ./mojo.nix {
inherit (pkgs.lib) makeBinPath makeLibraryPath;
inherit (pkgs.llvmPackages_18) clang;
ncurses = ncurses6-bin;
tinfo = tinfo6-bin;
};
lre-mojo = pkgs.callPackage ./local-remote-execution/lre-mojo.nix {
mojoEnv = self.lib.defaultMojoEnv {
inherit pkgs mojo;
};
inherit buildImage lre-cc;
};
lre-kill-the-mojo = pkgs.callPackage ./local-remote-execution/lre-kill-the-mojo.nix { };
createWorker = pkgs.callPackage ./local-remote-execution/create-worker.nix {
inherit buildImage self;
nativelink = nativelink-debug;
};
docs = pkgs.writeShellScriptBin "docs" ''
SRC_ROOT=$(git rev-parse --show-toplevel)
bazel build @rules_mojo//mojo:docs || exit
chmod 644 $SRC_ROOT/bazel-bin/mojo/*.md
cp $SRC_ROOT/bazel-bin/mojo/*.md $SRC_ROOT/docs/src/content/docs/reference/
cp $SRC_ROOT/bazel-bin/mojo/defs.md $SRC_ROOT/docs/src/content/docs/rules/
# Rerun the pre-commit hooks so that we do not need to stage everything twice.
git add docs
pre-commit run --all-files
git add docs
# Technically unnecessary, but we want to show users whether all tests pass.
printf '
**************************
RERUNNING PRE-COMMIT HOOKS
**************************
'
pre-commit run --all-files
'';
bazel = pkgs.writeShellScriptBin "bazel" ''
unset TMPDIR TMP
exec ${pkgs.bazelisk}/bin/bazelisk "$@"
'';
lre-bazel = pkgs.callPackage ./lre-bazel.nix { inherit bazel; };
in
{
_module.args.pkgs = import self.inputs.nixpkgs {
inherit system;
# CUDA support
# config.allowUnfree = true;
# config.cudaSupport = true;
};
local-remote-execution.settings = {
inherit (lre-cc.meta) Env;
};
pre-commit.settings = {
hooks = import ./pre-commit-hooks.nix { inherit pkgs; };
};
rules_ll.settings.llEnv =
let
openssl = pkgs.openssl.override { static = true; };
in
rules_ll.lib.defaultLlEnv {
inherit pkgs;
LL_CFLAGS = "-I${openssl.dev}/include";
LL_LDFLAGS = "-L${openssl.out}/lib";
};
rules_mojo.settings.mojoEnv = self.lib.defaultMojoEnv {
inherit pkgs mojo;
};
packages = {
inherit lre-mojo lre-cc mojo lre-mojo-cluster lre-kill-the-mojo bazel lre-bazel;
nativelink-worker-lre-mojo = createWorker lre-mojo;
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = [
bazel
docs
lre-bazel
lre-kill-the-mojo
lre-mojo-cluster
mojo
pkgs.kubectl
pkgs.python312
pkgs.tektoncd-cli
pkgs.kind
pkgs.vale
pkgs.bun
];
shellHook = ''
# Generate the .pre-commit-config.yaml symlink when entering the
# development shell.
${config.pre-commit.installationScript}
# Generate .bazelrc.ll which containes action-env
# configuration when rules_ll is run from a nix environment.
${config.rules_ll.installationScript}
# Generate .bazelrc.mojo which contains Bazel configuration
# when rules_mojo is run from a nix environment.
${config.rules_mojo.installationScript}
# Generate .bazelrc.lre which configures the LRE toolchains.
${config.local-remote-execution.installationScript}
# Ensure that the bazel command points to our custom wrapper.
[[ $(type -t bazel) == "alias" ]] && unalias bazel
'';
};
};
} // {
flakeModule = ./flake-module.nix;
lib = { defaultMojoEnv = import ./modules/defaultMojoEnv.nix; };
};
}