@smoothbricks/nx-plugin 0.4.14 → 0.4.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/README.md +20 -3
  2. package/dist/deploy-policy.d.ts +26 -0
  3. package/dist/deploy-policy.d.ts.map +1 -0
  4. package/dist/deploy-policy.js +36 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +160 -37
  7. package/dist/managed-assets.d.ts +3 -0
  8. package/dist/managed-assets.d.ts.map +1 -0
  9. package/dist/managed-assets.js +3 -0
  10. package/dist/managed-files/ci-workflow.d.ts +215 -0
  11. package/dist/managed-files/ci-workflow.d.ts.map +1 -0
  12. package/dist/managed-files/ci-workflow.js +1082 -0
  13. package/dist/managed-files/context.d.ts +51 -0
  14. package/dist/managed-files/context.d.ts.map +1 -0
  15. package/dist/managed-files/context.js +206 -0
  16. package/dist/managed-files/files.d.ts +53 -0
  17. package/dist/managed-files/files.d.ts.map +1 -0
  18. package/dist/managed-files/files.js +248 -0
  19. package/dist/managed-files/generator.d.ts +16 -0
  20. package/dist/managed-files/generator.d.ts.map +1 -0
  21. package/dist/managed-files/generator.js +41 -0
  22. package/dist/managed-files/github-runs-on.d.ts +19 -0
  23. package/dist/managed-files/github-runs-on.d.ts.map +1 -0
  24. package/dist/managed-files/github-runs-on.js +48 -0
  25. package/dist/managed-files/managed-content.d.ts +45 -0
  26. package/dist/managed-files/managed-content.d.ts.map +1 -0
  27. package/dist/managed-files/managed-content.js +102 -0
  28. package/dist/managed-files/managed-format.d.ts +37 -0
  29. package/dist/managed-files/managed-format.d.ts.map +1 -0
  30. package/dist/managed-files/managed-format.js +94 -0
  31. package/dist/managed-files/paths.d.ts +8 -0
  32. package/dist/managed-files/paths.d.ts.map +1 -0
  33. package/dist/managed-files/paths.js +46 -0
  34. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +5 -0
  35. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -0
  36. package/dist/managed-files/pr-preview-cleanup-workflow.js +38 -0
  37. package/dist/managed-files/private-npm-policy.d.ts +7 -0
  38. package/dist/managed-files/private-npm-policy.d.ts.map +1 -0
  39. package/dist/managed-files/private-npm-policy.js +51 -0
  40. package/dist/managed-files/publish-workflow.d.ts +150 -0
  41. package/dist/managed-files/publish-workflow.d.ts.map +1 -0
  42. package/dist/managed-files/publish-workflow.js +989 -0
  43. package/dist/managed-files/tree.d.ts +30 -0
  44. package/dist/managed-files/tree.d.ts.map +1 -0
  45. package/dist/managed-files/tree.js +91 -0
  46. package/dist/package-target-policy.d.ts +0 -1
  47. package/dist/package-target-policy.d.ts.map +1 -1
  48. package/dist/package-target-policy.js +50 -23
  49. package/dist/platform-targets.d.ts +5 -0
  50. package/dist/platform-targets.d.ts.map +1 -0
  51. package/dist/platform-targets.js +4 -0
  52. package/dist/typecheck-test-policy.d.ts +5 -9
  53. package/dist/typecheck-test-policy.d.ts.map +1 -1
  54. package/dist/typecheck-test-policy.js +69 -99
  55. package/dist/workspace-config-policy.d.ts +23 -3
  56. package/dist/workspace-config-policy.d.ts.map +1 -1
  57. package/dist/workspace-config-policy.js +35 -3
  58. package/dist/workspace-manifest.d.ts +291 -0
  59. package/dist/workspace-manifest.d.ts.map +1 -0
  60. package/dist/workspace-manifest.js +6 -0
  61. package/dist/workspace-package-policy.d.ts +13 -0
  62. package/dist/workspace-package-policy.d.ts.map +1 -0
  63. package/dist/workspace-package-policy.js +24 -0
  64. package/generators.json +5 -0
  65. package/managed/raw/envrc +20 -0
  66. package/managed/raw/git-format-staged.yml +82 -0
  67. package/managed/raw/gitattributes +8 -0
  68. package/managed/raw/tooling/devenv +83 -0
  69. package/managed/raw/tooling/direnv/devenv.smoo.nix +422 -0
  70. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +251 -0
  71. package/managed/raw/tooling/direnv/merge-newer-pins.sh +48 -0
  72. package/managed/raw/tooling/direnv/repo-path +34 -0
  73. package/managed/raw/tooling/direnv/secret-references.ts +636 -0
  74. package/managed/raw/tooling/direnv/setup-environment.ts +585 -0
  75. package/managed/raw/tooling/direnv/toolchain-stamp.ts +88 -0
  76. package/managed/raw/tooling/git-hooks/commit-msg.sh +9 -0
  77. package/managed/raw/tooling/git-hooks/post-commit.sh +71 -0
  78. package/managed/raw/tooling/git-hooks/pre-commit.sh +18 -0
  79. package/managed/raw/tooling/git-hooks/pre-push.sh +48 -0
  80. package/managed/raw/tsconfig.lib.json +28 -0
  81. package/managed/templates/github/actions/cache-nix-devenv/action.yml +45 -0
  82. package/managed/templates/github/actions/cache-node-modules/action.yml +17 -0
  83. package/managed/templates/github/actions/cache-nx/action.yml +21 -0
  84. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +19 -0
  85. package/managed/templates/github/actions/save-nix-devenv/action.yml +32 -0
  86. package/managed/templates/github/actions/setup-devenv/action.yml +241 -0
  87. package/managed/templates/github/workflows/managed-files.yml +127 -0
  88. package/package.json +89 -5
  89. package/src/bun-bootstrap.test.ts +0 -6
  90. package/src/deploy-policy.ts +40 -0
  91. package/src/index.test.ts +232 -9
  92. package/src/index.ts +187 -40
  93. package/src/managed-assets.ts +4 -0
  94. package/src/managed-files/ci-workflow.ts +1365 -0
  95. package/src/managed-files/context.ts +240 -0
  96. package/src/managed-files/files.ts +324 -0
  97. package/src/managed-files/generator.test.ts +151 -0
  98. package/src/managed-files/generator.ts +60 -0
  99. package/src/managed-files/github-runs-on.ts +51 -0
  100. package/src/managed-files/managed-content.test.ts +147 -0
  101. package/src/managed-files/managed-content.ts +121 -0
  102. package/src/managed-files/managed-format.ts +102 -0
  103. package/src/managed-files/paths.ts +44 -0
  104. package/src/managed-files/pr-preview-cleanup-workflow.ts +44 -0
  105. package/src/managed-files/private-npm-policy.ts +62 -0
  106. package/src/managed-files/publish-workflow.ts +1523 -0
  107. package/src/managed-files/schema.json +8 -0
  108. package/src/managed-files/tree-permissions.test.ts +109 -0
  109. package/src/managed-files/tree.test.ts +123 -0
  110. package/src/managed-files/tree.ts +118 -0
  111. package/src/package-target-policy.test.ts +4 -28
  112. package/src/package-target-policy.ts +55 -31
  113. package/src/platform-targets.ts +4 -0
  114. package/src/typecheck-test-policy.test.ts +28 -3
  115. package/src/typecheck-test-policy.ts +46 -121
  116. package/src/workspace-config-policy.test.ts +14 -2
  117. package/src/workspace-config-policy.ts +42 -3
  118. package/src/workspace-manifest.ts +327 -0
  119. package/src/workspace-package-policy.ts +32 -0
