-
Notifications
You must be signed in to change notification settings - Fork 2
/
flake.nix
88 lines (84 loc) · 2.92 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
{
description = "Shell for dev";
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
bazel-repo = {
url = "github:bazelbuild/bazel";
flake = false;
};
rules-scala = {
url = "github:bazelbuild/rules_scala";
flake = false;
};
};
outputs = { flake-utils, self, nixpkgs, bazel-repo, rules-scala, ... }:
let
system = flake-utils.lib.system.x86_64-linux;
pkgs = nixpkgs.legacyPackages.${system};
lib = nixpkgs.lib;
list = lib.lists;
bazel-wrapper = pkgs.writeShellScriptBin "bazel" ''
unset TMPDIR TMP
exec env --unset=USE_BAZEL_VERSION ${pkgs.bazelisk}/bin/bazelisk "$@"
'';
bazel-fhs = pkgs.buildFHSEnv {
name = "bazel";
runScript = "bazel";
targetPkgs = pkgs: [
bazel-wrapper
pkgs.zlib.dev
];
unsharePid = false;
unshareUser = false;
unshareIpc = false;
unshareNet = false;
unshareUts = false;
unshareCgroup = false;
};
bazel-watcher = pkgs.writeShellScriptBin "ibazel" ''
exec ${pkgs.bazel-watcher}/bin/ibazel -bazel_path=${bazel-fhs}/bin/bazel "$@"
'';
fmtall = pkgs.writeShellScriptBin "fmtall" ''
scalafmt src && buildifier -r src && buildifier -lint fix src/**/*
'';
proto-proj-root = ''''${PWD}/protos'';
bazel-protos = [
"src/main/java/com/google/devtools/build/lib/packages/metrics/package_load_metrics.proto"
"src/main/protobuf/action_cache.proto"
"src/main/protobuf/command_line.proto"
"src/main/protobuf/option_filters.proto"
"src/main/protobuf/failure_details.proto"
"src/main/protobuf/invocation_policy.proto"
"src/main/protobuf/analysis_v2.proto"
"src/main/protobuf/build.proto"
"src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto"
];
cps = lib.strings.concatLines
(lib.lists.map (path: ''cp ${bazel-repo}/${path} ${proto-proj-root}/src/main/protobuf/${path}'') bazel-protos);
gen-protobuf = pkgs.writeShellScriptBin "gen-mezel-protobuf" ''
rm -rf ${proto-proj-root}/src/main/protobuf
${pkgs.coreutils}/bin/mkdir -p ${proto-proj-root}/src/main/protobuf/src/main/protobuf
${pkgs.coreutils}/bin/mkdir -p ${proto-proj-root}/src/main/protobuf/src/main/java/com/google/devtools/build/lib/buildeventstream/proto
${pkgs.coreutils}/bin/mkdir -p ${proto-proj-root}/src/main/protobuf/src/main/java/com/google/devtools/build/lib/packages/metrics
cp \
${rules-scala}/src/protobuf/io/bazel/rules_scala/diagnostics.proto \
${proto-proj-root}/src/main/protobuf/src/main/protobuf/diagnostics.proto
${cps}
'';
in
{
devShells.${system}.default = pkgs.mkShell {
name = "mezel-dev";
nativeBuildInputs = [
bazel-fhs
pkgs.jdk21
pkgs.scalafmt
pkgs.sbt
bazel-watcher
fmtall
gen-protobuf
];
};
};
}