-
Notifications
You must be signed in to change notification settings - Fork 10
/
flake.nix
162 lines (150 loc) · 5.37 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
{
description = "rules_ll development environment";
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";
git-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
nativelink = {
# Note: Keep this commit in sync with the LRE commit in `ll/init.bzl`.
url = "github:TraceMachina/nativelink/481226be52a84ad5a6b990cc48e9f97512d8ccd2";
# 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";
inputs.flake-parts.follows = "flake-parts";
inputs.git-hooks.follows = "git-hooks";
};
};
nixConfig = {
bash-prompt-prefix = "(rules_ll) ";
bash-prompt = ''\[\033]0;\u@\h:\w\007\]\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]'';
bash-prompt-suffix = " ";
};
outputs =
{ self
, flake-parts
, flake-utils
, nativelink
, nixpkgs
, git-hooks
, ...
} @ inputs:
flake-parts.lib.mkFlake { inherit inputs; }
{
systems = [
"x86_64-linux"
];
imports = [
inputs.git-hooks.flakeModule
inputs.nativelink.flakeModule.local-remote-execution
./flake-module.nix
];
perSystem =
{ config
, pkgs
, system
, lib
, ...
}:
{
_module.args.pkgs = import self.inputs.nixpkgs {
inherit system;
# CUDA support
config.allowUnfree = true;
config.cudaSupport = true;
};
local-remote-execution.settings = {
inherit (nativelink.packages.${system}.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
self.lib.defaultLlEnv {
inherit pkgs;
LL_CFLAGS = "-I${openssl.dev}/include";
LL_LDFLAGS = "-L${openssl.out}/lib";
};
packages = {
# TODO(aaronmondal): The nativelink devcluster mounts the current
# git repository into the kind nodes and derives the lre-cc worker
# tag from this target. Consider changing this upstream.
lre-cc = nativelink.packages.${system}.lre-cc;
ll = import ./devtools/ll.nix {
inherit pkgs;
native = inputs.nativelink.packages.${system}.native-cli;
};
};
devShells.default = pkgs.mkShell {
nativeBuildInputs =
let
bazel = pkgs.writeShellScriptBin "bazel" ''
unset TMPDIR TMP
exec ${pkgs.bazelisk}/bin/bazelisk "$@"
'';
in
[
bazel
self.packages.${system}.ll
pkgs.git
(pkgs.python3.withPackages (pylib: [
pylib.mkdocs-material
]))
pkgs.mkdocs
pkgs.vale
pkgs.go
# Cloud tooling
pkgs.cilium-cli
pkgs.kubectl
pkgs.pulumi
pkgs.skopeo
pkgs.tektoncd-cli
pkgs.fluxcd
pkgs.kustomize
];
shellHook = ''
# Generate the .pre-commit-config.yaml symlink when entering the
# development shell.
${config.pre-commit.installationScript}
# Generate .bazelrc.ll which contains Bazel configuration
# when rules_ll is run from a nix environment.
${config.rules_ll.installationScript}
# Generate .bazelrc.lre which configures the LRE toolchains.
${config.local-remote-execution.installationScript}
# Ensure that the ll command points to our ll binary.
[[ $(type -t ll) == "alias" ]] && unalias ll
# Ensure that the bazel command points to our custom wrapper.
[[ $(type -t bazel) == "alias" ]] && unalias bazel
# Prettier color output for the ls command.
alias ls='ls --color=auto'
'';
};
};
} // {
templates = {
default = {
path = "${./templates/default}";
description = "A basic rules_ll workspace";
};
};
flakeModule = ./flake-module.nix;
lib = { defaultLlEnv = import ./modules/defaultLlEnv.nix; };
};
}