-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
1198 lines (1103 loc) · 51.2 KB
/
Copy pathflake.nix
File metadata and controls
1198 lines (1103 loc) · 51.2 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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
description = "GloriousFlywheel — pooled build/cache/runner substrate and dashboard";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
nixpkgs-opentofu.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
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";
# Exact prompt-toon Chapel source boundary. This revision's Nix metadata
# advertises 2.7.0 while the compiler reports 2.8.0 pre-release; preserve
# both facts until TIN-2807 reconciles provenance and the Chapel 2.9 uplift.
chapel-nix.url = "github:Jesssullivan/chapel/ab552d88630823a961cca5db5f693b3511234e6c";
# Treefmt for consistent formatting
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, nixpkgs-opentofu, flake-utils, attic, nix2container, chapel-nix, treefmt-nix }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
tofuPkgs = import nixpkgs-opentofu {
inherit system;
};
opentofuTool = tofuPkgs.opentofu;
# The publisher uses nix2container as a build-time image-copy helper.
# Its own upstream Go tests are not part of the gf-reapi-cell image
# contract, and this helper has been OOM-killed on
# tinyland-nix-heavy before the image can publish. Keep its checks off
# and its Go compile serial; GF validates the resulting image and
# publish wrapper separately.
nix2containerPkgs = nix2container.inputs.nixpkgs.legacyPackages.${system};
nix2containerBuildPkgs = nix2containerPkgs.extend (_final: prev: {
buildGoModule = args:
prev.buildGoModule (args // prev.lib.optionalAttrs ((args.pname or "") == "nix2container") {
doCheck = false;
enableParallelBuilding = false;
env = (args.env or { }) // {
GOMAXPROCS = "2";
};
});
});
n2c = (import nix2container { pkgs = nix2containerBuildPkgs; }).nix2container;
# Treefmt configuration
treefmtEval = treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
programs = {
nixpkgs-fmt.enable = true;
prettier.enable = true;
shfmt.enable = true;
};
settings.formatter.nixpkgs-fmt.excludes = [ "runners/Dockerfile.nix" ];
};
# 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;
# Compatibility wrapper for Bazel entrypoints. Normal repo usage
# goes through `just bazel-build-cached` with BAZEL_REMOTE_CACHE set.
bazelWrapper = pkgs.writeShellScriptBin "bazel" ''
exec ${pkgs.bazelisk}/bin/bazelisk "$@"
'';
# Chapel is staged in the worker image as a pinned runtime closure,
# not as broad language-family eligibility. The first consumer proof
# is prompt-toon's no-cache ChapelCompile action under TIN-2949.
gfChapelUpstreamPackage = chapel-nix.packages.${system}.chapel-system-llvm;
gfChapelCompilerBuildProfile = "OPTIMIZE=0 DEBUG=0";
gfChapelBoundBuildPhase = buildPhase:
let
upstreamBuildCommand = "make -j$NIX_BUILD_CORES";
buildPhaseLines = pkgs.lib.splitString "\n" buildPhase;
matchingBuildCommands = builtins.filter
(line: line == upstreamBuildCommand)
buildPhaseLines;
in
assert builtins.length matchingBuildCommands == 1;
pkgs.lib.concatStringsSep "\n" (builtins.map
(line:
if line == upstreamBuildCommand then
"${line} ${gfChapelCompilerBuildProfile}"
else
line)
buildPhaseLines);
gfChapelBuildPhaseGuardCheck =
assert gfChapelBoundBuildPhase "make -j$NIX_BUILD_CORES" ==
"make -j$NIX_BUILD_CORES ${gfChapelCompilerBuildProfile}";
assert (builtins.tryEval (gfChapelBoundBuildPhase "echo no match")).success == false;
assert (builtins.tryEval (gfChapelBoundBuildPhase ''
make -j$NIX_BUILD_CORES
make -j$NIX_BUILD_CORES
'')).success == false;
true;
gfChapelPackage =
assert gfChapelBuildPhaseGuardCheck;
gfChapelUpstreamPackage.overrideAttrs (oldAttrs: {
buildPhase = gfChapelBoundBuildPhase oldAttrs.buildPhase;
});
gfChapelNixPackageVersion = gfChapelPackage.version or null;
gfChapelCompilerReportedVersion = "2.8.0 pre-release";
gfChapelSourceRevision = "ab552d88630823a961cca5db5f693b3511234e6c";
gfChapelClangRoot = builtins.dirOf (builtins.dirOf gfChapelPackage.CHPL_HOST_CC);
gfChapelClangResourceInclude = "-I${gfChapelClangRoot}/resource-root/include";
gfChapelCompilerIncludes =
"${gfChapelClangResourceInclude} ${gfChapelPackage.CHPL_CLANG_INCLUDES}";
gfChapelWrapped =
assert gfChapelNixPackageVersion == "2.7.0";
pkgs.runCommand "gf-chapel-prompt-toon-ab552d8"
{
nativeBuildInputs = [ pkgs.makeWrapper ];
passthru = {
packageVersion = gfChapelNixPackageVersion;
compilerReportedVersion = gfChapelCompilerReportedVersion;
sourceRevision = gfChapelSourceRevision;
};
} ''
mkdir -p "$out/bin" "$out/share/chapel" "$out/share/gloriousflywheel"
for item in ${gfChapelPackage}/share/chapel/*; do
ln -sf "$item" "$out/share/chapel/$(basename "$item")"
done
ln -sf ${gfChapelPackage}/lib "$out/share/chapel/lib"
# Reuse the pinned package's evaluated compiler paths. Pointing
# these at GF's root nixpkgs adds a second LLVM/Clang closure to
# every worker image and weakens the source-revision boundary.
makeWrapper ${gfChapelPackage}/bin/.chpl-wrapped "$out/bin/chpl" \
--set CHPL_HOME "$out/share/chapel" \
--set-default CHPL_LLVM "${gfChapelPackage.CHPL_LLVM}" \
--set-default CHPL_LLVM_CONFIG "${gfChapelPackage.CHPL_LLVM_CONFIG}" \
--set-default CHPL_HOST_COMPILER "${gfChapelPackage.CHPL_HOST_COMPILER}" \
--set-default CHPL_HOST_CC "${gfChapelPackage.CHPL_HOST_CC}" \
--set-default CHPL_HOST_CXX "${gfChapelPackage.CHPL_HOST_CXX}" \
--set-default CHPL_TARGET_CC "${gfChapelPackage.CHPL_TARGET_CC}" \
--set-default CHPL_TARGET_CXX "${gfChapelPackage.CHPL_TARGET_CXX}" \
--set-default CHPL_TARGET_CPU "${gfChapelPackage.CHPL_TARGET_CPU}" \
--set-default CHPL_CLANG_INCLUDES "${gfChapelCompilerIncludes}" \
--set-default CHPL_GMP none \
--set-default CHPL_RE2 bundled \
--set-default CHPL_UNWIND ${if pkgs.stdenv.isDarwin then "system" else "bundled"} \
--set-default CHPL_LAUNCHER none \
--set-default CHPL_COMM none \
--set-default CHPL_TASKS qthreads \
--set-default CHPL_TARGET_MEM jemalloc \
--set-default CHPL_HWLOC bundled \
--prefix PATH : '${pkgs.lib.makeBinPath [
pkgs.coreutils pkgs.gnumake pkgs.pkg-config pkgs.python3 pkgs.which
]}' \
--add-flags '${gfChapelCompilerIncludes}'
cat > "$out/share/gloriousflywheel/chapel-toolchain.json" <<'EOF'
${builtins.toJSON {
nix_package_version = gfChapelNixPackageVersion;
compiler_reported_version = gfChapelCompilerReportedVersion;
compiler_build_profile = gfChapelCompilerBuildProfile;
source = "github:Jesssullivan/chapel";
source_revision = gfChapelSourceRevision;
consumer_issue = "TIN-2949";
eligibility = "worker-image-candidate-not-broad-rbe";
}}
EOF
'';
# Exposed only as a remote Linux proof package. It executes the
# compiler and must never become a local Darwin iteration path.
gfChapelToolchainCheck = pkgs.runCommand "gf-chapel-toolchain-check"
{
nativeBuildInputs = [ gfChapelWrapped ];
} ''
version_line="$(chpl --version | head -n 1)"
case "$version_line" in
*"version ${gfChapelCompilerReportedVersion}"*) ;;
*)
echo "unexpected Chapel version: $version_line" >&2
exit 1
;;
esac
cat > smoke.chpl <<'EOF'
writeln("GF_CHAPEL_SMOKE");
EOF
chpl smoke.chpl -o smoke
test "$(./smoke)" = "GF_CHAPEL_SMOKE"
metadata=${gfChapelWrapped}/share/gloriousflywheel/chapel-toolchain.json
grep -F '"nix_package_version":"${gfChapelNixPackageVersion}"' "$metadata" >/dev/null
grep -F '"compiler_reported_version":"${gfChapelCompilerReportedVersion}"' "$metadata" >/dev/null
grep -F '"compiler_build_profile":"${gfChapelCompilerBuildProfile}"' "$metadata" >/dev/null
grep -F '"source_revision":"${gfChapelSourceRevision}"' "$metadata" >/dev/null
mkdir -p "$out"
printf '%s\n' "$version_line" > "$out/version.txt"
cp "$metadata" "$out/chapel-toolchain.json"
'';
# Development tools
devTools = with pkgs; [
# Kubernetes tooling
kubectl
kubernetes-helm
k9s
kustomize
# Infrastructure as Code
opentofuTool
# civo # REMOVED — Civo cluster decommissioned April 2026
# Attic client
atticClient
# Node.js / SvelteKit tooling
nodejs_22
nodePackages.pnpm
# Nix tooling
fh # FlakeHub CLI
nix-prefetch-git
nix-tree
nixpkgs-fmt
statix
deadnix
# Build tooling. Bazel is exposed as `bazel` for compatibility,
# but the product contract routes routine use through Just.
bazel-buildtools
bazelWrapper
# Container tooling
skopeo
dive
# Configuration language (typed tfvars generation)
dhall
dhall-json
# Development utilities
just
jq
yq-go
just
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
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
export NIX_SSL_CERT_FILE=$SSL_CERT_FILE
export NODE_EXTRA_CA_CERTS=$SSL_CERT_FILE
# Keep the proof-path dashboard build inside a predictable memory
# envelope on self-hosted runners.
export CI=1
export NODE_OPTIONS="--max_old_space_size=4096"
export npm_config_jobs=1
pnpm install --frozen-lockfile --child-concurrency=1 --network-concurrency=16
cd app
pnpm build
'';
installPhase = ''
mkdir -p $out
cp -r build/. $out/
cp package.json $out/
'';
};
gfReapiGoPackage =
{ pname
, subPackages
, mainProgram
, description
,
}:
pkgs.buildGo124Module {
inherit pname subPackages;
version = "0.1.0";
src = ./services/gf-reapi-cell;
vendorHash = "sha256-Rlejt70tckrzgYmRRamanDXfVFbN9MVRiOhW6WwCo9A=";
ldflags = [
"-s"
"-w"
];
meta = {
inherit description mainProgram;
};
};
gfReapiCell = gfReapiGoPackage {
pname = "gf-reapi-cell";
description = "Minimal GloriousFlywheel-owned REAPI proof cell";
mainProgram = "gf-reapi-cell";
subPackages = [
"cmd/gf-reapi-cell"
"cmd/gf-reapi-credhelper"
"cmd/gf-reapi-token-exchange"
"cmd/gf-reapi-worker"
];
};
gfReapiCredhelper = gfReapiGoPackage {
pname = "gf-reapi-credhelper";
description = "Bazel credential helper for gf-reapi-cell bearer tokens";
mainProgram = "gf-reapi-credhelper";
subPackages = [ "cmd/gf-reapi-credhelper" ];
};
gfReapiTokenExchange = gfReapiGoPackage {
pname = "gf-reapi-token-exchange";
description = "GitHub OIDC to gf-reapi-cell JWT/profile exchange helper";
mainProgram = "gf-reapi-token-exchange";
subPackages = [ "cmd/gf-reapi-token-exchange" ];
};
flywheelConsumerEnv = pkgs.writeShellScriptBin "flywheel-consumer-env" (builtins.readFile ./scripts/flywheel-consumer-env.sh);
flywheelGithubOidcProfile = pkgs.writeShellScriptBin "flywheel-github-oidc-profile" (builtins.readFile ./scripts/flywheel-github-oidc-profile.sh);
flywheelDoctor = pkgs.writeShellScriptBin "flywheel-doctor" (builtins.readFile ./scripts/flywheel-doctor.sh);
flywheelVerify = pkgs.writeShellScriptBin "flywheel-verify" ''
exec ${flywheelDoctor}/bin/flywheel-doctor --verify "$@"
'';
flywheelEnroll = pkgs.writeShellScriptBin "flywheel-enroll" ''
export PATH="${flywheelConsumerEnv}/bin:$PATH"
${builtins.readFile ./scripts/flywheel-enroll.sh}
'';
gloriousflywheelBazel = pkgs.writeShellScriptBin "gloriousflywheel-bazel" (builtins.readFile ./examples/bazel/gloriousflywheel-bazel.sh);
gloriousflywheelFrontdoorKit = pkgs.runCommand "gloriousflywheel-frontdoor-kit" { } ''
mkdir -p $out/bin $out/share/gloriousflywheel/frontdoor
mkdir -p $out/share/gloriousflywheel/frontdoor/tools/bazel/platforms
cp ${./scripts/flywheel-frontdoor-kit.sh} $out/bin/flywheel-frontdoor-kit
cp ${./examples/bazel/gloriousflywheel-bazel.sh} $out/bin/gloriousflywheel-bazel
cp ${./kit/frontdoor/README.md} $out/share/gloriousflywheel/frontdoor/README.md
cp ${./kit/frontdoor/justfile.flywheel} $out/share/gloriousflywheel/frontdoor/justfile.flywheel
cp ${./kit/frontdoor/.bazelrc.flywheel} $out/share/gloriousflywheel/frontdoor/.bazelrc.flywheel
cp ${./kit/frontdoor/manifest.json} $out/share/gloriousflywheel/frontdoor/manifest.json
cp ${./kit/frontdoor/tools/bazel/platforms/BUILD.bazel} $out/share/gloriousflywheel/frontdoor/tools/bazel/platforms/BUILD.bazel
chmod +x $out/bin/flywheel-frontdoor-kit $out/bin/gloriousflywheel-bazel
'';
gloriousflywheelFrontdoorTools = pkgs.buildEnv {
name = "gloriousflywheel-frontdoor-tools";
paths = [
flywheelDoctor
flywheelEnroll
flywheelConsumerEnv
flywheelGithubOidcProfile
flywheelVerify
gloriousflywheelFrontdoorKit
];
pathsToLink = [ "/bin" ];
};
gloriousflywheelProfileTools = pkgs.buildEnv {
name = "gloriousflywheel-profile-tools";
paths = [
gloriousflywheelFrontdoorTools
gfReapiCredhelper
gfReapiTokenExchange
];
pathsToLink = [ "/bin" ];
};
gfReapiCellWorkerCompatRoot = pkgs.runCommand "gf-reapi-cell-worker-compat-root" { } ''
mkdir -p $out/bin $out/lib64 $out/usr/bin
ln -s ${pkgs.bash}/bin/bash $out/bin/sh
ln -s ${pkgs.coreutils}/bin/env $out/usr/bin/env
${pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
ln -s ${pkgs.nix-ld}/libexec/nix-ld $out/lib64/ld-linux-x86-64.so.2
''}
'';
gfReapiReconcilerToolsKubernetesTargetVersion = "1.33";
# The root nixpkgs pin currently carries kubectl 1.31, which is two
# minors behind the live Kubernetes 1.33 control plane. The
# nix2container input's locked nixpkgs carries kubectl 1.34 and is
# already part of flake.lock, keeping the image reproducible while
# staying inside kubectl's supported +/-1 minor skew.
gfReapiReconcilerToolsKubectl =
assert pkgs.lib.assertMsg
(pkgs.lib.versionAtLeast nix2containerPkgs.kubectl.version "1.32"
&& pkgs.lib.versionOlder nix2containerPkgs.kubectl.version "1.35")
"gf-reapi-reconciler-tools kubectl must support Kubernetes 1.33 (+/-1 minor)";
nix2containerPkgs.kubectl;
gfReapiReconcilerToolsKubectlVersion = gfReapiReconcilerToolsKubectl.version;
gfReapiReconcilerToolsKubectlNixpkgsRevision = nix2container.inputs.nixpkgs.rev;
gfReapiReconcilerToolsShellRoot = pkgs.runCommand "gf-reapi-reconciler-tools-shell-root" { } ''
mkdir -p $out/bin
ln -s ${pkgs.bash}/bin/bash $out/bin/bash
ln -s ${pkgs.bash}/bin/bash $out/bin/sh
'';
# Keep this list exact: it is both the image root input and the
# machine-readable runtime contract exposed on the image package.
gfReapiReconcilerToolsRuntime = [
{
name = "bash";
package = gfReapiReconcilerToolsShellRoot;
}
{
name = "coreutils/date";
package = pkgs.coreutils;
}
{
name = "grep";
package = pkgs.gnugrep;
}
{
name = "diff";
package = pkgs.diffutils;
}
{
name = "yq";
package = pkgs.yq-go;
}
{
name = "oras";
package = pkgs.oras;
}
{
name = "cosign";
package = pkgs.cosign;
}
{
name = "kubectl";
package = gfReapiReconcilerToolsKubectl;
}
{
name = "ca-certs";
package = pkgs.cacert;
}
];
gfReapiReconcilerToolsRuntimeNames = builtins.map (tool: tool.name) gfReapiReconcilerToolsRuntime;
gfReapiReconcilerToolsRuntimePackages = builtins.map (tool: tool.package) gfReapiReconcilerToolsRuntime;
gfReapiReconcilerToolsRuntimeCsv = pkgs.lib.concatStringsSep "," gfReapiReconcilerToolsRuntimeNames;
gfReapiReconcilerToolsRoot = pkgs.buildEnv {
name = "gf-reapi-reconciler-tools-root";
paths = gfReapiReconcilerToolsRuntimePackages;
pathsToLink = [ "/bin" "/etc" ];
};
gfReapiReconcilerToolsConfig = {
Entrypoint = [ "/bin/bash" ];
Env = [
"PATH=/bin"
"SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt"
];
Labels = {
"org.opencontainers.image.source" = "https://github.com/tinyland-inc/GloriousFlywheel";
"org.opencontainers.image.description" = "GloriousFlywheel REAPI desired-state reconciler tools";
"dev.tinyland.gf-reapi-reconciler-tools.runtime-tools" = gfReapiReconcilerToolsRuntimeCsv;
"dev.tinyland.gf-reapi-reconciler-tools.kubectl-version" = gfReapiReconcilerToolsKubectlVersion;
"dev.tinyland.gf-reapi-reconciler-tools.kubernetes-target-version" = gfReapiReconcilerToolsKubernetesTargetVersion;
"dev.tinyland.gf-reapi-reconciler-tools.kubectl-nixpkgs-revision" = gfReapiReconcilerToolsKubectlNixpkgsRevision;
};
};
gfReapiReconcilerToolsImage =
assert pkgs.lib.assertMsg pkgs.stdenv.hostPlatform.isLinux
"gf-reapi-reconciler-tools must be built from a Linux package set";
(n2c.buildImage {
name = "gf-reapi-reconciler-tools";
tag = "main";
copyToRoot = gfReapiReconcilerToolsRoot;
config = gfReapiReconcilerToolsConfig;
meta = {
description = "First-party runtime tools for the GF REAPI desired-state reconciler";
platforms = pkgs.lib.platforms.linux;
};
}).overrideAttrs
(oldAttrs: {
passthru = (oldAttrs.passthru or { }) // {
kubectlVersion = gfReapiReconcilerToolsKubectlVersion;
kubernetesTargetVersion = gfReapiReconcilerToolsKubernetesTargetVersion;
kubectlNixpkgsRevision = gfReapiReconcilerToolsKubectlNixpkgsRevision;
runtimeTools = gfReapiReconcilerToolsRuntimeNames;
root = gfReapiReconcilerToolsRoot;
ociConfig = gfReapiReconcilerToolsConfig;
};
});
# A derivation can prove the root closure, but it cannot execute an
# unpacked container filesystem inside the Nix sandbox. Run this app
# from the first-party Linux runner to copy the exact nix2container
# output to OCI layout, unpack its layers, and execute the resulting
# rootfs. This catches rewrite, symlink, loader, and PATH defects that
# store-root execution cannot.
gfReapiReconcilerToolsOciRuntimeProof = pkgs.writeShellApplication {
name = "prove-gf-reapi-reconciler-tools-oci-runtime";
runtimeInputs = [
gfReapiReconcilerToolsImage.copyTo
pkgs.coreutils
pkgs.gnugrep
pkgs.jq
pkgs.umoci
];
text = ''
if [[ $(id -u) -ne 0 ]]; then
echo "ERROR: OCI rootfs proof requires the root-running tinyland-nix-heavy capability" >&2
exit 1
fi
work_dir="$(mktemp -d)"
trap 'rm -rf "$work_dir"' EXIT
copy-to "oci:$work_dir/oci:proof"
umoci unpack --image "$work_dir/oci:proof" "$work_dir/bundle"
rootfs="$work_dir/bundle/rootfs"
runtime_config="$work_dir/bundle/config.json"
test -x "$rootfs/bin/bash"
test -s "$rootfs/etc/ssl/certs/ca-bundle.crt"
jq -e '
.process.args == ["/bin/bash"]
and (.process.env | index("PATH=/bin")) != null
and (.process.env | index("SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt")) != null
' "$runtime_config" >/dev/null
mkdir -p "$rootfs/dev" "$rootfs/tmp"
chmod 1777 "$rootfs/tmp"
rm -f "$rootfs/dev/null" "$rootfs/dev/urandom"
mknod -m 666 "$rootfs/dev/null" c 1 3
mknod -m 666 "$rootfs/dev/urandom" c 1 9
cat > "$rootfs/tmp/probe.sh" <<'PROBE'
set -euo pipefail
test -n "$BASH_VERSION"
test "$(date -u -d @0 +%Y-%m-%dT%H:%M:%SZ)" = "1970-01-01T00:00:00Z"
printf "gf-reapi-reconciler-tools\n" | grep -Fx "gf-reapi-reconciler-tools" >/dev/null
printf "{\"ok\":true}\n" | yq -e ".ok == true" >/dev/null
printf "before\n" > /tmp/before
printf "after\n" > /tmp/after
rc=0
diff -u /tmp/before /tmp/after > /tmp/diff || rc=$?
test "$rc" -eq 1
grep -F -- "-before" /tmp/diff >/dev/null
grep -F -- "+after" /tmp/diff >/dev/null
oras version >/dev/null
cosign version >/dev/null
kubectl version --client=true --output=yaml > /tmp/kubectl-version.yaml
grep -F "gitVersion: v${gfReapiReconcilerToolsKubectlVersion}" /tmp/kubectl-version.yaml >/dev/null
grep -F -- "-----BEGIN CERTIFICATE-----" "$SSL_CERT_FILE" >/dev/null
PROBE
chmod 0555 "$rootfs/tmp/probe.sh"
env -i \
HOME=/tmp \
PATH=/bin \
SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt \
${pkgs.coreutils}/bin/chroot --userspec=65532:65532 "$rootfs" /bin/bash /tmp/probe.sh
printf 'oci_rootfs_execution=passed\n'
printf 'runtime_uid_gid=65532:65532\n'
printf 'runtime_tools=%s\n' '${gfReapiReconcilerToolsRuntimeCsv}'
printf 'kubectl=%s\n' '${gfReapiReconcilerToolsKubectlVersion}'
'';
};
# This check builds the actual nix2container image JSON and executes
# every required tool from the exact root rewritten into the image.
gfReapiReconcilerToolsImageCheck = pkgs.runCommand "gf-reapi-reconciler-tools-image-check"
{
nativeBuildInputs = [ pkgs.jq ];
} ''
set -euo pipefail
root=${gfReapiReconcilerToolsRoot}
image=${gfReapiReconcilerToolsImage}
cert_file="$root/etc/ssl/certs/ca-bundle.crt"
export HOME="$TMPDIR/home"
export SSL_CERT_FILE="$cert_file"
mkdir -p "$HOME"
for binary in bash sh date grep diff yq oras cosign kubectl; do
test -x "$root/bin/$binary"
done
test -s "$cert_file"
"$root/bin/bash" -ceu 'test -n "$BASH_VERSION"'
"$root/bin/sh" -ceu 'test -n "$BASH_VERSION"'
test "$("$root/bin/date" -u -d @0 +%Y-%m-%dT%H:%M:%SZ)" = "1970-01-01T00:00:00Z"
printf 'gf-reapi-reconciler-tools\n' | "$root/bin/grep" -Fx 'gf-reapi-reconciler-tools' >/dev/null
printf 'before\n' > "$TMPDIR/before"
printf 'after\n' > "$TMPDIR/after"
rc=0
"$root/bin/diff" -u "$TMPDIR/before" "$TMPDIR/after" > "$TMPDIR/diff" || rc=$?
test "$rc" -eq 1
"$root/bin/grep" -F -- '-before' "$TMPDIR/diff" >/dev/null
"$root/bin/grep" -F -- '+after' "$TMPDIR/diff" >/dev/null
printf '{"ok":true}\n' | "$root/bin/yq" -e '.ok == true' >/dev/null
"$root/bin/oras" version > "$TMPDIR/oras-version.txt"
"$root/bin/cosign" version > "$TMPDIR/cosign-version.txt"
"$root/bin/kubectl" version --client=true --output=yaml > "$TMPDIR/kubectl-version.yaml"
"$root/bin/grep" -F 'gitVersion: v${gfReapiReconcilerToolsKubectlVersion}' "$TMPDIR/kubectl-version.yaml" >/dev/null
"$root/bin/grep" -F -- '-----BEGIN CERTIFICATE-----' "$cert_file" >/dev/null
jq -e \
--arg root "$root" \
--arg arch "${nix2containerBuildPkgs.go.GOARCH}" \
--arg runtimeTools "${gfReapiReconcilerToolsRuntimeCsv}" \
--arg kubectlVersion "${gfReapiReconcilerToolsKubectlVersion}" \
--arg kubernetesTarget "${gfReapiReconcilerToolsKubernetesTargetVersion}" \
--arg nixpkgsRevision "${gfReapiReconcilerToolsKubectlNixpkgsRevision}" \
'
.version == 1
and .arch == $arch
and (.layers | length) > 0
and .["image-config"].Entrypoint == ["/bin/bash"]
and (.["image-config"].Env | index("PATH=/bin")) != null
and (.["image-config"].Env | index("SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt")) != null
and .["image-config"].Labels["dev.tinyland.gf-reapi-reconciler-tools.runtime-tools"] == $runtimeTools
and .["image-config"].Labels["dev.tinyland.gf-reapi-reconciler-tools.kubectl-version"] == $kubectlVersion
and .["image-config"].Labels["dev.tinyland.gf-reapi-reconciler-tools.kubernetes-target-version"] == $kubernetesTarget
and .["image-config"].Labels["dev.tinyland.gf-reapi-reconciler-tools.kubectl-nixpkgs-revision"] == $nixpkgsRevision
and any(.layers[].paths[]?;
.path == $root
and .options.rewrite.regex == ("^" + $root)
and .options.rewrite.repl == "")
' "$image" >/dev/null
mkdir -p "$out"
cp "$image" "$out/image.json"
cat > "$out/runtime-evidence.txt" <<EOF
image_arch=${nix2containerBuildPkgs.go.GOARCH}
image_root=$root
runtime_tools=${gfReapiReconcilerToolsRuntimeCsv}
bash=${pkgs.bash.version}
coreutils=${pkgs.coreutils.version}
grep=${pkgs.gnugrep.version}
diff=${pkgs.diffutils.version}
yq=${pkgs.yq-go.version}
oras=${pkgs.oras.version}
cosign=${pkgs.cosign.version}
kubectl=${gfReapiReconcilerToolsKubectlVersion}
kubernetes_target=${gfReapiReconcilerToolsKubernetesTargetVersion}
ca_certs=${pkgs.cacert.version}
store_root_execution=passed
oci_config_and_root_rewrite=passed
EOF
'';
mkAdapterNodeImage =
{ name
, app
, tag ? "latest"
, nodejs ? pkgs.nodejs_22
, appDir ? "/app"
, port ? 3000
, cmd ? [ "${appDir}/index.js" ]
, env ? [ ]
, labels ? { }
, extraRootPaths ? [ ]
, pathsToLink ? [ "/bin" "/etc" "/share" "/lib" ]
}:
let
portString = toString port;
in
n2c.buildImage {
inherit name tag;
copyToRoot = pkgs.buildEnv {
name = "${name}-root";
paths = [
nodejs
pkgs.cacert
pkgs.tzdata
] ++ extraRootPaths;
inherit pathsToLink;
};
layers = [
(n2c.buildLayer {
copyToRoot = pkgs.runCommand "${name}-app" { } ''
mkdir -p "$out${appDir}"
cp -r ${app}/* "$out${appDir}/"
'';
})
];
config = {
Entrypoint = [ "${nodejs}/bin/node" ];
Cmd = cmd;
WorkingDir = appDir;
Env = [
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
"TZ=UTC"
"PORT=${portString}"
"HOST=0.0.0.0"
"NODE_ENV=production"
] ++ env;
ExposedPorts = {
"${portString}/tcp" = { };
};
Labels = labels;
};
};
# OCI image for Runner Dashboard, using the same reusable adapter-node
# builder exported to nix-only spokes.
runnerDashboardImage = mkAdapterNodeImage {
name = "runner-dashboard";
app = runnerDashboard;
labels = {
"org.opencontainers.image.source" = "https://github.com/tinyland-inc/GloriousFlywheel";
"org.opencontainers.image.description" = "GloriousFlywheel Runner Dashboard";
};
};
# WebKit runtime for the cell's Playwright-WebKit lane. Sourced from the
# unstable input (tofuPkgs): the nixos-24.11 playwright-driver (1.50.1 /
# webkit-2123) is too old for consumers — tofuPkgs ships 1.59.1 /
# webkit-2272, which consumer repos pin @playwright/test against
# (EXACT pin; WebKit revisions are playwright-version-locked, unlike
# the CDP-stable chromium lane). Fonts are scoped to WebKit via the
# derivation's own fontconfig_file wrapping — no global FONTCONFIG_FILE,
# so the proved fontless-chromium lane is byte-identical.
gfWebkitFontsConf = tofuPkgs.makeFontsConf {
fontDirectories = [
tofuPkgs.dejavu_fonts
tofuPkgs.liberation_ttf
];
};
gfWebkitBrowsers = tofuPkgs.playwright-driver.browsers.override {
withChromium = false;
withChromiumHeadlessShell = false;
withFirefox = false;
withFfmpeg = false;
fontconfig_file = gfWebkitFontsConf;
};
gfWebkitRevision = tofuPkgs.playwright-driver.passthru.browsersJSON.webkit.revision;
# The absolute store path, NOT a buildEnv /bin symlink: pw_run.sh
# resolves its sibling browser tree via `dirname $0`, which breaks
# through symlinks.
gfWebkitExecutable = "${gfWebkitBrowsers}/webkit-${gfWebkitRevision}/pw_run.sh";
# Launch shim, proved necessary by the first remote WebKit dispatch
# (darkmap run 27329374675): the image-global LD_LIBRARY_PATH points
# at the nixos-24.11 glibc and poisons the unstable-glibc binaries in
# the webkit closure the moment pw_run.sh's bash loads ("symbol
# lookup error: ... __nptl_change_stack_perm, version GLIBC_PRIVATE").
# Nix binaries resolve via embedded rpaths — the webkit subtree needs
# no LD_LIBRARY_PATH at all, so unset it HERE (scoped; proved
# chromium keeps the image runtime path). The shim
# itself is written against the 24.11 runtimeShell so it loads fine
# under the poisoned env, then execs the unstable tree clean. Generic
# worker actions do not inherit this image-global LD_LIBRARY_PATH;
# gf-reapi-cell strips it at the action environment boundary so
# consumer Nix closures resolve their own glibc/runtime libraries.
# Fonts ride the same scope: nixpkgs' fontconfig_file override only
# wraps chromium/firefox (a silent no-op for webkit), so
# FONTCONFIG_FILE is exported here instead — WebKit-only, chromium
# stays fontless.
gfWebkitLauncher = pkgs.writeShellScript "gf-webkit-launcher" ''
unset LD_LIBRARY_PATH
export FONTCONFIG_FILE=${gfWebkitFontsConf}
exec ${gfWebkitExecutable} "$@"
'';
# OCI image for the explicit RBE proof cell. This is not the default
# Bazel path and should not use the current RustFS service as CAS/AC.
gfReapiCellImage = n2c.buildImage {
name = "gf-reapi-cell";
tag = "latest";
copyToRoot = pkgs.buildEnv {
name = "gf-reapi-cell-root";
paths = [
gfReapiCell
gfReapiCellWorkerCompatRoot
gfChapelWrapped
gfWebkitBrowsers
pkgs.bash
pkgs.cacert
pkgs.chromium
pkgs.coreutils
pkgs.findutils
pkgs.fontconfig
pkgs.freetype
pkgs.gawk
pkgs.gnugrep
pkgs.gnused
pkgs.gnutar
pkgs.gzip
pkgs.nodejs_22
pkgs.python3
pkgs.stdenv.cc
pkgs.stdenv.cc.cc.lib
pkgs.tzdata
pkgs.which
pkgs.xorg.libX11
pkgs.xorg.libXcomposite
pkgs.xorg.libXdamage
pkgs.xorg.libXext
pkgs.xorg.libXfixes
pkgs.xorg.libXrandr
pkgs.xz
pkgs.zlib
pkgs.zstd
] ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [
pkgs.bubblewrap
];
pathsToLink = [ "/bin" "/etc" "/lib" "/share" "/usr" ]
++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [ "/lib64" ];
};
config = {
Entrypoint = [ "/bin/gf-reapi-cell" ];
Env = [
"PATH=/bin:/usr/bin"
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
"TZ=UTC"
"GF_REAPI_ADDR=:8980"
"GF_REAPI_HTTP_ADDR=:8080"
"GF_REAPI_STORE_ROOT=/var/lib/gf-reapi-cell"
"GF_RBE_PLATFORM=gloriousflywheel-rbe-linux-x86_64"
"GF_RBE_CHROMIUM_EXECUTABLE=/bin/chromium"
"GF_RBE_WEBKIT_EXECUTABLE=${gfWebkitLauncher}"
] ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [
"LD_LIBRARY_PATH=${pkgs.glibc}/lib:${pkgs.stdenv.cc.cc.lib}/lib:${pkgs.zlib}/lib"
"NIX_LD=${pkgs.glibc}/lib/ld-linux-x86-64.so.2"
"NIX_LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib:${pkgs.stdenv.cc.cc.lib}/lib64:${pkgs.zlib}/lib"
];
ExposedPorts = {
"8980/tcp" = { };
"8080/tcp" = { };
};
Labels = {
"org.opencontainers.image.source" = "https://github.com/tinyland-inc/GloriousFlywheel";
"org.opencontainers.image.description" = "GloriousFlywheel minimal REAPI proof cell";
};
};
};
# 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://github.com/tinyland-inc/GloriousFlywheel";
"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://github.com/tinyland-inc/GloriousFlywheel";
"org.opencontainers.image.description" = "Attic Nix Binary Cache Garbage Collector";
"org.opencontainers.image.licenses" = "Zlib";
};
};
};
in
{
lib = {
inherit mkAdapterNodeImage;
};
# Development shell with all required tools
devShells.default = pkgs.mkShell {
name = "gloriousflywheel-dev";
# Surface the GloriousFlywheel front-door tools (gloriousflywheel-bazel,
# flywheel-doctor/verify/enroll) on PATH in the default shell, not only
# in devShells.ci. This is the canonical, byte-identical wrapper source;
# consumers should reach it here (or via the flywheel-profile module /
# `nix run .#gloriousflywheel-bazel`) and never vendor a copy that drifts.
packages = devTools ++ [ gloriousflywheelFrontdoorTools ];
shellHook = ''
echo "GloriousFlywheel Development Environment"
echo "========================================"
echo ""
echo "Available tools:"
echo " kubectl, helm, k9s - Kubernetes management"
echo " tofu - Infrastructure as Code"
echo " # civo removed - Civo decommissioned April 2026"
echo " attic - Attic client"
echo " bazel - Compatibility wrapper for cache-backed Bazel"
echo ""
echo "Substrate checks:"
echo " just info - Show cache/substrate mode"
echo " just bazel-build-cached - Build through Bazel only with BAZEL_REMOTE_CACHE"
echo " just check - Run repo validation"
echo " just nix-build - Build runner-dashboard through Nix"
echo ""
if [ -n "''${BAZEL_REMOTE_CACHE:-}" ]; then
echo "Bazel substrate: shared-cache-backed (''${BAZEL_REMOTE_CACHE})"
else
echo "Bazel substrate: compatibility-local-only; set BAZEL_REMOTE_CACHE before Bazel dogfood."
fi
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.tinyland.dev";
};
# Lightweight CI shell for Bazel jobs (no attic/Rust builds)
devShells.ci = pkgs.mkShell {
name = "gloriousflywheel-ci";
packages = [
pkgs.bazel-buildtools
bazelWrapper
opentofuTool
pkgs.go_1_24