-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
415 lines (361 loc) · 13.4 KB
/
flake.nix
File metadata and controls
415 lines (361 loc) · 13.4 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
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
{
description = "Attic Nix Binary Cache - Civo Kubernetes Deployment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
flake-utils.url = "github:numtide/flake-utils";
# Attic binary cache server
# Don't follow nixpkgs - Attic needs its own nixpkgs with compatible Rust/Nix versions
attic.url = "github:zhaofengli/attic";
# OCI image building without Docker daemon
# Don't follow nixpkgs - nix2container needs its own newer nixpkgs for Go 1.24
nix2container.url = "github:nlewo/nix2container";
# Treefmt for consistent formatting
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, attic, nix2container, treefmt-nix }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
n2c = nix2container.packages.${system}.nix2container;
# Treefmt configuration
treefmtEval = treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
programs = {
nixpkgs-fmt.enable = true;
prettier.enable = true;
shfmt.enable = true;
};
};
# Attic packages from upstream
atticServer = attic.packages.${system}.attic-server or attic.packages.${system}.default;
atticClient = attic.packages.${system}.attic or attic.packages.${system}.attic-client;
# Bazel wrapper that calls bazelisk (most users expect 'bazel' command)
bazelWrapper = pkgs.writeShellScriptBin "bazel" ''
exec ${pkgs.bazelisk}/bin/bazelisk "$@"
'';
# Development tools
devTools = with pkgs; [
# Kubernetes tooling
kubectl
kubernetes-helm
k9s
kustomize
# Infrastructure as Code
opentofu
civo
# Attic client
atticClient
# Node.js / SvelteKit tooling
nodejs_22
nodePackages.pnpm
# Nix tooling
nix-prefetch-git
nix-tree
nixpkgs-fmt
statix
deadnix
# Build tooling
bazel-buildtools
bazelisk
bazelWrapper # Provides 'bazel' command that wraps bazelisk
# Container tooling
skopeo
dive
# Configuration language (typed tfvars generation)
dhall
dhall-json
# Development utilities
jq
yq-go
direnv
nix-direnv
git
gnumake
# PostgreSQL client for debugging
postgresql
];
# Runner Dashboard: pnpm build wrapper
# Source includes workspace root (lockfile, config) + app directory
runnerDashboardSrc = pkgs.lib.cleanSourceWith {
src = ./.;
filter = path: type:
let
baseName = builtins.baseNameOf path;
relPath = pkgs.lib.removePrefix (toString ./.) path;
in
# Workspace root files
baseName == "package.json"
|| baseName == "pnpm-lock.yaml"
|| baseName == "pnpm-workspace.yaml"
|| baseName == ".npmrc"
# App directory
|| pkgs.lib.hasPrefix "/app" relPath
# Config directory (for prebuild script)
|| pkgs.lib.hasPrefix "/config" relPath;
};
runnerDashboard = pkgs.stdenv.mkDerivation {
pname = "runner-dashboard";
version = "0.1.0";
src = runnerDashboardSrc;
nativeBuildInputs = [ pkgs.nodejs_22 pkgs.nodePackages.pnpm ];
buildPhase = ''
export HOME=$TMPDIR
pnpm install --frozen-lockfile
cd app
pnpm build
'';
installPhase = ''
mkdir -p $out
cp -r app/build/* $out/
cp app/package.json $out/
'';
};
# OCI image for Runner Dashboard
runnerDashboardImage = n2c.buildImage {
name = "runner-dashboard";
tag = "latest";
copyToRoot = pkgs.buildEnv {
name = "runner-dashboard-root";
paths = [
pkgs.nodejs_22
pkgs.cacert
pkgs.tzdata
];
pathsToLink = [ "/bin" "/etc" "/share" "/lib" ];
};
# Copy the built app into /app
layers = [
(n2c.buildLayer {
copyToRoot = pkgs.runCommand "runner-dashboard-app" { } ''
mkdir -p $out/app
cp -r ${runnerDashboard}/* $out/app/
'';
})
];
config = {
Entrypoint = [ "${pkgs.nodejs_22}/bin/node" ];
Cmd = [ "/app/index.js" ];
WorkingDir = "/app";
Env = [
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
"TZ=UTC"
"PORT=3000"
"HOST=0.0.0.0"
"NODE_ENV=production"
];
ExposedPorts = {
"3000/tcp" = { };
};
Labels = {
"org.opencontainers.image.source" = "https://github.com/tinyland-inc/GloriousFlywheel";
"org.opencontainers.image.description" = "Runner Dashboard";
};
};
};
# OCI image for Attic server
atticServerImage = n2c.buildImage {
name = "attic-server";
tag = "latest";
# Use a minimal base image
copyToRoot = pkgs.buildEnv {
name = "attic-server-root";
paths = [
atticServer
pkgs.cacert
pkgs.tzdata
];
pathsToLink = [ "/bin" "/etc" "/share" ];
};
config = {
Entrypoint = [ "${atticServer}/bin/atticd" ];
Cmd = [ "--config" "/etc/attic/server.toml" "--mode" "api-server" ];
Env = [
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
"TZ=UTC"
];
ExposedPorts = {
"8080/tcp" = { };
};
Labels = {
"org.opencontainers.image.source" = "https://gitlab.com/tinyland/infra/attic-cache";
"org.opencontainers.image.description" = "Attic Nix Binary Cache Server";
"org.opencontainers.image.licenses" = "Zlib";
};
};
};
# OCI image for Attic garbage collector
atticGCImage = n2c.buildImage {
name = "attic-gc";
tag = "latest";
copyToRoot = pkgs.buildEnv {
name = "attic-gc-root";
paths = [
atticServer
pkgs.cacert
pkgs.tzdata
];
pathsToLink = [ "/bin" "/etc" "/share" ];
};
config = {
Entrypoint = [ "${atticServer}/bin/atticd" ];
Cmd = [ "--config" "/etc/attic/server.toml" "--mode" "garbage-collector" ];
Env = [
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
"TZ=UTC"
];
Labels = {
"org.opencontainers.image.source" = "https://gitlab.com/tinyland/infra/attic-cache";
"org.opencontainers.image.description" = "Attic Nix Binary Cache Garbage Collector";
"org.opencontainers.image.licenses" = "Zlib";
};
};
};
in
{
# Development shell with all required tools
devShells.default = pkgs.mkShell {
name = "attic-cache-dev";
packages = devTools;
shellHook = ''
echo "Attic Cache Development Environment"
echo "===================================="
echo ""
echo "Available tools:"
echo " kubectl, helm, k9s - Kubernetes management"
echo " tofu - Infrastructure as Code"
echo " civo - Civo CLI"
echo " attic - Attic client"
echo " bazelisk - Bazel launcher"
echo ""
echo "Common commands:"
echo " nix build .#container - Build Attic OCI image"
echo " nix build .#attic-client - Build Attic client"
echo " nix flake check - Run all checks"
echo " bazel build //... - Build all Bazel targets"
echo ""
# Set up direnv if available
if command -v direnv &> /dev/null; then
eval "$(direnv hook bash 2>/dev/null || direnv hook zsh 2>/dev/null || true)"
fi
# Configure kubectl context hint
if [ -n "$KUBECONFIG" ]; then
echo "KUBECONFIG: $KUBECONFIG"
fi
'';
# Environment variables
ATTIC_CACHE_URL = "https://nix-cache.fuzzy-dev.tinyland.dev";
};
# Lightweight CI shell for Bazel jobs (no attic/Rust builds)
devShells.ci = pkgs.mkShell {
name = "attic-cache-ci";
packages = with pkgs; [
bazel-buildtools
bazelisk
bazelWrapper
opentofu
kubectl
nodejs_22
nodePackages.pnpm
git
];
};
# Packages
packages = {
default = atticClient;
attic-server = atticServer;
attic-client = atticClient;
# OCI images
container = atticServerImage;
attic-server-image = atticServerImage;
attic-gc-image = atticGCImage;
# Combined tarball for manual deployment
container-tarball = pkgs.runCommand "attic-server-image.tar.gz" { } ''
${atticServerImage.copyToDockerDaemon}/bin/copy-to-docker-daemon | gzip > $out
'';
# Runner Dashboard
runner-dashboard = runnerDashboard;
runner-dashboard-image = runnerDashboardImage;
};
# Checks for CI validation
checks = {
# Formatting check
formatting = treefmtEval.config.build.check self;
# Nix linting
statix = pkgs.runCommand "statix-check" { } ''
${pkgs.statix}/bin/statix check ${self} && touch $out
'';
# Dead code detection
deadnix = pkgs.runCommand "deadnix-check" { } ''
${pkgs.deadnix}/bin/deadnix --fail ${self} && touch $out
'';
# Verify attic packages build
attic-client-check = atticClient;
attic-server-check = atticServer;
# Verify container image builds
container-check = atticServerImage;
};
# Formatter
formatter = treefmtEval.config.build.wrapper;
# Apps for easy execution
apps = {
default = {
type = "app";
program = "${atticClient}/bin/attic";
};
attic = {
type = "app";
program = "${atticClient}/bin/attic";
};
atticd = {
type = "app";
program = "${atticServer}/bin/atticd";
};
};
}
) // {
# System-independent outputs
overlays.default = _final: prev: {
# Add any custom overlays here
attic-server = attic.packages.${prev.system}.attic-server or attic.packages.${prev.system}.default;
attic-client = attic.packages.${prev.system}.attic or attic.packages.${prev.system}.attic-client;
};
# NixOS/nix-darwin modules (placeholder for future use)
nixosModules.default = { config, lib, ... }: {
options.services.attic-cache = {
enable = lib.mkEnableOption "Attic cache client configuration";
cacheUrl = lib.mkOption {
type = lib.types.str;
default = "https://nix-cache.fuzzy-dev.tinyland.dev/main";
description = "URL of the Attic cache";
};
publicKey = lib.mkOption {
type = lib.types.str;
default = "";
description = "Public key for the cache (will be populated after deployment)";
};
};
config = lib.mkIf config.services.attic-cache.enable {
nix.settings = {
substituters = [ config.services.attic-cache.cacheUrl ];
trusted-public-keys = lib.optional
(config.services.attic-cache.publicKey != "")
config.services.attic-cache.publicKey;
};
};
};
};
# Attic binary cache — configure in your nix.conf (via Home Manager or manually):
#
# extra-substituters = https://nix-cache.fuzzy-dev.tinyland.dev
# extra-trusted-public-keys = main:l/gpjG5GLg1Gczmn5K97n5iSIRcsaWerICzdXqiBYT8=
#
# To extract the public key from a deployed Attic instance:
# ./scripts/init-cache.sh -e https://your-attic-cache.example.com
}