Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
4350 lines (4103 loc) · 226 KB
/
Copy pathflake.nix
File metadata and controls
4350 lines (4103 loc) · 226 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 = "Workstation configuration";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
home-manager = {
url = "github:nix-community/home-manager/release-26.05";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-darwin = {
url = "github:nix-darwin/nix-darwin/nix-darwin-26.05";
inputs.nixpkgs.follows = "nixpkgs";
};
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
# Pinned to a release tag. Unpinned, this input followed devenv `main` and
# once locked an unreleased 2.1.3 snapshot that printed nix log lines to
# stdout, breaking `use devenv` under direnv. Keep it on the same release
# as eternal-machinery's devenv.yaml `devenv` modules input and its
# hosted-CI devenv pin (bead eternal-machinery-njrvv.2).
devenv = {
url = "github:cachix/devenv/v2.4.0";
};
# Used ONLY by gamebox, for Sunshine: 25.11 ships Sunshine 2025.924,
# which lacks the KWin capture backend the headless-streaming design
# depends on. Everything else stays on the stable nixpkgs above.
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
# Used ONLY by overlays/cloudflared.nix, for the Go 1.27.3 toolchain the
# cloudflared security release needs. Locked separately from
# nixpkgs-unstable so bumping one never moves the other.
nixpkgs-cloudflared.url = "github:NixOS/nixpkgs/nixos-unstable";
honk = {
url = "github:johnnymo87/honk";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, home-manager, nix-darwin, disko, sops-nix, devenv, honk, ... }@inputs:
let
# cloudflared security release; see overlays/cloudflared.nix. Applied to
# every package set that provides cloudflared: pkgsFor (standalone
# home-manager on every host), the devbox NixOS system (the tunnel
# connector), and the darwin system.
cloudflaredOverlay = import ./overlays/cloudflared.nix {
inherit (inputs) nixpkgs-cloudflared;
};
# setproctitle's fork tests segfault on Darwin and block azure-cli, which
# is a HOME package (home.base.nix). Shared by the darwin system and the
# Mac's standalone home-manager so the two evaluate one package set.
setproctitleDarwinOverlay = import ./overlays/setproctitle-darwin.nix;
# Centralized pkgs definition to prevent drift
pkgsFor = system: import nixpkgs {
inherit system;
config.allowUnfree = true;
overlays = [ cloudflaredOverlay ];
};
devboxSystem = "aarch64-linux";
devboxPkgs = pkgsFor devboxSystem;
# Darwin (macOS) pkgs
darwinSystem = "aarch64-darwin";
darwinPkgs = pkgsFor darwinSystem;
# The package set the Mac's standalone home-manager evaluates against.
# It must equal the darwin system's pkgs (same nixpkgs, same allowUnfree,
# same overlays in the same order: the flake-level module below puts
# cloudflared first, then configuration.nix adds setproctitle). Home-manager
# used to be a nix-darwin module with useGlobalPkgs, which guaranteed that;
# standalone it has to be kept true by hand. Drift here does not break
# anything loudly -- it silently rebuilds, and silently changes the store
# path in every launchd plist, which re-bootstraps (restarts) those agents.
darwinHomePkgs = import nixpkgs {
system = darwinSystem;
config.allowUnfree = true;
overlays = [ cloudflaredOverlay setproctitleDarwinOverlay ];
};
# Self-packaged tools (updated via nix-update in CI)
localPkgsFor = system: let
p = pkgsFor system;
goose = p.callPackage ./pkgs/goose { };
goose-link = p.callPackage ./pkgs/goose-link { };
ro-shell = p.callPackage ./pkgs/ro-shell { };
cfp = p.callPackage ./pkgs/claude-failover-proxy { };
in {
ask-question = p.callPackage ./pkgs/ask-question { };
# Named `bazel-scope` rather than `bazel`: the DERIVATION provides bin/bazel
# (it has to shadow the real one on PATH), but a flake output called `bazel`
# would be a trap for anyone running `nix build .#bazel` expecting bazel.
bazel-scope = p.callPackage ./pkgs/bazel-scope { };
bb = p.callPackage ./pkgs/bb { };
pressure-sampler = p.callPackage ./pkgs/pressure-sampler { };
beads = p.callPackage ./pkgs/beads { };
beads-sync = p.callPackage ./pkgs/beads-sync {
beads = p.callPackage ./pkgs/beads { };
driftAlert = p.callPackage ./pkgs/opencode-drift-alert { };
};
claude-failover-proxy = cfp;
cfp-shaper = cfp.shaper;
# Seeds the PRIVATE cfp release asset into the store on macOS, where no
# GITHUB_TOKEN reaches the builder. Exposed as its own output so it can be
# run BEFORE a rebuild -- the whole point is that the rebuild it unblocks
# cannot build it first. See pkgs/cfp-prefetch-darwin/default.nix.
cfp-prefetch-darwin = p.callPackage ./pkgs/cfp-prefetch-darwin { };
# SYSTEM-only deploy on macOS: `sudo darwin-rebuild switch` (needs an
# Admin By Request window once local admin is gone). See
# pkgs/darwin-switch/default.nix.
darwin-switch = p.callPackage ./pkgs/darwin-switch {
cfp-prefetch-darwin = p.callPackage ./pkgs/cfp-prefetch-darwin { };
};
# USER-level deploy on macOS, no root: cfp seed, then standalone
# `home-manager switch`. `nix run .#home-switch` works before it is on
# PATH (the one-time migration needs exactly that). The home-manager CLI
# comes from the SAME flake input that builds the configuration, so the
# CLI and the activation script it drives cannot skew. See
# pkgs/home-switch/default.nix.
home-switch = p.callPackage ./pkgs/home-switch {
cfp-prefetch-darwin = p.callPackage ./pkgs/cfp-prefetch-darwin { };
home-manager = home-manager.packages.${system}.home-manager;
};
# Exposed so pull-workstation on cloudbox/devbox can run the exact
# home-manager CLI pinned by the pulled flake.lock (`nix run "$repo#home-manager"`)
# instead of fetching an unpinned branch tip from GitHub on every run.
home-manager = home-manager.packages.${system}.home-manager;
codex-lb-status = p.callPackage ./pkgs/codex-lb-status { };
# Server half of EM's sandboxed history shell; deployed by hosts/devbox/em-history-shell.nix.
em-history-shell = p.callPackage ./pkgs/em-history-shell { };
# DevCycle CLI. Provides BOTH `dvc` (CLI, on PATH via home.base.nix) and
# `dvc-mcp` (the local MCP server opencode-config.nix wires up), so the
# two can never drift to different @devcycle/cli versions.
dvc = p.callPackage ./pkgs/dvc { };
figma-mcp-server = p.callPackage ./pkgs/figma-mcp-server { };
mcp-remote = p.callPackage ./pkgs/mcp-remote { };
gclpr = p.callPackage ./pkgs/gclpr { };
git-work = p.callPackage ./pkgs/git-work { };
worktree-guard-hook = p.callPackage ./pkgs/worktree-guard-hook { };
inherit goose;
goose-roles = p.callPackage ./pkgs/goose-roles {
agentsDir = ./assets/opencode/agents;
inherit ro-shell goose;
astraProvider = (import ./users/dev/codex-lb-models.nix).provider;
astraModel = (import ./users/dev/agent-twin-models.nix).astra;
fableModel = (import ./users/dev/agent-twin-models.nix).fable;
};
goose-config-enforce = p.callPackage ./pkgs/goose-config-enforce { };
goose-tool-shell = p.callPackage ./pkgs/goose-tool-shell { };
goose-canary = p.callPackage ./pkgs/goose-canary { };
goose-link = p.callPackage ./pkgs/goose-link { };
goose-cutover = p.callPackage ./pkgs/goose-cutover {
inherit goose-link;
driftAlert = p.callPackage ./pkgs/opencode-drift-alert { };
};
goose-host-report = p.callPackage ./pkgs/goose-host-report {
inherit goose-link;
};
goose-sync-watch = p.callPackage ./pkgs/goose-sync-watch { };
gws = p.callPackage ./pkgs/gws { };
hm-deploy-gate-sh = p.callPackage ./pkgs/hm-deploy-gate-sh { };
hm-deploy-canary-sh = p.callPackage ./pkgs/hm-deploy-canary-sh { };
lgtm-gh = import ./pkgs/lgtm-gh { pkgs = p; };
lgtm-review = import ./pkgs/lgtm-review { pkgs = p; };
nvims = p.callPackage ./pkgs/nvims { };
oc-auto-attach = p.callPackage ./pkgs/oc-auto-attach { };
oc-context = p.callPackage ./pkgs/oc-context { };
agent-model-signature = p.callPackage ./pkgs/agent-model-signature { };
oc-attach-reap = p.callPackage ./pkgs/oc-attach-reap { };
oc-search = p.callPackage ./pkgs/oc-search { };
oc-cost = p.callPackage ./pkgs/oc-cost { };
oc-mcp-enable = p.callPackage ./pkgs/oc-mcp-enable { };
oc-scoped-shell = p.callPackage ./pkgs/oc-scoped-shell { };
oc-revive = p.callPackage ./pkgs/oc-revive { };
oc-session-list = p.callPackage ./pkgs/oc-session-list { };
oc-tags = p.callPackage ./pkgs/oc-tags { };
llm-ledger = p.callPackage ./pkgs/llm-ledger { };
worker-scorecard = p.callPackage ./pkgs/worker-scorecard { };
# The honk rev the probe tests is the honk this flake deploys.
goose-upgrade-probe = p.callPackage ./pkgs/goose-upgrade-probe { honkRev = honk.rev; };
oc-throwaway-serve = p.callPackage ./pkgs/oc-throwaway-serve { };
opencode-frontdoor = p.callPackage ./pkgs/opencode-frontdoor { };
# NOTE: `opencode-frontdoor-route-gate` is deliberately NOT exposed here.
# It needs the PINNED opencode, and that pin lives in
# `users/dev/home.base.nix` (edited in place by
# .github/workflows/update-opencode-patched.yml, so it must not be moved).
# Exposing a flake output would require a second copy of the pin here, which
# the updater would not bump — the gate would then silently validate a STALE
# binary while the pool ran the new one: green and wrong, at exactly the
# moment the gate exists for. The gate is instantiated in home.base.nix
# against the real pin; `pkgs/opencode-frontdoor/test.sh` runs the same
# check on demand.
opencode-launch = p.callPackage ./pkgs/opencode-launch { };
opencode-serve-auth-sh = p.callPackage ./pkgs/opencode-serve-auth-sh { };
reset-workspace = p.callPackage ./pkgs/reset-workspace { };
turn-cut-notice = p.callPackage ./pkgs/turn-cut-notice { };
inherit ro-shell;
self-compact-plugin = p.callPackage ./pkgs/self-compact-plugin { };
session-state-plugin = p.callPackage ./pkgs/session-state-plugin { };
slack-mcp-server = p.callPackage ./pkgs/slack-mcp-server { };
teamclaude = p.callPackage ./pkgs/teamclaude { };
} // nixpkgs.lib.optionalAttrs (system == devboxSystem || system == darwinSystem) {
terraform = p.callPackage ./pkgs/terraform { };
};
# macOS host facts
mac = import ./hosts/Y0FMQX93RR-2/vars.nix;
# Filter projects by platform tag.
# Projects without a `platforms` attr are included everywhere.
allProjects = import ./projects.nix;
projectsFor = platform: nixpkgs.lib.filterAttrs
(_: p: !(p ? platforms) || builtins.elem platform p.platforms)
allProjects;
# All systems we target
systems = [ devboxSystem darwinSystem ];
pluginSrc = ./assets/opencode/plugins;
# node_modules INCLUDING devDependencies, for the TypeScript test checks
# below. Deliberately a SECOND deps stage rather than a reuse of the one in
# pkgs/opencode-plugin-bundle: that one passes `--omit=dev` because a
# shipped bundle needs no test tooling, and vitest lives in
# devDependencies. Sharing a single stage would mean either shipping test
# tooling into every plugin bundle or having no vitest to run here.
#
# Built with `importNpmLock.buildNodeModules` (not buildNpmPackage +
# npmDepsHash) to match the convention pkgs/opencode-plugin-bundle
# documents at length: each dep is fetched by the lockfile's own SRI
# integrity, so there is NO output hash to maintain and a nixpkgs nodejs
# bump can at most trigger a rebuild, never a hash mismatch.
pluginTestNodeModules = devboxPkgs.importNpmLock.buildNodeModules {
package = devboxPkgs.lib.importJSON (pluginSrc + "/package.json");
packageLock = devboxPkgs.lib.importJSON (pluginSrc + "/package-lock.json");
nodejs = devboxPkgs.nodejs;
derivationArgs = {
pname = "opencode-plugin-node-modules-dev";
version = "0.1.0";
};
};
frontdoorSrc = ./pkgs/opencode-frontdoor;
# node_modules INCLUDING devDependencies, for the frontdoor vitest check.
#
# pkgs/opencode-frontdoor/default.nix builds the SHIPPED artifact with
# buildNpmPackage + a pinned npmDepsHash; this is a separate deps stage for
# the same reason the plugin one above is separate from the bundle's. It
# also uses importNpmLock rather than a second npmDepsHash on purpose: a
# hash is a thing to maintain and to get wrong, and the lockfile's own SRI
# integrity already pins every dep.
frontdoorTestNodeModules = devboxPkgs.importNpmLock.buildNodeModules {
package = devboxPkgs.lib.importJSON (frontdoorSrc + "/package.json");
packageLock = devboxPkgs.lib.importJSON (frontdoorSrc + "/package-lock.json");
nodejs = devboxPkgs.nodejs_22;
derivationArgs = {
pname = "opencode-frontdoor-node-modules-dev";
version = "1.0.0";
};
};
in {
# Expose local packages for nix-update and nix build.
# Filter out packages whose meta.platforms excludes the target system
# (e.g. a package restricted to aarch64 won't appear in packages.x86_64-linux).
packages = builtins.listToAttrs (map (system: {
name = system;
value = let
all = localPkgsFor system;
platform = (pkgsFor system).stdenv.hostPlatform;
in nixpkgs.lib.filterAttrs
(_: pkg: nixpkgs.lib.meta.availableOn platform pkg)
all;
}) systems);
# Build-level CI gate.
#
# `nix flake check` on its own is NOT a build gate for this repo. It
# *evaluates* `nixosConfigurations` (drv level only) and does not even
# evaluate `homeConfigurations` -- it just confirms the attrset exists. So a
# derivation that is fine at eval time but fails at BUILD time sails through
# CI green and only explodes later, on the user's machine, at `switch` time.
#
# That is not hypothetical. #211 added `source "${opencode-serve-auth-sh}"`
# to three `writeShellApplication`s; that builder runs shellcheck with
# findings treated as fatal, and shellcheck always emits SC1091 for a source
# target it cannot resolve -- which a /nix/store path never is at lint time.
# All three failed to build, taking `home-manager-generation` with them,
# while CI reported success on both legs. It went unnoticed for a day, so
# nothing from #211/#212 reached the box, which in turn silently invalidated
# an unrelated measurement that was about to be acted on. Fixed in #215.
#
# Listing the configurations here makes `nix flake check` actually realise
# them, locally and in CI, by the same command. Both NixOS hosts are
# aarch64-linux (devbox is ARM on Hetzner, cloudbox is ARM on GCP), so the
# ubuntu-24.04-arm leg builds all four. This is keyed per-system so the
# x86_64 leg never tries to realise an aarch64 attribute.
#
# Deliberately absent:
#
# The Mac's configurations (darwinConfigurations.<host>.system and
# homeConfigurations.<host>) -- BUILDING them needs a macOS builder,
# and the home one also contains claude-failover-proxy. Even forcing
# their full derivation graph here is out: devenv's aarch64-darwin
# package is import-from-derivation of a darwin-only drv, so plain
# EVALUATION of the home closure needs a darwin builder too. They are
# built by checks.${darwinSystem} further down, which `nix flake check`
# realises when it runs on the Mac. (Single attributes still evaluate
# fine on this leg -- see bazelrc-disk-cache-tests.)
#
# (nixos-cloudbox and nixos-devbox pull in `claude-failover-proxy` / `cfp-shaper`
# from a private repo; they are built in CI by save-before-private ordering:
# public checks are built and the Actions store cache is saved BEFORE any
# private asset enters the store. Checks with private closures are isolated
# via PRIVATE_CHECKS so private binaries are never saved into the public
# repository's Actions cache.)
checks.${devboxSystem} = {
home-dev = self.homeConfigurations.dev.activationPackage;
home-cloudbox = self.homeConfigurations.cloudbox.activationPackage;
nixos-devbox = self.nixosConfigurations.devbox.config.system.build.toplevel;
nixos-cloudbox = self.nixosConfigurations.cloudbox.config.system.build.toplevel;
# ---- pkgs/opencode-frontdoor vitest suite (bead workstation-5m47) ----
#
# WHY THIS EXISTS: 25 test files and 496 assertions covering the routing
# layer every consumer is required to go through -- the repo's largest
# untested surface -- ran NOWHERE. The suite was believed un-runnable as a
# nix check because it binds loopback sockets; that belief was wrong, and
# the counter-example was already in the tree (pkgs/opencode-frontdoor/
# route-gate.nix boots a real opencode serve on 127.0.0.1 inside the
# sandbox, and depends on the sandbox's private network namespace to make
# a FIXED port safe). Only the `npm ci` half was a real obstacle, and
# importNpmLock removes it.
#
# Two properties worth knowing before editing:
#
# - This lives under checks.${devboxSystem}, so it is evaluated for
# aarch64-linux only and darwin never sees it. The loopback tests
# lean on the Linux sandbox's private network namespace; if a darwin
# checks leg is ever added, do not assume this one travels.
# - It copies the whole ${self} (see below), so it REBUILDS on any
# change anywhere in the repo, and 25 socket-driven integration
# files now gate every PR. That is the deliberate trade for
# hermeticity, but it does promote any flakiness in this suite into
# a repo-wide blocker. If one turns out flaky, fix or delete it --
# do not skip it, which the skip census below refuses anyway.
frontdoor-vitest = devboxPkgs.runCommand "frontdoor-vitest-tests" {
nativeBuildInputs = [ devboxPkgs.nodejs_22 devboxPkgs.diffutils ];
} ''
# Copies the whole ${self}, not just the frontdoor directory, for the
# same reason plugin-vitest does: test/wire-text.test.ts:160 resolves
# `../../..` to the repo root to assert the operator runbook it points
# at exists. Measured: with only the package directory, that one case
# fails ENOENT while the other 495 pass.
cp -r --no-preserve=mode,ownership ${self} ./repo
cd ./repo/pkgs/opencode-frontdoor
# A symlink FARM, not a symlink to the store directory. vitest writes a
# results cache to node_modules/.vite, and with `ln -s` that resolves
# into the read-only store: EACCES, raised as an unhandled error that
# fails the run AFTER every test has already passed. `cp -rs` gives real
# (writable) directories whose leaves are symlinks into the store, so
# the cache write lands in the build dir. Version-independent, unlike
# pinning vitest's cacheDir flag.
cp -rs ${frontdoorTestNodeModules}/node_modules ./node_modules
# cp copies the SOURCE's mode, and store directories are r-x: without
# this the farm is as unwritable as the symlink was, and the EACCES
# comes back at the same place.
chmod -R u+w ./node_modules
export HOME="$TMPDIR/home"
mkdir -p "$HOME"
# Typecheck FIRST, and note it is not redundant with the package build.
# default.nix compiles tsconfig.build.json, which excludes test/ -- so
# the type-correctness of 25 test files was checked by nothing in CI
# either. `npm run typecheck` is tsconfig.json, which includes them.
node_modules/.bin/tsc --noEmit
node_modules/.bin/vitest run \
--reporter=default \
--reporter=json --outputFile.json="$TMPDIR/vitest.json"
# Same two assertions as plugin-vitest below, for the same reasons: a
# green runner is not evidence that anything ran. (1) nothing was
# skipped -- vitest exits 0 over a `describe.skip` and leaves the file
# in testResults, so a skip is invisible to both the exit code and the
# file-set check. (2) the set of files vitest EXECUTED equals the
# *.test.ts files on disk -- a set and not a count, because the failure
# being defended against is whole-file exclusion by the include
# pattern, which a count cannot see and which invites a reviewer to
# "fix" it by bumping the number.
node -e 'const fs=require("fs"),path=require("path");const j=JSON.parse(fs.readFileSync(process.argv[1],"utf8"));if(!(j.numTotalTests>0)){console.error("GATE FAILURE: vitest reported 0 tests.");process.exit(1)}if(j.numPendingTests>0||j.numTodoTests>0){console.error("GATE FAILURE: "+j.numPendingTests+" skipped and "+j.numTodoTests+" todo test(s). A skipped test is not a passing one; un-skip it or delete it.");process.exit(1)}console.log(j.testResults.map(function(r){return path.relative(process.cwd(),r.name)}).sort().join("\n"))' \
"$TMPDIR/vitest.json" > "$TMPDIR/ran.txt"
find test -name '*.test.ts' -type f | sort > "$TMPDIR/ondisk.txt"
if ! diff -u --label "on disk" --label "actually ran" "$TMPDIR/ondisk.txt" "$TMPDIR/ran.txt"; then
echo "" >&2
echo "GATE FAILURE: the *.test.ts files on disk are not the files vitest ran." >&2
echo " A '-' line is a file that EXISTS but was NOT RUN -- silently excluded" >&2
echo " by vitest's include pattern. That is the defect this check ends." >&2
echo " A '+' line is a file vitest ran that this check did not expect --" >&2
echo " most likely the on-disk glob above needs widening." >&2
exit 1
fi
touch $out
'';
# Phase 9.2 opacity guard. Bash-only, so it adds seconds to the ARM leg that
# already spends ~3 min realising the three configurations above.
#
# WHY THIS EXISTS: the guard was written in Phase 9.2 and then enforced
# NOWHERE -- no flake check, no CI step, no canary. It sat red on main from
# #217 (which added a devbox door, and with it two unmarked sites) until
# 2026-08-01 and nothing noticed. A guard nothing runs is documentation with
# a shebang.
frontdoor-opacity = devboxPkgs.runCommand "frontdoor-opacity-guard" {
nativeBuildInputs = [ devboxPkgs.bash ];
} ''
cd ${self}
bash users/dev/test-frontdoor-opacity.sh
bash users/dev/test-frontdoor-opacity-guard.sh
touch $out
'';
# Bans `printf|echo "$VAR" | grep -q PAT`, which `set -o pipefail` can
# invert into reporting a match as a miss -- and, for negative-sense
# assertions, into a silent false GREEN. #431 and #432 removed 57 of
# these, two of them in production shell embedded in .nix (one could
# `rm` a live nvim socket). This keeps number 58 from landing.
#
# The suite self-tests its own detector against planted fixtures before
# scanning, so a rotted regex fails loudly instead of reporting a
# reassuring "0 violations" over a repo full of them.
pipefail-inversion = devboxPkgs.runCommand "pipefail-inversion-guard" {
nativeBuildInputs = [ devboxPkgs.bash devboxPkgs.gnugrep devboxPkgs.gnused
devboxPkgs.coreutils devboxPkgs.findutils devboxPkgs.gawk ];
} ''
cd ${self}
bash users/dev/test-pipefail-inversion.sh 2>&1 | tee "$TMPDIR/pi.txt"
grep -q '^ALL PASS' "$TMPDIR/pi.txt" || {
echo "GATE FAILURE: pipefail-inversion guard did not reach ALL PASS." >&2
exit 1
}
touch $out
'';
# ---- pkgs/astra-probe -------------------------------------------------
#
# astra-probe gates every -astra reviewer/oracle dispatch, so its
# failure mode is a false GREEN: print "astra UP" at a broken codex-lb and
# the caller dispatches into an empty review it will read as "no findings".
# The first draft did exactly that -- `.accounts[]` iterates a JSON OBJECT
# as happily as an array, so a reshaped response printed UP. That is the
# regression this suite is here for, and most cases below are malformed or
# drifted payloads rather than happy paths.
#
# It runs the SHIPPED executable (ASTRA_PROBE_BIN below), not a copy of the
# jq logic -- a mirror suite could pass while the installed script kept the
# bug. The fixtures are throwaway loopback HTTP servers, so no subscription,
# network or live codex-lb is involved; that the probe honours CODEX_LB_URL
# is the only reason it is testable at all.
#
# The count is PINNED, following checks.oc-attach-reap: most assertions
# here describe REFUSALS (must not say UP), and a refusal test passes
# trivially if the probe stops classifying at all, so "OK" alone is close
# to meaningless.
astra-probe-tests = devboxPkgs.runCommand "astra-probe-tests" {
nativeBuildInputs = [ devboxPkgs.python3 devboxPkgs.gnugrep ];
ASTRA_PROBE_BIN = "${devboxPkgs.callPackage ./pkgs/astra-probe { }}/bin/astra-probe";
} ''
cd ${self}
python3 pkgs/astra-probe/test_astra_probe.py 2>&1 | tee "$TMPDIR/astra.txt"
grep -q '^OK' "$TMPDIR/astra.txt" || {
echo "GATE FAILURE: astra-probe suite did not pass." >&2
exit 1
}
grep -q '^Ran 19 tests' "$TMPDIR/astra.txt" || {
echo "GATE FAILURE: expected 19 tests; a suite that stops asserting still prints OK." >&2
exit 1
}
touch $out
'';
# ---- pkgs/codex-lb-status (bead workstation-dmkv) ---------------------
#
# Runs the SHIPPED binary against throwaway loopback fixtures (via
# CODEX_LB_PORT); no live codex-lb or subscription involved. Count pinned
# like astra-probe: several cases assert absence (no `null`, no crash), and
# those pass trivially if the suite stops running them.
codex-lb-status-tests = devboxPkgs.runCommand "codex-lb-status-tests" {
nativeBuildInputs = [ devboxPkgs.python3 devboxPkgs.gnugrep ];
CODEX_LB_STATUS_BIN = "${devboxPkgs.callPackage ./pkgs/codex-lb-status { }}/bin/codex-lb-status";
} ''
cd ${self}
python3 pkgs/codex-lb-status/test_codex_lb_status.py 2>&1 | tee "$TMPDIR/out.txt"
grep -q '^OK' "$TMPDIR/out.txt" || {
echo "GATE FAILURE: codex-lb-status suite did not pass." >&2
exit 1
}
grep -q '^Ran 22 tests' "$TMPDIR/out.txt" || {
echo "GATE FAILURE: expected 22 tests; a suite that stops asserting still prints OK." >&2
exit 1
}
touch $out
'';
# ---- pkgs/aigateway-cache-miss-watch (bead workstation-ke9f.2) --------
aigateway-cache-miss-watch-tests = devboxPkgs.runCommand "aigateway-cache-miss-watch-tests" {
nativeBuildInputs = [ devboxPkgs.python3 devboxPkgs.gnugrep ];
ACM_WATCH_BIN = "${devboxPkgs.callPackage ./pkgs/aigateway-cache-miss-watch { }}/bin/aigateway-cache-miss-watch";
} ''
cd ${self}
python3 pkgs/aigateway-cache-miss-watch/test_aigateway_cache_miss_watch.py 2>&1 | tee "$TMPDIR/out.txt"
grep -q '^OK' "$TMPDIR/out.txt" || {
echo "GATE FAILURE: aigateway-cache-miss-watch suite did not pass." >&2
exit 1
}
grep -q '^Ran 11 tests' "$TMPDIR/out.txt" || {
echo "GATE FAILURE: expected 11 tests; a suite that stops asserting still prints OK." >&2
exit 1
}
touch $out
'';
# ---- pkgs/oc-attach-reap (bead workstation-o5s1.14) ------------------
#
# This tool SENDS SIGTERM, so its suite is about the ways it could kill
# the wrong processes rather than about the happy path: a stale or
# unreadable oracle, a TUI on another door, a TUI a human is typing in,
# and a process whose age cannot be established. Each of those makes a
# live TUI look orphaned.
#
# The test COUNT is pinned. Most of these assertions describe REFUSALS,
# and a refusal test passes trivially if the tool stops doing anything at
# all, so "OK" on its own is close to meaningless here.
oc-attach-reap = devboxPkgs.runCommand "oc-attach-reap-tests" {
nativeBuildInputs = [ devboxPkgs.python3 devboxPkgs.bash devboxPkgs.gnugrep ];
} ''
cd ${self}
# Full path on purpose: users/dev/test-unwired-tests.sh looks for the
# repo-relative path here, so `cd` into the directory plus a bare
# filename reads to it as "nothing executes this file". The suite puts
# its own directory on sys.path, so running from the root works.
python3 pkgs/oc-attach-reap/test_oc_attach_reap.py 2>&1 | tee "$TMPDIR/reap.txt"
grep -q '^OK' "$TMPDIR/reap.txt" || {
echo "GATE FAILURE: oc-attach-reap suite did not pass." >&2
exit 1
}
grep -q '^Ran 18 tests' "$TMPDIR/reap.txt" || {
echo "GATE FAILURE: expected 18 tests; a suite that stops asserting still prints OK." >&2
exit 1
}
touch $out
'';
# ---- pkgs/opencode-launch (bead workstation-o5s1.14) -----------------
#
# 111 assertions that ran NOWHERE. The file carried an
# unwired-test(workstation-3g4j) marker, but that bead is about
# reset-workspace/test.sh, whose two SIGPIPE assertions are genuinely
# sandbox-hostile. This suite has no such obstacle and was simply never
# wired; removing the marker and adding the check took one attempt.
#
# It matters now because the --no-attach gate added for
# workstation-o5s1.14 is asserted here. The helper assertions exercise a
# MIRROR of the production function, so on their own they could pass
# while the shipped launcher still attached unconditionally; the
# source-grep guards in the same file pin the real call site. Both halves
# are worthless unexecuted.
opencode-launch-tests = devboxPkgs.runCommand "opencode-launch-tests" {
# util-linux: setsid, for the oc-auto-attach spawn test (the production
# spawn_auto_attach runs against a fake to prove the env scrub).
nativeBuildInputs = with devboxPkgs; [ bash coreutils gnugrep gnused gawk jq util-linux ];
} ''
cd ${self}
bash pkgs/opencode-launch/test.sh 2>&1 | tee "$TMPDIR/ol.txt"
grep -q '^all opencode-launch helper tests passed' "$TMPDIR/ol.txt" || {
echo "GATE FAILURE: opencode-launch suite did not reach its final line." >&2
exit 1
}
# COUNT IS PINNED, following checks.oc-pool-attach. The banner alone is
# a vacuous-green path here: test.sh has two SKIP fall-throughs that
# still reach it -- jq absent, and default.nix not found beside the
# test. The second skips EVERY source-grep guard, which is precisely
# the set that pins the production call site.
got=$(grep -c '^PASS' "$TMPDIR/ol.txt")
[ "$got" = "160" ] || {
echo "GATE FAILURE: expected 160 PASS lines, got $got." >&2
echo "If you added assertions, bump this deliberately." >&2
exit 1
}
touch $out
'';
# ---- pkgs/pressure-sampler (bead workstation-o5s1.11) ----------------
#
# The sampler had NO tests and ran in no check. It hardcoded the serve
# cgroups at system.slice/system-opencode*.slice; the serves moved to a
# root-level opencode.slice, the old cgroup stayed behind EMPTY, and the
# glob went on matching it. Nothing errored. Every serve-slice row from
# the move to 2026-09-16 recorded zeros -- 20-25 MB against four serves
# actually holding 19.0 GB -- and no per-serve row was emitted at all.
#
# The failure mode is the reason for the suite's shape: a cgroup path that
# is real, readable and WRONG yields confident, plausible, useless numbers.
# A suite that only asserted "does not crash" would have stayed green
# throughout, so the central test plants BOTH the ghost and the live slice
# and pins that the live one wins.
#
# The count is PINNED, following checks.oc-auto-attach: "ALL PASS" alone
# cannot distinguish a passing suite from one that silently stopped
# asserting, which is the same class of bug as the one under test.
pressure-sampler-tests = devboxPkgs.runCommand "pressure-sampler-tests" {
nativeBuildInputs = [ devboxPkgs.bash devboxPkgs.coreutils devboxPkgs.gnugrep
devboxPkgs.gawk devboxPkgs.findutils ];
PRESSURE_SAMPLER_BIN = "${(localPkgsFor devboxSystem).pressure-sampler}/bin/pressure-sampler";
} ''
cd ${self}
bash pkgs/pressure-sampler/test-pressure-sampler.sh 2>&1 | tee "$TMPDIR/ps.txt"
grep -q '^ALL PASS (47 assertions)' "$TMPDIR/ps.txt" || {
echo "GATE FAILURE: pressure-sampler suite did not reach ALL PASS (47 assertions)." >&2
echo "If you added assertions, bump the pinned count here deliberately." >&2
exit 1
}
touch $out
'';
# TeamClaude pool-canary classification (bead claude-failover-proxy-w1w).
# Tests the SAME jq file the cloudbox canary and relogin reminder load
# (hosts/cloudbox/teamclaude-healthy.jq), against synthetic states and a
# replay of real samples from the 2026-09-07 blip and 2026-09-10 storm.
# Count pinned, following checks.pressure-sampler-tests.
teamclaude-healthy-tests = devboxPkgs.runCommand "teamclaude-healthy-tests" {
nativeBuildInputs = [ devboxPkgs.bash devboxPkgs.coreutils devboxPkgs.gnugrep
devboxPkgs.gawk devboxPkgs.jq ];
} ''
cd ${self}
bash hosts/cloudbox/test-teamclaude-healthy.sh 2>&1 | tee "$TMPDIR/th.txt"
grep -q '^ALL PASS (25 assertions)' "$TMPDIR/th.txt" || {
echo "GATE FAILURE: teamclaude-healthy suite did not reach ALL PASS (25 assertions)." >&2
echo "If you added assertions, bump the pinned count here deliberately." >&2
exit 1
}
touch $out
'';
# cf-route-monitor (devbox route-to-api.anthropic.com probe + episode
# alerting, bead workstation-dkts.2). Hermetic: curl/ip are stubs.
# Pinned assertion count; see users/dev/test-cf-route-monitor.sh.
cf-route-monitor-tests = devboxPkgs.runCommand "cf-route-monitor-tests" {
nativeBuildInputs = [ devboxPkgs.bash devboxPkgs.coreutils devboxPkgs.gnugrep
devboxPkgs.gawk devboxPkgs.jq devboxPkgs.gnused
devboxPkgs.findutils ];
} ''
cd ${self}
bash users/dev/test-cf-route-monitor.sh 2>&1 | tee "$TMPDIR/cfr.txt"
grep -q '^ALL PASS (93 assertions)' "$TMPDIR/cfr.txt" || {
echo "GATE FAILURE: cf-route-monitor suite did not reach ALL PASS (93 assertions)." >&2
echo "If you added assertions, bump the pinned count here deliberately." >&2
exit 1
}
touch $out
'';
# Failover reconciler (devbox em-ci-failover, bead eternal-machinery-0oycj.5).
# Pinned assertion count; see hosts/devbox/test-em-ci-failover.sh.
em-ci-failover-tests = devboxPkgs.runCommand "em-ci-failover-tests" {
nativeBuildInputs = [ devboxPkgs.bash devboxPkgs.coreutils devboxPkgs.gnugrep devboxPkgs.jq devboxPkgs.findutils ];
} ''
cd ${self}
bash hosts/devbox/test-em-ci-failover.sh 2>&1 | tee "$TMPDIR/f.txt"
grep -q '^ALL PASS (86 assertions)' "$TMPDIR/f.txt" || {
echo "GATE FAILURE: em-ci-failover suite did not reach ALL PASS (86 assertions)." >&2
exit 1
}
touch $out
'';
# em-ci monitor: GitHub API failure wording (a REST rate limit is not a
# token problem; eternal-machinery bead bq50q). Pinned assertion count;
# see hosts/devbox/test-em-ci-monitor.sh.
em-ci-monitor-tests = devboxPkgs.runCommand "em-ci-monitor-tests" {
nativeBuildInputs = [ devboxPkgs.bash devboxPkgs.coreutils devboxPkgs.gnugrep devboxPkgs.gnused devboxPkgs.jq ];
} ''
cd ${self}
bash hosts/devbox/test-em-ci-monitor.sh 2>&1 | tee "$TMPDIR/m.txt"
grep -q '^ALL PASS (17 assertions)' "$TMPDIR/m.txt" || {
echo "GATE FAILURE: em-ci-monitor suite did not reach ALL PASS (17 assertions)." >&2
exit 1
}
touch $out
'';
# slack_send, shared by the em-* monitors (#em-alerts, pigeon bead pigeon-4ogz.9).
# Pinned assertion count; see hosts/devbox/test-em-slack.sh.
em-slack-tests = devboxPkgs.runCommand "em-slack-tests" {
nativeBuildInputs = [ devboxPkgs.bash devboxPkgs.coreutils devboxPkgs.gnugrep
devboxPkgs.gawk devboxPkgs.jq ];
} ''
cd ${self}
bash hosts/devbox/test-em-slack.sh 2>&1 | tee "$TMPDIR/e.txt"
grep -q '^ALL PASS (24 assertions)' "$TMPDIR/e.txt" || {
echo "GATE FAILURE: em-slack suite did not reach ALL PASS (24 assertions)." >&2
echo "If you added assertions, bump the pinned count here deliberately." >&2
exit 1
}
touch $out
'';
# The suites above build each monitor by prepending em-slack.sh by hand. This
# checks that the BUILT units do the same (a monitor without slack_send would
# fail every alert, and ping /fail, only at runtime), and that none of them
# still loads a Telegram credential.
em-alerts-wiring = let
svc = n: self.nixosConfigurations.devbox.config.systemd.services.${n}.serviceConfig;
units = [ "em-ci-monitor" "em-ci-failover" "em-stack-monitor" ];
in devboxPkgs.runCommand "em-alerts-wiring" {
nativeBuildInputs = [ devboxPkgs.gnugrep ];
} (devboxPkgs.lib.concatMapStrings (n: ''
grep -q '^slack_send() {' ${(svc n).ExecStart} ||
{ echo "GATE FAILURE: ${n} has no slack_send (em-slack.sh not prepended)" >&2; exit 1; }
${devboxPkgs.lib.optionalString (devboxPkgs.lib.any (c: devboxPkgs.lib.hasPrefix "tg_" c) (svc n).LoadCredential)
"echo 'GATE FAILURE: ${n} still loads a Telegram credential' >&2; exit 1"}
${devboxPkgs.lib.optionalString (!(devboxPkgs.lib.any (c: devboxPkgs.lib.hasPrefix "slack_webhook:" c) (svc n).LoadCredential))
"echo 'GATE FAILURE: ${n} does not load slack_webhook' >&2; exit 1"}
'') units + "touch $out\n");
# EM stack monitor (devbox em-stack-monitor, bead eternal-machinery-qpmfc.103.1).
# Pinned assertion count; see hosts/devbox/test-em-stack-monitor.sh.
em-stack-monitor-tests = devboxPkgs.runCommand "em-stack-monitor-tests" {
nativeBuildInputs = [ devboxPkgs.bash devboxPkgs.coreutils devboxPkgs.gnugrep
devboxPkgs.gnused devboxPkgs.jq devboxPkgs.git ];
} ''
cd ${self}
bash hosts/devbox/test-em-stack-monitor.sh 2>&1 | tee "$TMPDIR/s.txt"
grep -q '^ALL PASS (203 assertions)' "$TMPDIR/s.txt" || {
echo "GATE FAILURE: em-stack-monitor suite did not reach ALL PASS (203 assertions)." >&2
echo "If you added assertions, bump the pinned count here deliberately." >&2
exit 1
}
touch $out
'';
# The BUILT monitor runs a real `#!/usr/bin/env bash` stack-health with a bare
# PATH, as a system unit does. The suite above fakes stack-health, so it cannot
# see that the monitor's own PATH lacks a tool stack-health needs.
em-stack-monitor-path = let
exec = self.nixosConfigurations.devbox.config.systemd.services.em-stack-monitor.serviceConfig.ExecStart;
cu = devboxPkgs.coreutils;
in devboxPkgs.runCommand "em-stack-monitor-path" { } ''
mkdir -p repo/bin state
printf '%s\n' '#!${cu}/bin/env bash' \
'for t in awk curl python3 pgrep ss jq; do command -v "$t" >/dev/null || echo " missing FAIL $t"; done' \
'echo "SUMMARY: OK"' > repo/bin/stack-health
printf '%s\n' '#!${cu}/bin/env bash' 'echo manual-live' > mode
printf '%s\n' '#!${cu}/bin/env bash' 'echo 000' > fetch
chmod +x repo/bin/stack-health mode fetch
out_txt=$(${cu}/bin/env -i PATH=${cu}/bin STATE_DIRECTORY=$PWD/state \
EM_STACK_MONITOR_DRY_RUN=1 EM_STACK_REPO=$PWD/repo \
EM_STACK_GATE_CMD=${cu}/bin/true EM_STACK_MODE_CMD=$PWD/mode \
EM_STACK_FETCH_CMD=$PWD/fetch ${exec} 2>&1 || true)
echo "$out_txt"
if ! echo "$out_txt" | ${devboxPkgs.gnugrep}/bin/grep -q 'raw keys:'; then
echo "GATE FAILURE: the built monitor did not finish a dry pass." >&2; exit 1
fi
if echo "$out_txt" | ${devboxPkgs.gnugrep}/bin/grep -q 'monitor:blind\|fail:missing'; then
echo "GATE FAILURE: the built monitor cannot run stack-health with its own PATH." >&2
exit 1
fi
touch $out
'';
# devbox pigeon-daemon Slack wiring (pigeon-4ogz.15, chat-transport phase 2).
# Must be in place BEFORE devbox flips to Slack (pigeon-4ogz.8): without the
# Slack owner id in the allowlist every bound coordinator refuses his replies,
# and without the webhook the daemon's direct-fallback alarm has nowhere to go.
# Eval half: the env and the sops declaration. Build half: the BUILT start
# script reads the webhook from the secret file and degrades when it is absent
# (set -euo pipefail would otherwise kill the daemon on a missing file). The
# webhook URL is a credential and must never appear in Environment=, which
# `systemctl show` prints to any local uid.
devbox-pigeon-slack-wiring = let
cfg = self.nixosConfigurations.devbox.config;
svc = cfg.systemd.services.pigeon-daemon.serviceConfig;
lib = devboxPkgs.lib;
envList = svc.Environment;
envVal = name: let
hits = builtins.filter (e: lib.hasPrefix "${name}=" e) envList;
in if hits == [ ] then null else lib.removePrefix "${name}=" (builtins.head hits);
allowed = lib.splitString "," (toString (envVal "PIGEON_PULL_ALLOWED_USER_IDS"));
secret = cfg.sops.secrets.pigeon_slack_alarm_webhook or null;
checks = {
"owner id env" = envVal "PIGEON_SLACK_OWNER_USER_ID" == "U0CKTGLSULR";
"allowlist has Slack owner" = builtins.elem "U0CKTGLSULR" allowed;
"allowlist has no Telegram id (pigeon-4ogz.13)" = !(builtins.elem "8248645256" allowed);
"no Telegram sops secret (pigeon-4ogz.13)" = !(cfg.sops.secrets ? telegram_bot_token || cfg.sops.secrets ? telegram_chat_id);
"webhook not in Environment" = !(builtins.any (e: lib.hasPrefix "PIGEON_SLACK_ALARM_WEBHOOK_URL=" e) envList);
"webhook sops secret declared" = secret != null;
"webhook secret owned by dev" = secret != null && secret.owner == "dev" && secret.mode == "0400";
};
failed = builtins.attrNames (lib.filterAttrs (_: ok: !ok) checks);
script = svc.ExecStart;
g = "${devboxPkgs.gnugrep}/bin/grep";
in
assert lib.assertMsg (failed == [ ]) "devbox-pigeon-slack-wiring failed: ${lib.concatStringsSep "; " failed}";
devboxPkgs.runCommand "devbox-pigeon-slack-wiring" { } ''
s=${script}
${g} -qF 'export PIGEON_SLACK_ALARM_WEBHOOK_URL="$(cat ${secret.path})"' "$s" || {
echo "GATE FAILURE: start script does not export the webhook from ${secret.path}" >&2; exit 1; }
${g} -qF '[ -s ${secret.path} ]' "$s" || {
echo "GATE FAILURE: start script does not guard a missing/empty webhook secret" >&2; exit 1; }
if ${g} -q 'hooks\.slack\.com' "$s"; then
echo "GATE FAILURE: a webhook URL is inlined in the start script" >&2; exit 1
fi
if ${g} -q 'TELEGRAM_' "$s"; then
echo "GATE FAILURE: the start script still exports Telegram env (pigeon-4ogz.13)" >&2; exit 1
fi
echo "devbox-pigeon-slack-wiring: ${toString (builtins.length (builtins.attrNames checks))} eval + 4 script checks passed" > $out
'';
# cloudbox pigeon-daemon Slack wiring (pigeon-4ogz.10, chat-transport
# phase 2), the cloudbox twin of devbox-pigeon-slack-wiring. Must be in
# place BEFORE cloudbox flips to Slack: without the Slack owner id in the
# allowlist every bound coordinator refuses his replies, and without the
# webhook the daemon's direct-fallback alarm has nowhere to go. Eval half:
# the env and the sops declaration. Build half: the BUILT start script
# reads the webhook from the secret file and degrades when it is absent
# (set -euo pipefail would otherwise kill the daemon on a missing file).
# The webhook URL is a credential and must never appear in Environment=,
# which `systemctl show` prints to any local uid.
cloudbox-pigeon-slack-wiring = let
cfg = self.nixosConfigurations.cloudbox.config;
svc = cfg.systemd.services.pigeon-daemon.serviceConfig;
lib = devboxPkgs.lib;
envList = svc.Environment;
envVal = name: let
hits = builtins.filter (e: lib.hasPrefix "${name}=" e) envList;
in if hits == [ ] then null else lib.removePrefix "${name}=" (builtins.head hits);
allowed = lib.splitString "," (toString (envVal "PIGEON_PULL_ALLOWED_USER_IDS"));
secret = cfg.sops.secrets.pigeon_slack_alarm_webhook or null;
checks = {
"owner id env" = envVal "PIGEON_SLACK_OWNER_USER_ID" == "U0CKLESTD45";
"allowlist has Slack owner" = builtins.elem "U0CKLESTD45" allowed;
"allowlist has no Telegram id (pigeon-4ogz.13)" = !(builtins.elem "8248645256" allowed);
"no Telegram sops secret (pigeon-4ogz.13)" = !(cfg.sops.secrets ? telegram_bot_token || cfg.sops.secrets ? telegram_chat_id);
"no pushes (NOTIFY_OWNER unset)" = !(builtins.any (e: lib.hasPrefix "PIGEON_SLACK_NOTIFY_OWNER=" e) envList);
"webhook not in Environment" = !(builtins.any (e: lib.hasPrefix "PIGEON_SLACK_ALARM_WEBHOOK_URL=" e) envList);
"webhook sops secret declared" = secret != null;
"webhook secret owned by dev" = secret != null && secret.owner == "dev" && secret.mode == "0400";
};
failed = builtins.attrNames (lib.filterAttrs (_: ok: !ok) checks);
script = svc.ExecStart;
g = "${devboxPkgs.gnugrep}/bin/grep";
in
assert lib.assertMsg (failed == [ ]) "cloudbox-pigeon-slack-wiring failed: ${lib.concatStringsSep "; " failed}";
devboxPkgs.runCommand "cloudbox-pigeon-slack-wiring" { } ''
s=${script}
${g} -qF 'export PIGEON_SLACK_ALARM_WEBHOOK_URL="$(cat ${secret.path})"' "$s" || {
echo "GATE FAILURE: start script does not export the webhook from ${secret.path}" >&2; exit 1; }
${g} -qF '[ -s ${secret.path} ]' "$s" || {
echo "GATE FAILURE: start script does not guard a missing/empty webhook secret" >&2; exit 1; }
if ${g} -q 'hooks\.slack\.com' "$s"; then
echo "GATE FAILURE: a webhook URL is inlined in the start script" >&2; exit 1
fi
if ${g} -q 'TELEGRAM_' "$s"; then
echo "GATE FAILURE: the start script still exports Telegram env (pigeon-4ogz.13)" >&2; exit 1
fi
echo "cloudbox-pigeon-slack-wiring: ${toString (builtins.length (builtins.attrNames checks))} eval + 4 script checks passed" > $out
'';
# pigeon-daemon survives a Node change from a system switch (pigeon-odrg).
# cloudbox's 26.05 switch moved the daemon to a new Node ABI and it
# crash-looped 54 times on ERR_DLOPEN_FAILED until better-sqlite3 was
# rebuilt by hand. Every machine's start script must run pigeon's
# scripts/ensure-native-modules.sh BEFORE it execs the daemon, under the
# daemon's own node, with the build tools the rebuild needs, and a failed
# rebuild must stop the systemd units restarting (exit 78) rather than
# recompile on every restart. Eval half: unit settings and the Mac's
# script string. Build half: line order in the built systemd scripts.
pigeon-native-check-wiring = let
lib = devboxPkgs.lib;
g = "${devboxPkgs.gnugrep}/bin/grep";
unit = host: self.nixosConfigurations.${host}.config.systemd.services.pigeon-daemon.serviceConfig;
prevents78 = host: let v = (unit host).RestartPreventExitStatus or null; in
v != null && builtins.elem "78" (lib.splitString " " (toString v));
hm = self.homeConfigurations.${mac.hostname}.config;
macAgent = hm.launchd.agents.pigeon-daemon.config;
macScript = lib.concatStringsSep "\n" macAgent.ProgramArguments;
macNodeDir = builtins.unsafeDiscardStringContext (builtins.head (lib.splitString ":" macAgent.EnvironmentVariables.PATH));
macBeforeExec = builtins.head (lib.splitString "exec " macScript);
checks = {
"devbox: exit 78 stops restarts" = prevents78 "devbox";
"cloudbox: exit 78 stops restarts" = prevents78 "cloudbox";
"macbook: check runs before the daemon's exec" =
lib.hasInfix "/Code/pigeon/scripts/ensure-native-modules.sh" macBeforeExec;
"macbook: --node-dir is the node first on the agent's PATH" =
lib.hasInfix "--node-dir ${macNodeDir}" macBeforeExec
&& lib.hasInfix "exec ${macNodeDir}/node" macScript;
"macbook: latched, alarmed, fails with 78" =
lib.hasInfix "--latch" macBeforeExec && lib.hasInfix "--alarm" macBeforeExec
&& lib.hasInfix "3) exit 78 ;;" macBeforeExec;
};
failed = builtins.attrNames (lib.filterAttrs (_: ok: !ok) checks);
scriptCheck = host: ''
s=${(unit host).ExecStart}
e=$(${g} -n 'scripts/ensure-native-modules.sh' "$s" | head -1 | cut -d: -f1)
x=$(${g} -n '^exec .*/bin/node ' "$s" | head -1 | cut -d: -f1)
[ -n "$e" ] && [ -n "$x" ] && [ "$e" -lt "$x" ] || {
echo "GATE FAILURE: ${host} start script does not run ensure-native-modules.sh before exec'ing the daemon" >&2; exit 1; }
for want in '--node-dir ${self.nixosConfigurations.${host}.pkgs.nodejs}/bin' \
'exec ${self.nixosConfigurations.${host}.pkgs.nodejs}/bin/node ' \
'--build-path ' '--latch ' '--alarm' '3) exit 78 ;;'; do
${g} -qF -- "$want" "$s" || { echo "GATE FAILURE: ${host} start script lacks '$want'" >&2; exit 1; }
done
w=$(${g} -n 'PIGEON_SLACK_ALARM_WEBHOOK_URL=' "$s" | head -1 | cut -d: -f1)
[ -n "$w" ] && [ "$w" -lt "$e" ] || {
echo "GATE FAILURE: ${host} runs the check before the alarm webhook is exported" >&2; exit 1; }
'';
in
assert lib.assertMsg (failed == [ ]) "pigeon-native-check-wiring failed: ${lib.concatStringsSep "; " failed}";
devboxPkgs.runCommand "pigeon-native-check-wiring" { } ''
${scriptCheck "devbox"}
${scriptCheck "cloudbox"}
echo "pigeon-native-check-wiring: ${toString (builtins.length (builtins.attrNames checks))} eval + 2 hosts x 8 script checks passed" > $out
'';
# cloudbox Grafana loopback exposure and security wiring (workstation-4si2.3).
# Guard cloudbox host firewall: enabled, SSH (TCP 22) + Mosh (UDP 60000-61000)
# only, loopback-only trustedInterfaces, no per-interface overrides, reverse-path
# filter on, iptables backend (matches lgtm-container-network.nix), and
# DOCKER-USER eth0 drop in extraCommands.
cloudbox-host-firewall = let
cfg = self.nixosConfigurations.cloudbox.config;
fw = cfg.networking.firewall;
lib = devboxPkgs.lib;
checks = {
"firewall enabled" = fw.enable == true;
"nftables disabled (iptables backend)" = cfg.networking.nftables.enable == false;
"trustedInterfaces is [ \"lo\" ] only" = fw.trustedInterfaces == [ "lo" ];
"per-interface firewall overrides empty" = fw.interfaces == { };
"reverse-path filter enabled" = fw.checkReversePath != false;
"allowedTCPPorts is [ 22 ] only" = fw.allowedTCPPorts == [ 22 ];
"allowedTCPPortRanges is empty" = fw.allowedTCPPortRanges == [ ];
"allowedUDPPorts is empty" = fw.allowedUDPPorts == [ ];
"allowedUDPPortRanges is Mosh 60000-61000" =
fw.allowedUDPPortRanges == [ { from = 60000; to = 61000; } ];
"DOCKER-USER eth0 drop present in extraCommands" =
lib.hasInfix "DOCKER-USER -i eth0 -j nixos-fw-docker-ext" fw.extraCommands;
"DOCKER-USER eth0 cleanup present in extraStopCommands" =
lib.hasInfix "DOCKER-USER -i eth0 -j nixos-fw-docker-ext" fw.extraStopCommands;
};
failed = lib.attrNames (lib.filterAttrs (_: ok: !ok) checks);
in
if failed != [ ] then
throw "cloudbox-host-firewall failed: ${lib.concatStringsSep ", " failed}"
else
devboxPkgs.runCommand "cloudbox-host-firewall" { } ''
touch "$out"
'';
# Loopback bind on 127.0.0.1:3000 is explicit and guarded because cloudbox
# has a public IP and no NixOS firewall. Eval half: module options, secrets,
# datasources, and env override immunity. Build half: greps the rendered
# grafana.ini that the service daemon script actually passes to -config.
cloudbox-grafana-exposure = let
cfg = self.nixosConfigurations.cloudbox.config;
lib = devboxPkgs.lib;
grafana = cfg.services.grafana;
settings = if builtins.isAttrs (grafana.settings or null) then grafana.settings else { };
server = if builtins.isAttrs (settings.server or null) then settings.server else { };
analytics = if builtins.isAttrs (settings.analytics or null) then settings.analytics else { };
news = if builtins.isAttrs (settings.news or null) then settings.news else { };
security = if builtins.isAttrs (settings.security or null) then settings.security else { };
users = if builtins.isAttrs (settings.users or null) then settings.users else { };
provisionSettings = grafana.provision.datasources.settings or null;
datasources =
if provisionSettings != null && provisionSettings ? datasources && builtins.isList provisionSettings.datasources
then provisionSettings.datasources
else [ ];
firstDs = if datasources != [ ] then builtins.head datasources else { };
firstDsJson = if builtins.isAttrs (firstDs.jsonData or null) then firstDs.jsonData else { };
sopsAdmin = cfg.sops.secrets.grafana_admin_password or null;
sopsSecretKey = cfg.sops.secrets.grafana_secret_key or null;
userGrafana = cfg.users.users.grafana or null;