@@ -0,0 +1,422 @@
1
+ # Managed by `smoo monorepo`. Repo-owned configuration belongs in devenv.nix,
2
+ # which imports this module:
3
+ #
4
+ # imports = [./devenv.smoo.nix];
5
+ #
6
+ # This is the SmoothBricks shell contract — the wiring that pairs with the other
7
+ # managed files (tooling/direnv/repo-path, setup-environment.ts, the CI actions)
8
+ # and must stay identical across repositories. `enterShell` is `types.lines`, so
9
+ # this module's prologue and epilogue merge around whatever devenv.nix adds:
10
+ # mkBefore establishes the workspace root, PATH, and toolchain before any
11
+ # project step runs, and mkAfter restores the caller's directory last.
12
+ #
13
+ # Every explanation lives out here in Nix comments. Hook bodies are exported as
14
+ # shell text, so a comment inside one becomes part of an environment variable.
15
+ {
16
+ inputs,
17
+ lib,
18
+ pkgs,
19
+ ...
20
+ }: {
21
+ env = lib.mkMerge [
22
+ {
23
+ # Nx otherwise defaults to three workers. Scale to the cores available in each
24
+ # developer shell or CI runner; explicit --parallel flags still take precedence.
25
+ NX_PARALLEL = "100%";
26
+ }
27
+ # Playwright's downloaded Ubuntu browser has no runtime closure on NixOS
28
+ # (CI reached the executable, then failed loading libglib-2.0.so.0). Use
29
+ # the lock-pinned Nix browser and its libraries; smoo passes this executable
30
+ # to the child before Playwright imports. Darwin keeps its native browser path.
31
+ (lib.mkIf pkgs.stdenv.hostPlatform.isLinux {
32
+ PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH = lib.getExe pkgs.chromium;
33
+ })
34
+ ];
35
+ # sccache is deliberately absent from this shell. It used to export
36
+ # RUSTC_WRAPPER=sccache as a BARE NAME, which PATH then resolved per project —
37
+ # which is precisely how an unpatched binary from one profile came to serve
38
+ # clients from another. sccache now belongs to cowshed: `cowshed setup
39
+ # --sccache` builds packages/cowshed/nix/sccache, pins the result with a nix GC
40
+ # root, and supervises that exact store path. A repository shell has no
41
+ # business deciding which compiler cache a host runs.
42
+
43
+ # One toolchain for every repository and every workspace, pinned by devenv.lock
44
+ # rather than by a rust-toolchain file. devenv resolves the channel through
45
+ # rust-overlay, so a lock bump is the only thing that moves the compiler, and a
46
+ # CI runner building this same shell gets the same rustc a laptop has.
47
+ #
48
+ # Nightly because the fleet needs `-Z` features (`-Zbuild-std`,
49
+ # `panic=immediate-abort` for wasm artifacts) and there is no reason to keep a
50
+ # second toolchain alongside for them. `version = "latest"` reads "newest
51
+ # nightly the locked rust-overlay offers", not "whatever nightly exists today".
52
+ #
53
+ # `components` and fleet-wide `targets` belong to this module; repositories
54
+ # add only platform- or product-specific targets in devenv.nix. These list
55
+ # options merge, while `channel` and `version` are single-valued. A
56
+ # `rust-toolchain.toml` is NOT the
57
+ # mechanism here: nix cargo ignores it unless devenv is pointed at it with
58
+ # `languages.rust.toolchainFile`, so such a file is decoration that silently
59
+ # disagrees with the shell.
60
+ languages.rust = {
61
+ enable = true;
62
+ channel = "nightly";
63
+ version = "latest";
64
+ components = [
65
+ "rustc"
66
+ "cargo"
67
+ "clippy"
68
+ "rustfmt"
69
+ "rust-analyzer"
70
+ "rust-src"
71
+ ];
72
+ # Every repository builds WASM, so the shared shell always carries that std.
73
+ # Keeping it here prevents each repo from restating the same target.
74
+ # CI validates on Linux, so a macOS shell carries Linux's std and can
75
+ # type-check the arm CI compiles. rust-std alone reaches every crate whose
76
+ # dependency graph is pure Rust; a dependency that compiles C for the target
77
+ # — ring, openssl-sys, libgit2-sys, libz-sys — additionally needs a cross C
78
+ # compiler, which is 0.4 GiB and so lives in the opt-in `linux-cross` profile
79
+ # below rather than here, keeping it off every macOS shell and macOS runner.
80
+ #
81
+ # The reverse direction is not available at any price: type-checking an Apple
82
+ # target from Linux needs an Apple SDK for those same C-building
83
+ # dependencies, which is a licensing boundary rather than a missing package.
84
+ targets = [
85
+ "wasm32-unknown-unknown"
86
+ "x86_64-unknown-linux-gnu"
87
+ ];
88
+ };
89
+
90
+ # Opt-in Linux cross toolchain, activated by `devenv -P linux-cross` and driven
91
+ # by the root `check:linux` script. devenv 2.2.3 has first-class profiles, so
92
+ # this is one gated module in the shared file rather than a second config
93
+ # directory that would have to re-import and re-pin everything here.
94
+ #
95
+ # It is a profile and NOT a default package because pkgsCross.gnu64's cc
96
+ # closure is 0.4 GiB against a default shell closure of ~5.4 GiB — a 7% tax on
97
+ # every shell entry and every CI cache restore, to serve one command that a
98
+ # macOS laptop runs deliberately. Nothing on Darwin links a Linux object.
99
+ #
100
+ # Why a C compiler is needed at all, when rust-std above is already installed:
101
+ # ring, openssl-sys, libgit2-sys and libz-sys compile C for the target from
102
+ # their build scripts, and build scripts are compiled and run even under
103
+ # `cargo check`, so std alone stops at `ToolNotFound: failed to find tool
104
+ # "x86_64-linux-gnu-gcc"`. The `cc` crate probes triple-prefixed tool names,
105
+ # which is precisely what this wrapper's bin/ exports.
106
+ #
107
+ # Each tool path is derived from the wrapper's own `targetPrefix` instead of
108
+ # being written out, so a nixpkgs bump that renames the prefix carries these
109
+ # with it rather than leaving four stale strings that fail at build-script time.
110
+ #
111
+ # This profile supplies the toolchain and nothing else. CARGO_BUILD_TARGET is
112
+ # deliberately NOT set: the triple belongs to the Nx target that asks for it
113
+ # (`cargo-lint-x64-linux` passes `--target` explicitly), not to the ambient
114
+ # environment. An ambient triple would make the check silently host-local
115
+ # whenever the profile was forgotten — reporting green having compiled macOS —
116
+ # and that false green is the precise failure this whole profile exists to end.
117
+ # With the flag on the target instead, running it outside this profile fails
118
+ # loudly at `ToolNotFound` and a host lint can never be mistaken for a cross one.
119
+ profiles.linux-cross.module = let
120
+ crossCC = pkgs.pkgsCross.gnu64.stdenv.cc;
121
+ crossLibc = lib.getDev crossCC.libc;
122
+ tool = name: "${crossCC}/bin/${crossCC.targetPrefix}${name}";
123
+ in {
124
+ packages = [crossCC];
125
+ env = {
126
+ CC_x86_64_unknown_linux_gnu = tool "cc";
127
+ CXX_x86_64_unknown_linux_gnu = tool "c++";
128
+ AR_x86_64_unknown_linux_gnu = tool "ar";
129
+ CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER = tool "cc";
130
+ # bindgen runs host libclang, which cannot infer the cross compiler's headers.
131
+ BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu = "--target=x86_64-unknown-linux-gnu -isystem ${crossLibc}/include -isystem ${pkgs.pkgsCross.gnu64.linuxHeaders}/include";
132
+ };
133
+ };
134
+
135
+ # linux-cross is the only profile here, and the shape of the publish job is
136
+ # why. A lean publish shell was measured and rejected, so the next reader does
137
+ # not have to measure it again.
138
+ #
139
+ # The ceiling first: dropping rustc, Go, binaryen, the cargo helpers, python
140
+ # and the clang/lldb tools leaves 2.21 GiB of a 5.41 GiB default closure
141
+ # (`nix path-info -S` over the devenv profile, aarch64-darwin), and modules
142
+ # only ADD — so collecting that saving means moving the toolchain OUT of base
143
+ # and making every developer shell and every other CI job pass `-P`. A
144
+ # forgotten flag then yields a shell that is quietly missing a compiler, which
145
+ # is the same false green the paragraph above exists to prevent.
146
+ #
147
+ # Repair is what makes it unfixable rather than merely awkward. `smoo release
148
+ # repair-pending` builds the historical release commits npm is missing, and it
149
+ # gets their toolchain by running a plain `devenv shell` AT that checkout
150
+ # (packages/cli/src/lib/devenv.ts). No flag is passed and none can be: devenv
151
+ # throws for a profile the checked-out commit does not define — `Profile 'x'
152
+ # not found. Available profiles: ...` — which is every release commit older
153
+ # than the split. Leave the flag off and a post-split commit hands repair a
154
+ # base without rustc; add it and every pre-split commit fails to evaluate.
155
+ # Either way the break surfaces months later, in the one command whose whole
156
+ # job is to recover a release that already went wrong.
157
+ #
158
+ # The publish job's OWN environment is not just publishing either: `smoo
159
+ # release publish --prebuilt` runs each project's Nx `release-check` gate over
160
+ # the merged artifacts, which is where a native or wasm artifact is validated
161
+ # before it is packed. A lean publish shell removes those tools silently, from
162
+ # the one step that exists to refuse a bad artifact.
163
+ #
164
+ # And it would not even pay: the Actions nix segment is keyed on
165
+ # os+arch+hash(devenv.yaml, devenv.nix, devenv.lock) and is blind to the
166
+ # profile, so a restore ships the whole NAR regardless, while the save exports
167
+ # the closure that job realized. A lean publish job that won that immutable
168
+ # key would hand the CI workflow a NAR with no toolchain in it. On any run
169
+ # where repair has work the saving is zero anyway, because repair realizes the
170
+ # historical default shell inside the same job.
171
+
172
+ # One Go for every repository, same reasoning as the Rust toolchain: a compiler
173
+ # is part of a cache key, so two of them mean two caches.
174
+ #
175
+ # Pinned to the patch release ttsc vendors inside its native package, because
176
+ # that SDK is not overridable — ttsc exposes cache locations and
177
+ # TTSC_TSGO_BINARY, never the Go it builds plugins with — so matching it is the
178
+ # only way to have ONE Go rather than ours plus a dependency's. `smoo monorepo
179
+ # check` enforces the match and fails with both versions when they diverge,
180
+ # which is what makes this pin a maintained invariant instead of a comment that
181
+ # rots.
182
+ #
183
+ # It needs its own input because the fleet's nixpkgs does not carry that patch:
184
+ # devenv-nixpkgs rolling ships go 1.26.5 and its `go_1_27` is a release
185
+ # candidate, while ttsc 0.28.3 vendors go1.26.7. Same idiom, and same reason,
186
+ # for any single-package pin — one leaf package from a nixpkgs that has it,
187
+ # lock-pinned, prebuilt, rather than a fleet-wide bump that would move rustc,
188
+ # bun and node too. Not every pairing is reachable: ttsc 0.28.1/0.28.2 vendor
189
+ # go1.26.6, which NO channel packages, so when no revision offers the vendored
190
+ # patch the ttsc pin is what moves.
191
+ #
192
+ # The ownership boundary this pin sits inside, unchanged by it: our code is
193
+ # built with the Go devenv provides, a dependency may vendor its own SDK, and
194
+ # neither may leak GOROOT into the other. Go therefore arrives via `packages`
195
+ # and NOT `languages.go.enable`, which would export GOROOT; on PATH only, each
196
+ # toolchain resolves its own GOROOT from its own binary. With the versions
197
+ # matched that crossing cannot misfire at all, so the unset in enterShell is
198
+ # belt-and-braces rather than the fix.
199
+ # Node tracks the newest AWS Lambda managed runtime, currently nodejs26.x. It
200
+ # lives here rather than in each repository's devenv.nix because it is a
201
+ # fleet-wide fact: declared in three places, the next bump has to find all
202
+ # three, and the one it misses re-splits the fleet.
203
+ #
204
+ # An explicit major, NOT `nodejs_latest`. A tool that participates in cache keys
205
+ # and native-addon ABI must not be spelled "whatever is newest" in one
206
+ # repository and a fixed major in the others — and the two spellings agreeing
207
+ # today is precisely what makes the drift invisible, because the fleet looks
208
+ # unified right up to the lock bump that splits it. A floating attribute is a
209
+ # version that changes without a commit, so it cannot be reviewed or bisected.
210
+ #
211
+ # 26 also closes a split this axis caused once: 24.0.x declares URLPattern in a
212
+ # way that TS2403-conflicts with lib.dom in consumers emitting declarations,
213
+ # which forced a ~24.13.0 floor on one side; 26 is DOM-compatible.
214
+ #
215
+ # `@types/node`, `engines.node` and `packageManager` are derived from this pin
216
+ # rather than maintained beside it — smoo's syncRootRuntimeVersions reads the
217
+ # shell's Node major, so this line moves them.
218
+ #
219
+ # Reading which version this resolves to: devenv.lock has TWO nixpkgs nodes and
220
+ # the obvious one is a decoy. `.nodes.nixpkgs` is not what `pkgs` is; the
221
+ # authoritative path is `.nodes.root.inputs.nixpkgs`, which indirects to
222
+ # `nixpkgs_2`.
223
+ packages =
224
+ [
225
+ (import inputs.nixpkgs-go {inherit (pkgs.stdenv.hostPlatform) system;}).go
226
+ pkgs.nodejs_26
227
+ pkgs.binaryen
228
+ # Test runner for inferred Cargo test targets. Generated targets must never
229
+ # depend on an ambient host installation that CI does not reproduce.
230
+ pkgs.cargo-nextest
231
+ # Target-dir GC for the inferred cargo-sweep target: cargo never removes
232
+ # superseded artifacts on its own (a busy workspace accumulated ~18k stale
233
+ # variants per crate and 26 GB of junk before this existed), and a sweep
234
+ # prunes them without touching the warm current-fingerprint surface.
235
+ pkgs.cargo-sweep
236
+ # The stable-toolchain arm of smoo's workspace feature-unification policy:
237
+ # `cargo hakari` generates and wires the workspace-hack crate that unifies
238
+ # features when `[resolver] feature-unification` — nightly-only, and what
239
+ # the channel above selects — is unavailable. `smoo monorepo validate` runs
240
+ # `cargo hakari verify` for a workspace that took that route.
241
+ pkgs.cargo-hakari
242
+ ]
243
+ ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [pkgs.chromium];
244
+
245
+ enterShell = lib.mkMerge [
246
+ # Prologue, in order:
247
+ #
248
+ # 1. The devenv wrapper runs from tooling/direnv; every later step expects the
249
+ # workspace root.
250
+ # 2. PATH order is most-specific → least-specific, the same list the git hooks
251
+ # use, so a hook and a shell resolve one binary the same way.
252
+ # 3. ttsc drives the native TypeScript 7 binary while Nx imports the TypeScript
253
+ # 6 API, so the two must be named separately.
254
+ # 4. On a cowshed host, Go and ttsc caches point at the shared store, so every
255
+ # workspace reads one warm cache instead of growing its own copy inside its
256
+ # image. Without one, ttsc stays in-tree for the CI cache action while Go
257
+ # keeps its normal per-user defaults. Both Go caches are content-addressed,
258
+ # so sharing them needs no patch — unlike Rust, Go keys on content and flags
259
+ # rather than on where the files live. An inherited value always wins so CI
260
+ # can place any of these caches itself. GOFLAGS carries -trimpath because it
261
+ # is Go's stable way to keep absolute build paths out of the artifact, and
262
+ # unlike Rust's trim-paths it costs no cache reuse.
263
+ #
264
+ # ttsc's plugin builds use the Go it bundles rather than ours, so the
265
+ # repository's own Go work and ttsc's plugin builds are two toolchains by
266
+ # construction. Placing both caches in the shared store is what keeps that
267
+ # from costing a rebuild per workspace.
268
+ #
269
+ # TTSC_GO_CACHE_DIR and GOCACHE stay separate for ownership, not
270
+ # correctness: both caches are content-addressed, so one directory would
271
+ # compile the same bytes to the same entries. What sharing loses is an
272
+ # owner. ttsc reclaims a Go build cache only when it resolved that
273
+ # directory itself — `ttsc clean` takes the cache whose source is
274
+ # TTSC_GO_CACHE_DIR and never one whose source is a user GOCACHE, which it
275
+ # treats as someone else's property. Pointing ttsc at GOCACHE therefore
276
+ # produced a directory ttsc filled and no repository verb could empty,
277
+ # measured at 35G here. A dedicated directory gives ttsc's half back to
278
+ # `ttsc clean` and leaves GOCACHE holding only Go work this repository does
279
+ # itself, which is one module.
280
+ #
281
+ # That buys ownership, not automatic GC: ttsc prunes opportunistically only
282
+ # when it owns the whole cache root, which requires TTSC_CACHE_DIR unset,
283
+ # and a pinned shared root is the point of the block below. The trade is
284
+ # deliberate — one warm cache every workspace shares, reclaimed by an
285
+ # explicit verb, over per-workspace caches that self-trim. Go's own build
286
+ # cache trimming belongs to the go command and still applies to both.
287
+ # 5. The shared setup-environment.ts bootstraps repository dependencies; a
288
+ # failure aborts shell entry instead of yielding a half-working shell.
289
+ # Repo-owned enterShell bodies merge after this prologue.
290
+ # 6. Shell entry resolves the `shell` group of `smoo.secrets` and nothing
291
+ # else. Shell entry happens on every direnv reload and every
292
+ # `devenv shell -- <command>`, and a provider command that runs then is a
293
+ # credential prompt on every one of them (1Password authorises per
294
+ # requesting process lineage, and this one is new each time). A
295
+ # credential only one deliberate command needs belongs to that command:
296
+ # `smoo secrets run <group> <command...>`. The full statement, and the
297
+ # derivation below, live in tooling/direnv/secret-references.ts.
298
+ #
299
+ # A group is derived from what the repository already declares, so
300
+ # nothing restates it:
301
+ #
302
+ # The variable `smoo.remoteCache.tokenSecret` names is group
303
+ # `nx-cache`, and shell entry never resolves it. Nx reads
304
+ # NX_SELF_HOSTED_REMOTE_CACHE_SERVER and _ACCESS_TOKEN from the
305
+ # environment when it runs: CI injects them into the job, a developer
306
+ # exports the token once in the terminal that wants the cache (for
307
+ # example `op signin`, then the declared command), and every nested
308
+ # shell inherits it. Absent, Nx runs with the local cache only.
309
+ #
310
+ # A variable `.npmrc` interpolates as `${VAR}` is group `registry`,
311
+ # deferred rather than resolved, so setup-environment.ts installs
312
+ # without it. An installed checkout contacts no registry, which is why
313
+ # that costs nothing in the common case; an install that genuinely
314
+ # needs one fails naming the variable, and `smoo secrets run registry
315
+ # bun install` supplies it for that one command.
316
+ # 7. GOROOT is unset rather than set. With devenv's Go pinned to the patch
317
+ # release ttsc vendors, a GOROOT crossing cannot misfire on version at all,
318
+ # so this is belt-and-braces rather than the fix — it keeps the isolation
319
+ # boundary intact even while the two are momentarily out of step, e.g. after
320
+ # a ttsc bump and before the Go pin follows it. The boundary itself: our Go
321
+ # comes from devenv, a dependency may vendor its own SDK, and neither may
322
+ # leak GOROOT into the other. An inherited GOROOT names exactly one
323
+ # toolchain and so is wrong for at least one side, surfacing as `compile:
324
+ # version does not match go tool version`. Absent the variable, every Go
325
+ # resolves its own GOROOT from its own binary, which makes "whose Go is
326
+ # whose" a property of which binary is invoked — the only thing that can
327
+ # actually be reasoned about.
328
+ # 8. On Darwin, drop nix CC/CXX so xcodebuild finds Xcode's clang (it supports
329
+ # -index-store-path); bun/node native addons find compilers through
330
+ # node-gyp. CC/CXX are what xcodebuild reads, which is why they go rather
331
+ # than being pointed somewhere else.
332
+ #
333
+ # The Apple SDK is the same boundary, and dropping CC/CXX alone does not
334
+ # hold it. An outer nix stdenv exports SDKROOT and DEVELOPER_DIR pointing
335
+ # at nixpkgs' RECONSTRUCTED apple-sdk, so Xcode's own clang goes on to
336
+ # compile against that sysroot. It is not a substitute for the licensed
337
+ # SDK: apple-sdk-14.4 carries usr/include and the frameworks but NO libc++
338
+ # whatsoever — no usr/include/c++/v1 and no usr/lib/libc++* — so any C++
339
+ # build script that resolves the SDK by name dies at `ld: library 'c++'
340
+ # not found`, which a CMake `*-sys` crate reaches before compiling a line
341
+ # of the project. DEVELOPER_DIR is the half that hides: `xcrun
342
+ # --show-sdk-path` honours it, so even code that correctly asks xcrun for
343
+ # the SDK is handed the nix one, while `xcrun --find clang` and
344
+ # `xcodebuild -version` keep reporting Xcode and look healthy. It also
345
+ # defeats any later guard that unsets a nix SDKROOT and then re-resolves
346
+ # it through xcrun, because xcrun answers with the same tree again.
347
+ #
348
+ # Only a /nix/store value is dropped. An SDKROOT the operator exported
349
+ # deliberately — the documented way to link Darwin from a Linux host — is
350
+ # left exactly as given. Each drop is announced, so a shell never silently
351
+ # swaps the SDK a build was compiled against.
352
+ # Nx's fallback includes HOME or TMPDIR, either of which can exceed the
353
+ # Unix socket limit in a checkout. Reuse devenv's short runtime directory,
354
+ # which is keyed on this checkout's devenv root and so is one per
355
+ # workspace. Unconditionally: an inherited value is another workspace's
356
+ # shell (a shed entered from the host, a second repository from the first,
357
+ # a subprocess of either), and one socket dir for two workspaces makes the
358
+ # daemon refuse whichever came second ("received a message from a
359
+ # different workspace"). Nobody supplies this deliberately.
360
+ (lib.mkBefore ''
361
+ cd "$DEVENV_ROOT/../.."
362
+ export PATH="$("$PWD/tooling/direnv/repo-path")"
363
+ # devenv enters the shell with TMPDIR unset (not empty) on every platform.
364
+ # Tools then fall back to /tmp, which on Darwin is not the per-user
365
+ # temporary directory the OS hands out, and a test that asserts the
366
+ # parent carries TMPDIR (so its env_clear check means something) fails in
367
+ # the shell and passes outside it. Ask the OS; an explicit value wins.
368
+ if [ -z "''${TMPDIR:-}" ]; then
369
+ TMPDIR="$(getconf DARWIN_USER_TEMP_DIR 2>/dev/null || true)"
370
+ export TMPDIR="''${TMPDIR:-/tmp}"
371
+ fi
372
+ export TTSC_TSGO_BINARY="$PWD/node_modules/@typescript/native/bin/tsc"
373
+ if [ -d "$HOME/.cowshed/caches" ]; then
374
+ export TTSC_CACHE_DIR="''${TTSC_CACHE_DIR:-$HOME/.cowshed/caches/ttsc}"
375
+ export GOCACHE="''${GOCACHE:-$HOME/.cowshed/caches/go/build}"
376
+ export GOMODCACHE="''${GOMODCACHE:-$HOME/.cowshed/caches/go/mod}"
377
+ mkdir -p "$GOCACHE" "$GOMODCACHE"
378
+ else
379
+ export TTSC_CACHE_DIR="''${TTSC_CACHE_DIR:-$PWD/.cache/ttsc}"
380
+ fi
381
+ export TTSC_GO_CACHE_DIR="''${TTSC_GO_CACHE_DIR:-$TTSC_CACHE_DIR/go-build}"
382
+ mkdir -p "$TTSC_CACHE_DIR" "$TTSC_GO_CACHE_DIR"
383
+ export GOFLAGS="''${GOFLAGS:--trimpath}"
384
+ unset GOROOT
385
+ bun "$DEVENV_ROOT/setup-environment.ts" || exit $?
386
+ # One socket dir per Nx workspace. DEVENV_RUNTIME is keyed to the devenv
387
+ # ROOT, so every workspace sharing one devenv - a sibling repository, a
388
+ # copy-on-write clone, a scratch workspace created inside this shell -
389
+ # would land on one socket. The first daemon to claim it then refuses
390
+ # every message from the others ("received a message from a different
391
+ # workspace"), which reads as a hung Nx in a workspace that did nothing
392
+ # wrong. Nx's own diagnostic names this exact cause.
393
+ nx_workspace_root="$(cd "$DEVENV_ROOT/../.." >/dev/null 2>&1 && pwd || printf '%s' "$PWD")"
394
+ export NX_SOCKET_DIR="$DEVENV_RUNTIME/nx-$(printf '%s' "$nx_workspace_root" | cksum | cut -d' ' -f1)"
395
+ mkdir -p "$NX_SOCKET_DIR"
396
+ ${lib.optionalString pkgs.stdenv.isDarwin ''
397
+ unset CC CXX
398
+ case "''${SDKROOT:-}" in
399
+ /nix/store/*)
400
+ echo "devenv: dropping nix-store SDKROOT ($SDKROOT); Xcode holds the licensed macOS SDK" >&2
401
+ unset SDKROOT NIX_APPLE_SDK_VERSION
402
+ ;;
403
+ esac
404
+ case "''${DEVELOPER_DIR:-}" in
405
+ /nix/store/*)
406
+ echo "devenv: dropping nix-store DEVELOPER_DIR ($DEVELOPER_DIR); xcrun must answer from Xcode" >&2
407
+ unset DEVELOPER_DIR NIX_APPLE_SDK_VERSION
408
+ ;;
409
+ esac
410
+ ''}
411
+ '')
412
+ # Epilogue, after every project step (a project's own enterShell may resolve
413
+ # SDKROOT/compilers; the toolchain identity must see the final values). The
414
+ # stamp logic lives in toolchain-stamp.ts; see its header for why.
415
+ (lib.mkAfter ''
416
+ bun "$DEVENV_ROOT/toolchain-stamp.ts" || exit $?
417
+ if [ -n "$DEVENV_SHELL_PWD" ]; then
418
+ cd "$DEVENV_SHELL_PWD"
419
+ fi
420
+ '')
421
+ ];
422
+ }