@smoothbricks/nx-plugin 0.4.25 → 0.4.27

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 (348) hide show
  1. package/README.md +1078 -98
  2. package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
  3. package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
  4. package/dist/bin/smoo-nx-bound-failures.js +31 -0
  5. package/dist/bin/smoo-nx-cargo-hash.js +28 -3
  6. package/dist/bin/smoo-nx-exec.js +16 -85
  7. package/dist/bin/smoo-nx-failures.d.ts +3 -0
  8. package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
  9. package/dist/bin/smoo-nx-failures.js +3 -0
  10. package/dist/bin/smoo-nx-nextest-extract.js +3 -2
  11. package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
  12. package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
  13. package/dist/bin/smoo-nx-test-walks.js +34 -0
  14. package/dist/bounded-test-policy.d.ts +7 -1
  15. package/dist/bounded-test-policy.d.ts.map +1 -1
  16. package/dist/bounded-test-policy.js +101 -40
  17. package/dist/build-state-output-policy.d.ts +25 -0
  18. package/dist/build-state-output-policy.d.ts.map +1 -0
  19. package/dist/build-state-output-policy.js +64 -0
  20. package/dist/cargo-closure-input.d.ts +16 -17
  21. package/dist/cargo-closure-input.d.ts.map +1 -1
  22. package/dist/cargo-closure-input.js +37 -44
  23. package/dist/cargo-dev-profile.d.ts +37 -0
  24. package/dist/cargo-dev-profile.d.ts.map +1 -0
  25. package/dist/cargo-dev-profile.js +108 -0
  26. package/dist/cargo-source-hash.d.ts +50 -8
  27. package/dist/cargo-source-hash.d.ts.map +1 -1
  28. package/dist/cargo-source-hash.js +691 -71
  29. package/dist/cargo-toolchain-policy.d.ts +4 -0
  30. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  31. package/dist/cargo-toolchain-policy.js +5 -0
  32. package/dist/cargo-workspace.d.ts +108 -12
  33. package/dist/cargo-workspace.d.ts.map +1 -1
  34. package/dist/cargo-workspace.js +299 -18
  35. package/dist/cross-check-policy.d.ts +21 -3
  36. package/dist/cross-check-policy.d.ts.map +1 -1
  37. package/dist/cross-check-policy.js +24 -6
  38. package/dist/disk-command-policy.d.ts +7 -0
  39. package/dist/disk-command-policy.d.ts.map +1 -0
  40. package/dist/disk-command-policy.js +98 -0
  41. package/dist/ensure-built-receipt.d.ts +25 -0
  42. package/dist/ensure-built-receipt.d.ts.map +1 -0
  43. package/dist/ensure-built-receipt.js +261 -0
  44. package/dist/ensure-built-witness.d.ts +57 -0
  45. package/dist/ensure-built-witness.d.ts.map +1 -0
  46. package/dist/ensure-built-witness.js +412 -0
  47. package/dist/ensure-built.d.ts +213 -12
  48. package/dist/ensure-built.d.ts.map +1 -1
  49. package/dist/ensure-built.js +624 -177
  50. package/dist/eslint-file-set.d.ts +7 -0
  51. package/dist/eslint-file-set.d.ts.map +1 -0
  52. package/dist/eslint-file-set.js +12 -0
  53. package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
  54. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
  55. package/dist/executors/bounded-exec/cpu-pool.js +379 -0
  56. package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
  57. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
  58. package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
  59. package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
  60. package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
  61. package/dist/executors/bounded-exec/disk-lease.js +91 -0
  62. package/dist/executors/bounded-exec/executor.d.ts +45 -2
  63. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  64. package/dist/executors/bounded-exec/executor.js +447 -52
  65. package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
  66. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
  67. package/dist/executors/bounded-exec/gateway-lease.js +143 -0
  68. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
  69. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
  70. package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
  71. package/dist/executors/bounded-exec/progress.d.ts +35 -0
  72. package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
  73. package/dist/executors/bounded-exec/progress.js +79 -0
  74. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
  75. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
  76. package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
  77. package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
  78. package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
  79. package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
  80. package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
  81. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
  82. package/dist/executors/bounded-exec/ram-temp.js +1528 -0
  83. package/dist/executors/bounded-exec/schema.d.ts +29 -11
  84. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  85. package/dist/executors/bounded-exec/verdict.d.ts +162 -0
  86. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/verdict.js +318 -0
  88. package/dist/executors/shard-timings/executor.d.ts +14 -0
  89. package/dist/executors/shard-timings/executor.d.ts.map +1 -0
  90. package/dist/executors/shard-timings/executor.js +25 -0
  91. package/dist/executors/shard-timings/schema.d.ts +4 -0
  92. package/dist/executors/shard-timings/schema.d.ts.map +1 -0
  93. package/dist/executors/shard-timings/schema.js +1 -0
  94. package/dist/failure-summary.d.ts +5 -0
  95. package/dist/failure-summary.d.ts.map +1 -0
  96. package/dist/failure-summary.js +118 -0
  97. package/dist/generators/create-package/generator.d.ts.map +1 -1
  98. package/dist/generators/create-package/generator.js +6 -2
  99. package/dist/index.d.ts +14 -2
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +435 -230
  102. package/dist/managed-assets.d.ts +6 -0
  103. package/dist/managed-assets.d.ts.map +1 -1
  104. package/dist/managed-files/ci-workflow.d.ts +13 -0
  105. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  106. package/dist/managed-files/ci-workflow.js +44 -13
  107. package/dist/managed-files/files.d.ts +7 -1
  108. package/dist/managed-files/files.d.ts.map +1 -1
  109. package/dist/managed-files/files.js +62 -8
  110. package/dist/managed-files/json-edit.d.ts +21 -0
  111. package/dist/managed-files/json-edit.d.ts.map +1 -0
  112. package/dist/managed-files/json-edit.js +295 -0
  113. package/dist/managed-files/managed-format.d.ts +33 -1
  114. package/dist/managed-files/managed-format.d.ts.map +1 -1
  115. package/dist/managed-files/managed-format.js +82 -2
  116. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
  117. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
  118. package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
  119. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  120. package/dist/managed-files/publish-workflow.js +231 -48
  121. package/dist/managed-files/tree.d.ts +5 -0
  122. package/dist/managed-files/tree.d.ts.map +1 -1
  123. package/dist/managed-files/tree.js +5 -3
  124. package/dist/manifest-hash.js +3 -2
  125. package/dist/nextest-code-bound.d.ts +62 -0
  126. package/dist/nextest-code-bound.d.ts.map +1 -0
  127. package/dist/nextest-code-bound.js +154 -0
  128. package/dist/nextest-extraction.d.ts +24 -8
  129. package/dist/nextest-extraction.d.ts.map +1 -1
  130. package/dist/nextest-extraction.js +42 -7
  131. package/dist/package-target-policy.d.ts.map +1 -1
  132. package/dist/package-target-policy.js +3 -5
  133. package/dist/release-config-policy.d.ts.map +1 -1
  134. package/dist/release-config-policy.js +3 -5
  135. package/dist/runtime-input.d.ts +14 -0
  136. package/dist/runtime-input.d.ts.map +1 -0
  137. package/dist/runtime-input.js +15 -0
  138. package/dist/rust-tokens.d.ts +11 -0
  139. package/dist/rust-tokens.d.ts.map +1 -0
  140. package/dist/rust-tokens.js +81 -0
  141. package/dist/task-results.d.ts +6 -0
  142. package/dist/task-results.d.ts.map +1 -0
  143. package/dist/task-results.js +61 -0
  144. package/dist/test-program.d.ts +54 -0
  145. package/dist/test-program.d.ts.map +1 -0
  146. package/dist/test-program.js +292 -0
  147. package/dist/test-timings.d.ts +71 -0
  148. package/dist/test-timings.d.ts.map +1 -0
  149. package/dist/test-timings.js +393 -0
  150. package/dist/test-walk-policy.d.ts +103 -0
  151. package/dist/test-walk-policy.d.ts.map +1 -0
  152. package/dist/test-walk-policy.js +657 -0
  153. package/dist/testing.d.ts +177 -0
  154. package/dist/testing.d.ts.map +1 -0
  155. package/dist/testing.js +824 -0
  156. package/dist/type-guards.d.ts +3 -0
  157. package/dist/type-guards.d.ts.map +1 -0
  158. package/dist/type-guards.js +4 -0
  159. package/dist/typecheck-test-policy.d.ts +8 -5
  160. package/dist/typecheck-test-policy.d.ts.map +1 -1
  161. package/dist/typecheck-test-policy.js +113 -100
  162. package/dist/workspace-config-policy.d.ts +8 -0
  163. package/dist/workspace-config-policy.d.ts.map +1 -1
  164. package/dist/workspace-config-policy.js +175 -63
  165. package/dist/workspace-index.d.ts +12 -0
  166. package/dist/workspace-index.d.ts.map +1 -0
  167. package/dist/workspace-index.js +17 -0
  168. package/dist/workspace-manifest.d.ts +37 -1
  169. package/dist/workspace-manifest.d.ts.map +1 -1
  170. package/executors.json +5 -0
  171. package/loader.js +13 -11
  172. package/managed/raw/envrc +33 -62
  173. package/managed/raw/git-format-staged.yml +30 -35
  174. package/managed/raw/patches/nx@23.2.1.patch +3484 -0
  175. package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
  176. package/managed/raw/tooling/direnv/developer-links.ts +607 -17
  177. package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -92
  178. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
  179. package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
  180. package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
  181. package/managed/raw/tooling/direnv/repo-path +14 -2
  182. package/managed/raw/tooling/direnv/setup-environment.ts +1009 -118
  183. package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
  184. package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
  185. package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
  186. package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
  187. package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
  188. package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
  189. package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
  190. package/managed/templates/github/actions/cache-nx/action.yml +1 -1
  191. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
  192. package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
  193. package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
  194. package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
  195. package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
  196. package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
  197. package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
  198. package/managed/templates/github/workflows/managed-files.yml +1 -2
  199. package/nextest.toml +8 -75
  200. package/package.json +75 -13
  201. package/runtime-input.sh +81 -0
  202. package/src/__tests__/counted-cargo-process.ts +286 -0
  203. package/src/__tests__/counted-cargo.ts +730 -0
  204. package/src/__tests__/fixture-cargo-home.ts +36 -0
  205. package/src/__tests__/fixture-nx-env.ts +157 -2
  206. package/src/__tests__/progress-clock.ts +43 -0
  207. package/src/__tests__/runtime-input.ts +23 -0
  208. package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
  209. package/src/bin/smoo-nx-bound-failures.ts +33 -0
  210. package/src/bin/smoo-nx-cargo-hash.ts +28 -3
  211. package/src/bin/smoo-nx-exec.ts +17 -86
  212. package/src/bin/smoo-nx-failures.ts +4 -0
  213. package/src/bin/smoo-nx-nextest-extract.ts +3 -2
  214. package/src/bin/smoo-nx-test-walks.ts +42 -0
  215. package/src/bounded-test-policy.test.ts +268 -22
  216. package/src/bounded-test-policy.ts +114 -42
  217. package/src/build-state-output-policy.test.ts +115 -0
  218. package/src/build-state-output-policy.ts +90 -0
  219. package/src/bun-bootstrap.test.ts +57 -3
  220. package/src/bun-file-packages.test.ts +47 -0
  221. package/src/cargo-closure-input.test.ts +432 -62
  222. package/src/cargo-closure-input.ts +51 -57
  223. package/src/cargo-dev-profile.ts +137 -0
  224. package/src/cargo-resolve-cache.test.ts +1044 -0
  225. package/src/cargo-source-hash.test.ts +203 -93
  226. package/src/cargo-source-hash.ts +762 -75
  227. package/src/cargo-toolchain-policy.ts +6 -0
  228. package/src/cargo-workspace.test.ts +320 -0
  229. package/src/cargo-workspace.ts +344 -18
  230. package/src/cross-check-policy.test.ts +59 -1
  231. package/src/cross-check-policy.ts +25 -6
  232. package/src/disk-command-policy.test.ts +61 -0
  233. package/src/disk-command-policy.ts +107 -0
  234. package/src/ensure-built-receipt.test.ts +184 -0
  235. package/src/ensure-built-receipt.ts +263 -0
  236. package/src/ensure-built-witness.test.ts +344 -0
  237. package/src/ensure-built-witness.ts +252 -0
  238. package/src/ensure-built.test.ts +1043 -483
  239. package/src/ensure-built.ts +870 -197
  240. package/src/eslint-file-set.ts +9 -0
  241. package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
  242. package/src/executors/bounded-exec/cpu-pool.ts +417 -0
  243. package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
  244. package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
  245. package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
  246. package/src/executors/bounded-exec/disk-lease.ts +139 -0
  247. package/src/executors/bounded-exec/executor-host.test.ts +778 -0
  248. package/src/executors/bounded-exec/executor.test.ts +1116 -63
  249. package/src/executors/bounded-exec/executor.ts +565 -67
  250. package/src/executors/bounded-exec/gateway-lease.ts +176 -0
  251. package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
  252. package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
  253. package/src/executors/bounded-exec/progress.test.ts +79 -0
  254. package/src/executors/bounded-exec/progress.ts +118 -0
  255. package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
  256. package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
  257. package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
  258. package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
  259. package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
  260. package/src/executors/bounded-exec/ram-temp.ts +1918 -0
  261. package/src/executors/bounded-exec/schema.json +11 -5
  262. package/src/executors/bounded-exec/schema.ts +27 -11
  263. package/src/executors/bounded-exec/verdict.test.ts +440 -0
  264. package/src/executors/bounded-exec/verdict.ts +433 -0
  265. package/src/executors/shard-timings/executor.ts +36 -0
  266. package/src/executors/shard-timings/schema.json +21 -0
  267. package/src/executors/shard-timings/schema.ts +4 -0
  268. package/src/failure-summary.ts +119 -0
  269. package/src/generators/bounded-test-targets/generator.test.ts +4 -4
  270. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  271. package/src/generators/create-package/generator.test.ts +6 -0
  272. package/src/generators/create-package/generator.ts +6 -2
  273. package/src/host-controller-wiring.test.ts +31 -0
  274. package/src/index.test.ts +1070 -360
  275. package/src/index.ts +524 -255
  276. package/src/linked-snapshots.nx.test.ts +172 -0
  277. package/src/managed-assets.ts +12 -0
  278. package/src/managed-files/ci-workflow.ts +54 -13
  279. package/src/managed-files/files.ts +65 -9
  280. package/src/managed-files/forgejo-artifact.test.ts +395 -0
  281. package/src/managed-files/generator.test.ts +60 -1
  282. package/src/managed-files/json-edit.test.ts +216 -0
  283. package/src/managed-files/json-edit.ts +290 -0
  284. package/src/managed-files/managed-format-json.test.ts +308 -0
  285. package/src/managed-files/managed-format.ts +90 -2
  286. package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
  287. package/src/managed-files/publish-workflow.ts +285 -67
  288. package/src/managed-files/repo-path.test.ts +129 -0
  289. package/src/managed-files/trace-db-artifact.test.ts +7 -0
  290. package/src/managed-files/tree.ts +11 -3
  291. package/src/manifest-hash.ts +3 -2
  292. package/src/nextest-code-bound.test.ts +155 -0
  293. package/src/nextest-code-bound.ts +195 -0
  294. package/src/nextest-extraction.test.ts +37 -5
  295. package/src/nextest-extraction.ts +51 -9
  296. package/src/nextest-partitions.test.ts +495 -0
  297. package/src/nx-cache-bound.test.ts +109 -0
  298. package/src/nx-cache-restore-mtime.test.ts +170 -0
  299. package/src/nx-daemon-claim.test.ts +277 -0
  300. package/src/nx-daemon-idle-cpu.test.ts +81 -0
  301. package/src/nx-daemon-idle-policy.test.ts +51 -0
  302. package/src/nx-daemon-ignore-files.test.ts +210 -0
  303. package/src/nx-daemon-root-normalization.test.ts +105 -0
  304. package/src/nx-daemon-validity.test.ts +925 -0
  305. package/src/nx-dot-input-policy.test.ts +353 -0
  306. package/src/nx-failure-life-cycles.test.ts +207 -0
  307. package/src/nx-files-archive-racy.test.ts +97 -0
  308. package/src/nx-foreign-workspace-env.test.ts +329 -0
  309. package/src/nx-incomplete-run-summary.test.ts +70 -0
  310. package/src/nx-plugin-load-errors.test.ts +120 -0
  311. package/src/nx-project-resolution-cache.test.ts +176 -0
  312. package/src/nx-raw-inputs.test.ts +166 -0
  313. package/src/nx-resident-graph-workers.test.ts +112 -0
  314. package/src/nx-run-information.test.ts +118 -0
  315. package/src/nx-skipped-task-exit.test.ts +180 -0
  316. package/src/nx-state-location.test.ts +63 -0
  317. package/src/nx-store-resolution.test.ts +99 -0
  318. package/src/nx-task-graph-cycles.test.ts +148 -0
  319. package/src/nx-task-output-lease.test.ts +414 -0
  320. package/src/nx-use-local.test.ts +103 -0
  321. package/src/package-target-policy.ts +3 -6
  322. package/src/release-config-policy.ts +3 -6
  323. package/src/runtime-input.test.ts +215 -0
  324. package/src/runtime-input.ts +17 -0
  325. package/src/rust-tokens.ts +78 -0
  326. package/src/serial-group-wiring.test.ts +326 -0
  327. package/src/task-history-namespace.test.ts +181 -0
  328. package/src/task-results.test.ts +226 -0
  329. package/src/task-results.ts +75 -0
  330. package/src/test-program.test.ts +303 -0
  331. package/src/test-program.ts +341 -0
  332. package/src/test-timings.test.ts +240 -0
  333. package/src/test-timings.ts +311 -0
  334. package/src/test-walk-policy.test.ts +585 -0
  335. package/src/test-walk-policy.ts +731 -0
  336. package/src/testing.test.ts +509 -0
  337. package/src/testing.ts +922 -0
  338. package/src/type-guards.ts +4 -0
  339. package/src/typecheck-test-policy.test.ts +496 -11
  340. package/src/typecheck-test-policy.ts +137 -103
  341. package/src/workspace-config-policy.test.ts +212 -13
  342. package/src/workspace-config-policy.ts +101 -73
  343. package/src/workspace-index.ts +18 -0
  344. package/src/workspace-manifest.ts +41 -1
  345. package/test-timings.json +85 -28
  346. package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -615
  347. package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
  348. package/src/__tests__/in-process-nx-index.ts +0 -9
@@ -1,615 +0,0 @@
1
- #!/usr/bin/env bun
2
- import { randomUUID } from 'node:crypto';
3
- /**
4
- * Managed by `smoo monorepo`. A cowshed clone inherits its origin's .devenv
5
- * along with the source tree. Reuse a real devenv export from that private
6
- * image only while the evaluated inputs and toolchain still agree. No shell
7
- * reads a writable cache belonging to another workspace.
8
- */
9
- import {
10
- existsSync,
11
- lstatSync,
12
- mkdirSync,
13
- readdirSync,
14
- readFileSync,
15
- readlinkSync,
16
- realpathSync,
17
- renameSync,
18
- statSync,
19
- writeFileSync,
20
- } from 'node:fs';
21
- import path from 'node:path';
22
-
23
- const DEVENV_DIR = 'tooling/direnv';
24
- const ARTIFACT = 'inherited-shell.json';
25
- const ENV_PATHS = [
26
- 'HOME',
27
- 'TMPDIR',
28
- 'XDG_RUNTIME_DIR',
29
- 'XDG_CONFIG_HOME',
30
- 'XDG_CACHE_HOME',
31
- 'XDG_DATA_HOME',
32
- 'XDG_STATE_HOME',
33
- 'DEVENV_HOME',
34
- 'DIRENV_CONFIG',
35
- 'NX_SOCKET_DIR',
36
- ] as const;
37
- // Nix receives no caller credential, gateway token, or ambient impure override
38
- // while creating an artifact. A live shell still runs with its exact caller env.
39
- const EVALUATOR_ENV = [
40
- 'PATH',
41
- 'HOME',
42
- 'TMPDIR',
43
- 'XDG_RUNTIME_DIR',
44
- 'XDG_CONFIG_HOME',
45
- 'XDG_CACHE_HOME',
46
- 'XDG_DATA_HOME',
47
- 'XDG_STATE_HOME',
48
- 'DEVENV_HOME',
49
- 'DIRENV_CONFIG',
50
- 'NX_SOCKET_DIR',
51
- 'USER',
52
- 'LOGNAME',
53
- 'SHELL',
54
- 'LANG',
55
- 'LC_ALL',
56
- 'LC_CTYPE',
57
- 'TERM',
58
- 'NIX_SSL_CERT_FILE',
59
- 'SSL_CERT_FILE',
60
- 'NODE_EXTRA_CA_CERTS',
61
- 'GIT_SSL_CAINFO',
62
- 'DEVELOPER_DIR',
63
- 'SDKROOT',
64
- ] as const;
65
-
66
- type Watch = { readonly scope: 'root' | 'home' | 'runtime' | 'tmp' | 'store'; readonly relative: string };
67
- type Entry = {
68
- readonly relative: string;
69
- readonly kind: 'file' | 'link';
70
- readonly executable?: boolean;
71
- readonly target?: string;
72
- };
73
- interface Artifact {
74
- readonly version: 1;
75
- readonly root: string;
76
- readonly paths: Readonly<Record<string, string>>;
77
- readonly basis: string;
78
- readonly graphBasis: string;
79
- readonly watches: readonly Watch[];
80
- readonly watchBasis: string;
81
- readonly toolchain: string;
82
- readonly export: string;
83
- }
84
-
85
- function privateEnvironment(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
86
- const selected: NodeJS.ProcessEnv = {};
87
- for (const name of EVALUATOR_ENV) {
88
- const value = env[name];
89
- if (value !== undefined) selected[name] = value;
90
- }
91
- return selected;
92
- }
93
-
94
- function toolchain(env: NodeJS.ProcessEnv): string | undefined {
95
- const versions: string[] = [];
96
- for (const command of [
97
- ['devenv', 'version'],
98
- ['nix', '--version'],
99
- ]) {
100
- const result = Bun.spawnSync(command, { env, stdout: 'pipe', stderr: 'pipe' });
101
- if (result.exitCode !== 0) return undefined;
102
- versions.push(result.stdout.toString().trim());
103
- }
104
- return `${process.platform}/${process.arch}\n${versions.join('\n')}`;
105
- }
106
-
107
- /** devenv's runtime directory is keyed by the dotfile, not by DEVENV_RUNTIME. */
108
- export function devenvRuntimeDir(xdg: string | undefined, dotfile: string): string {
109
- const hash = new Bun.CryptoHasher('sha256').update(dotfile).digest('hex');
110
- return path.join(xdg || '/tmp', `devenv-${hash.slice(0, 7)}`);
111
- }
112
-
113
- function pathsOf(root: string, env: NodeJS.ProcessEnv): Record<string, string> {
114
- const paths: Record<string, string> = {};
115
- for (const name of ENV_PATHS) {
116
- const value = env[name];
117
- if (value) paths[name] = value;
118
- }
119
- paths.DEVENV_RUNTIME = devenvRuntimeDir(env.XDG_RUNTIME_DIR, path.join(root, DEVENV_DIR, '.devenv'));
120
- return paths;
121
- }
122
-
123
- export interface Relocation {
124
- readonly from: string;
125
- readonly to: string;
126
- }
127
- export function relocations(
128
- origin: string,
129
- originPaths: Readonly<Record<string, string>>,
130
- root: string,
131
- env: NodeJS.ProcessEnv,
132
- ): Relocation[] {
133
- const current = pathsOf(root, env);
134
- const moves: Relocation[] = [];
135
- for (const [name, from] of Object.entries(originPaths)) {
136
- const to = current[name];
137
- if (to && from !== to) moves.push({ from, to });
138
- }
139
- moves.push({ from: origin, to: root });
140
- moves.sort((left, right) => right.from.length - left.from.length);
141
- return moves;
142
- }
143
- export function relocate(text: string, moves: readonly Relocation[]): string {
144
- // Match only the original export: a replacement can itself start with HOME,
145
- // especially when a host's checkout lives below HOME.
146
- let cursor = 0;
147
- let result = '';
148
- while (cursor < text.length) {
149
- let next = text.length;
150
- let selected: Relocation | undefined;
151
- for (const move of moves) {
152
- if (!move.from) continue;
153
- const found = text.indexOf(move.from, cursor);
154
- if (found !== -1 && (found < next || (found === next && move.from.length > (selected?.from.length ?? 0)))) {
155
- next = found;
156
- selected = move;
157
- }
158
- }
159
- if (!selected) break;
160
- result += text.slice(cursor, next) + selected.to;
161
- cursor = next + selected.from.length;
162
- }
163
- return result + text.slice(cursor);
164
- }
165
-
166
- /** Local path inputs have Nix's layout; unknown YAML imports are not guessed. */
167
- function pathInputs(root: string): string[] {
168
- const dir = path.join(root, DEVENV_DIR);
169
- const yaml = path.join(dir, 'devenv.yaml');
170
- const document: unknown = Bun.YAML.parse(readFileSync(yaml, 'utf8'));
171
- if (typeof document !== 'object' || document === null || Array.isArray(document))
172
- throw new Error(`${yaml} is not a mapping`);
173
- if ('imports' in document && Array.isArray(document.imports) && document.imports.length > 0) {
174
- throw new Error(`${yaml} imports modules outside the captured inputs`);
175
- }
176
- const inputs = 'inputs' in document ? document.inputs : undefined;
177
- const directories = new Set<string>();
178
- for (const [name, input] of Object.entries(typeof inputs === 'object' && inputs !== null ? inputs : {})) {
179
- const url: unknown = typeof input === 'object' && input !== null && 'url' in input ? input.url : undefined;
180
- if (typeof url !== 'string' || !url.startsWith('path:')) continue;
181
- const resolved = realpathSync(path.resolve(dir, url.slice(5)));
182
- if (!resolved.startsWith(`${root}/`) || !statSync(resolved).isDirectory()) {
183
- throw new Error(`path input ${name} is not a directory inside ${root}`);
184
- }
185
- const relative = path.relative(root, resolved);
186
- if (relative !== DEVENV_DIR && !relative.startsWith(`${DEVENV_DIR}/`)) directories.add(relative);
187
- }
188
- return [...directories].sort();
189
- }
190
-
191
- function entriesUnder(
192
- root: string,
193
- relative: string,
194
- followLinks: boolean,
195
- entries: Entry[],
196
- ancestors: ReadonlySet<string>,
197
- ): void {
198
- const absolute = path.join(root, relative);
199
- const stat = lstatSync(absolute);
200
- if (stat.isSymbolicLink() && !followLinks) {
201
- entries.push({ relative, kind: 'link', target: readlinkSync(absolute) });
202
- return;
203
- }
204
- const real = realpathSync(absolute);
205
- if (!real.startsWith(`${root}/`)) throw new Error(`${absolute} resolves outside ${root}`);
206
- if (ancestors.has(real)) throw new Error(`${absolute} links back into itself`);
207
- const target = statSync(absolute);
208
- if (target.isDirectory()) {
209
- const inside = new Set(ancestors).add(real);
210
- for (const name of readdirSync(absolute).sort()) {
211
- if (relative === DEVENV_DIR && (name === '.devenv' || name === '.direnv')) continue;
212
- entriesUnder(root, path.join(relative, name), followLinks, entries, inside);
213
- }
214
- } else if (target.isFile()) {
215
- entries.push({ relative, kind: 'file', executable: (target.mode & 0o100) !== 0 });
216
- }
217
- }
218
-
219
- function sourceBasis(root: string): string {
220
- const entries: Entry[] = [];
221
- entriesUnder(root, DEVENV_DIR, true, entries, new Set());
222
- for (const relative of pathInputs(root)) entriesUnder(root, relative, false, entries, new Set());
223
- entries.sort((left, right) => left.relative.localeCompare(right.relative));
224
- const hash = new Bun.CryptoHasher('sha256');
225
- for (const entry of entries) {
226
- if (entry.kind === 'link') {
227
- hash.update(`link\0${entry.relative}\0${entry.target}\0`);
228
- } else {
229
- const bytes = readFileSync(path.join(root, entry.relative));
230
- hash.update(`file\0${entry.relative}\0${entry.executable ? 'x' : '-'}\0${bytes.byteLength}\0`);
231
- hash.update(bytes);
232
- }
233
- }
234
- return hash.digest('hex');
235
- }
236
-
237
- function watchPaths(root: string, env: NodeJS.ProcessEnv): Watch[] {
238
- const inputPaths = readFileSync(path.join(root, DEVENV_DIR, '.devenv', 'input-paths.txt'), 'utf8');
239
- const home = env.HOME;
240
- const runtime = devenvRuntimeDir(env.XDG_RUNTIME_DIR, path.join(root, DEVENV_DIR, '.devenv'));
241
- const tmp = env.TMPDIR || '/tmp';
242
- const bases: readonly [Watch['scope'], string | undefined][] = [
243
- ['runtime', runtime],
244
- ['home', home],
245
- ['root', root],
246
- ['tmp', tmp],
247
- ['store', '/nix/store'],
248
- ];
249
- const watches = new Map<string, Watch>();
250
- for (const input of inputPaths.split('\n').filter(Boolean)) {
251
- if (!path.isAbsolute(input)) throw new Error(`devenv input is not absolute: ${input}`);
252
- const match = [...bases]
253
- .sort((a, b) => (b[1]?.length ?? 0) - (a[1]?.length ?? 0))
254
- .find(([, base]) => base && (input === base || input.startsWith(`${base}/`)));
255
- if (!match || !match[1]) throw new Error(`devenv input is outside isolated roots: ${input}`);
256
- const relative = path.relative(match[1], input);
257
- const watch: Watch = { scope: match[0], relative };
258
- watches.set(`${watch.scope}:${watch.relative}`, watch);
259
- }
260
- return [...watches.values()].sort((a, b) => `${a.scope}:${a.relative}`.localeCompare(`${b.scope}:${b.relative}`));
261
- }
262
-
263
- function watchedBasis(root: string, env: NodeJS.ProcessEnv, watches: readonly Watch[]): string {
264
- const bases: Record<Watch['scope'], string> = {
265
- root,
266
- home: env.HOME ?? '',
267
- runtime: devenvRuntimeDir(env.XDG_RUNTIME_DIR, path.join(root, DEVENV_DIR, '.devenv')),
268
- tmp: env.TMPDIR || '/tmp',
269
- store: '/nix/store',
270
- };
271
- const hash = new Bun.CryptoHasher('sha256');
272
- for (const watch of watches) {
273
- const base = bases[watch.scope];
274
- if (!base) throw new Error(`missing ${watch.scope} for a watched devenv input`);
275
- const absolute = path.resolve(base, watch.relative);
276
- if (absolute !== base && !absolute.startsWith(`${base}/`)) throw new Error(`watch escapes ${watch.scope}`);
277
- hash.update(`${watch.scope}:${watch.relative}\0`);
278
- const stat = lstatSync(absolute, { throwIfNoEntry: false });
279
- if (!stat) {
280
- hash.update('absent\0');
281
- } else if (watch.scope === 'store') {
282
- hash.update('store-present\0'); // Nix store paths are immutable; their names identify their contents.
283
- } else if (stat.isSymbolicLink()) {
284
- const target = readlinkSync(absolute);
285
- hash.update(`link\0${target}\0`);
286
- const resolved = realpathSync(absolute);
287
- if (!resolved.startsWith(`${root}/`) && !resolved.startsWith('/nix/store/')) {
288
- throw new Error(`watched link resolves outside isolated roots: ${absolute}`);
289
- }
290
- hash.update(readFileSync(resolved));
291
- } else if (stat.isFile()) {
292
- hash.update(`file\0${stat.mode & 0o111}\0${stat.size}\0`);
293
- hash.update(readFileSync(absolute));
294
- } else {
295
- throw new Error(`watched input is neither a file nor a missing path: ${absolute}`);
296
- }
297
- }
298
- return hash.digest('hex');
299
- }
300
-
301
- function graphBasis(dotfile: string): string {
302
- const gc = path.join(dotfile, 'gc');
303
- if (!lstatSync(dotfile).isDirectory() || !lstatSync(gc).isDirectory())
304
- throw new Error('devenv state or GC root is not a private directory');
305
- const graph = path.join(gc, 'task-config-devenv-config-task-config');
306
- const link = lstatSync(graph);
307
- if (
308
- !link.isSymbolicLink() ||
309
- !readlinkSync(graph).startsWith('/nix/store/') ||
310
- !realpathSync(graph).startsWith('/nix/store/')
311
- )
312
- throw new Error(`task graph is not a Nix store link: ${graph}`);
313
- return new Bun.CryptoHasher('sha256').update(readFileSync(graph)).digest('hex');
314
- }
315
-
316
- function readArtifact(file: string): Artifact | undefined {
317
- if (!lstatSync(file, { throwIfNoEntry: false })?.isFile()) return undefined;
318
- const value: unknown = JSON.parse(readFileSync(file, 'utf8'));
319
- if (
320
- typeof value !== 'object' ||
321
- value === null ||
322
- !('version' in value) ||
323
- value.version !== 1 ||
324
- !('root' in value) ||
325
- typeof value.root !== 'string' ||
326
- !('paths' in value) ||
327
- typeof value.paths !== 'object' ||
328
- value.paths === null ||
329
- Array.isArray(value.paths) ||
330
- !('basis' in value) ||
331
- !('graphBasis' in value) ||
332
- typeof value.graphBasis !== 'string' ||
333
- typeof value.basis !== 'string' ||
334
- !('watches' in value) ||
335
- !Array.isArray(value.watches) ||
336
- !('watchBasis' in value) ||
337
- typeof value.watchBasis !== 'string' ||
338
- !('toolchain' in value) ||
339
- typeof value.toolchain !== 'string' ||
340
- !('export' in value) ||
341
- typeof value.export !== 'string'
342
- )
343
- return undefined;
344
- const paths: Record<string, string> = {};
345
- for (const [name, entry] of Object.entries(value.paths)) {
346
- if (typeof entry !== 'string') return undefined;
347
- paths[name] = entry;
348
- }
349
- const watches: Watch[] = [];
350
- for (const entry of value.watches) {
351
- const watch: unknown = entry;
352
- if (
353
- typeof watch !== 'object' ||
354
- watch === null ||
355
- !('scope' in watch) ||
356
- (watch.scope !== 'root' &&
357
- watch.scope !== 'home' &&
358
- watch.scope !== 'runtime' &&
359
- watch.scope !== 'tmp' &&
360
- watch.scope !== 'store') ||
361
- !('relative' in watch) ||
362
- typeof watch.relative !== 'string'
363
- )
364
- return undefined;
365
- watches.push({ scope: watch.scope, relative: watch.relative });
366
- }
367
- return {
368
- version: 1,
369
- root: value.root,
370
- paths,
371
- basis: value.basis,
372
- graphBasis: value.graphBasis,
373
- watches,
374
- watchBasis: value.watchBasis,
375
- toolchain: value.toolchain,
376
- export: value.export,
377
- };
378
- }
379
-
380
- /** Check inherited data from this checkout only. A sibling cannot write this file or its GC roots. */
381
- function inherited(root: string, env: NodeJS.ProcessEnv, file: string): string | undefined {
382
- if (!lstatSync(path.dirname(file), { throwIfNoEntry: false })?.isDirectory()) return undefined;
383
- const artifact = readArtifact(file);
384
- if (!artifact) return undefined;
385
- if (
386
- artifact.basis !== sourceBasis(root) ||
387
- artifact.toolchain !== toolchain(privateEnvironment(env)) ||
388
- artifact.watchBasis !== watchedBasis(root, env, artifact.watches) ||
389
- artifact.graphBasis !== graphBasis(path.join(root, DEVENV_DIR, '.devenv'))
390
- )
391
- return undefined;
392
- const graph = enterShellTasks(path.join(root, DEVENV_DIR, '.devenv'));
393
- if (graph.kind !== 'confined') return undefined;
394
- const dotfile = path.join(root, DEVENV_DIR, '.devenv');
395
- const shell = path.join(dotfile, 'gc', 'shell');
396
- if (!lstatSync(shell, { throwIfNoEntry: false })?.isSymbolicLink()) return undefined;
397
- const target = readlinkSync(shell);
398
- if (!target.startsWith('/nix/store/') || !realpathSync(shell).startsWith('/nix/store/')) return undefined;
399
- const moves = relocations(artifact.root, artifact.paths, root, env);
400
- const registered = Bun.spawnSync(['nix-store', '--realise', target, '--add-root', shell], {
401
- env: privateEnvironment(env),
402
- stdout: 'ignore',
403
- stderr: 'inherit',
404
- });
405
- if (registered.exitCode !== 0) return undefined;
406
- const inputPaths = path.join(dotfile, 'input-paths.txt');
407
- if (existsSync(inputPaths)) {
408
- const staged = `${inputPaths}.${randomUUID()}`;
409
- writeFileSync(staged, relocate(readFileSync(inputPaths, 'utf8'), moves), { flag: 'wx' });
410
- renameSync(staged, inputPaths);
411
- }
412
- return `${relocate(artifact.export, moves)}\nunset DEVENV_TASK_FILE DEVENV_TASKS\n`;
413
- }
414
-
415
- interface Task {
416
- readonly name: string;
417
- readonly command: string | null;
418
- readonly before: readonly string[];
419
- readonly after: readonly string[];
420
- }
421
- function strings(value: unknown): value is string[] {
422
- return Array.isArray(value) && value.every((item): item is string => typeof item === 'string');
423
- }
424
- /** Classify the real graph emitted by devenv, not script text or source names. */
425
- function enterShellTasks(
426
- dotfile: string,
427
- ): { kind: 'confined'; names: ReadonlySet<string> } | { kind: 'writes'; reason: string } {
428
- const graph = path.join(dotfile, 'gc', 'task-config-devenv-config-task-config');
429
- let rows: unknown;
430
- try {
431
- rows = JSON.parse(readFileSync(graph, 'utf8'));
432
- } catch (error) {
433
- return { kind: 'writes', reason: `task graph ${graph}: ${String(error)}` };
434
- }
435
- if (!Array.isArray(rows)) return { kind: 'writes', reason: `${graph} is not a list of tasks` };
436
- const tasks = new Map<string, Task>();
437
- for (const row of rows) {
438
- const raw: unknown = row;
439
- if (
440
- typeof raw !== 'object' ||
441
- raw === null ||
442
- !('name' in raw) ||
443
- typeof raw.name !== 'string' ||
444
- !('command' in raw) ||
445
- (raw.command !== null && typeof raw.command !== 'string') ||
446
- !('before' in raw) ||
447
- !strings(raw.before) ||
448
- !('after' in raw) ||
449
- !strings(raw.after) ||
450
- tasks.has(raw.name)
451
- )
452
- return { kind: 'writes', reason: `${graph} has a malformed or duplicate task` };
453
- tasks.set(raw.name, { name: raw.name, command: raw.command, before: raw.before, after: raw.after });
454
- }
455
- if (!tasks.has('devenv:enterShell')) return { kind: 'writes', reason: `${graph} has no devenv:enterShell` };
456
- const pending = ['devenv:enterShell'];
457
- const closure = new Set<string>();
458
- for (let name = pending.pop(); name !== undefined; name = pending.pop()) {
459
- if (closure.has(name)) continue;
460
- const task = tasks.get(name);
461
- if (!task) return { kind: 'writes', reason: `${graph} depends on missing task ${name}` };
462
- closure.add(name);
463
- pending.push(...task.after);
464
- for (const candidate of tasks.values()) if (candidate.before.includes(name)) pending.push(candidate.name);
465
- }
466
- const writing = [...closure].filter((name) => {
467
- const task = tasks.get(name);
468
- return (
469
- task?.command !== null &&
470
- task?.command !== undefined &&
471
- name !== 'devenv:enterShell' &&
472
- name !== 'devenv:files:cleanup'
473
- );
474
- });
475
- return writing.length === 0
476
- ? { kind: 'confined', names: new Set(tasks.keys()) }
477
- : { kind: 'writes', reason: `enterShell runs ${writing.sort().join(', ')}, which write into its evaluation root` };
478
- }
479
-
480
- /** Expose only a credential-free evaluated shell to future private COW clones. */
481
- export function exportShell(rootPath: string, args: readonly string[], env: NodeJS.ProcessEnv): number {
482
- const root = realpathSync(rootPath);
483
- const cwd = path.join(root, DEVENV_DIR);
484
- if (args.at(-1) !== 'direnv-export') {
485
- const live = Bun.spawnSync(['devenv', ...args], {
486
- cwd,
487
- env,
488
- stdin: 'inherit',
489
- stdout: 'inherit',
490
- stderr: 'inherit',
491
- });
492
- return live.exitCode;
493
- }
494
- const local = ['.env', 'devenv.local.nix', 'devenv.local.yaml', 'devenv.local.yml'];
495
- const privateInputs =
496
- local.some((name) => existsSync(path.join(cwd, name))) ||
497
- (env.HOME && existsSync(path.join(env.HOME, '.config', 'nixpkgs')));
498
- const file = path.join(cwd, '.devenv', ARTIFACT);
499
- if (!privateInputs) {
500
- try {
501
- const cached = inherited(root, env, file);
502
- if (cached !== undefined) {
503
- process.stdout.write(cached);
504
- console.error("inherited devenv: reused this checkout's evaluated shell");
505
- return 0;
506
- }
507
- } catch (error) {
508
- console.error(`inherited devenv: private artifact cannot be used (${String(error)}); evaluating in place`);
509
- }
510
- }
511
- const safe = privateEnvironment(env);
512
- const dotfile = path.join(cwd, '.devenv');
513
- const live = (): number => {
514
- const evaluated = Bun.spawnSync(['devenv', ...args], {
515
- cwd,
516
- env,
517
- stdin: 'inherit',
518
- stdout: 'pipe',
519
- stderr: 'inherit',
520
- });
521
- if (evaluated.exitCode === 0) process.stdout.write(evaluated.stdout);
522
- return evaluated.exitCode;
523
- };
524
- if (privateInputs) {
525
- console.error('inherited devenv: checkout-local or home configuration; evaluating in place');
526
- return live();
527
- }
528
- try {
529
- const before = sourceBasis(root);
530
- const options = args.slice(0, -1);
531
- const disabled = [...options, '--option', 'enterShell:string', ''];
532
- const evaluate = (argv: readonly string[]) =>
533
- Bun.spawnSync(['devenv', ...argv], {
534
- cwd,
535
- env: safe,
536
- stdin: 'inherit',
537
- stdout: 'pipe',
538
- stderr: 'inherit',
539
- });
540
- const original = evaluate([...options, 'eval', 'enterShell']);
541
- const without = evaluate([...disabled, 'eval', 'enterShell']);
542
- if (original.exitCode !== 0 || without.exitCode !== 0)
543
- throw new Error('devenv cannot evaluate the merged hook without executing it');
544
- const hook: unknown = JSON.parse(original.stdout.toString());
545
- const empty: unknown = JSON.parse(without.stdout.toString());
546
- if (
547
- typeof hook !== 'object' ||
548
- hook === null ||
549
- !('enterShell' in hook) ||
550
- typeof hook.enterShell !== 'string' ||
551
- typeof empty !== 'object' ||
552
- empty === null ||
553
- !('enterShell' in empty) ||
554
- empty.enterShell !== ''
555
- )
556
- throw new Error('devenv did not prove the complete merged hook was disabled');
557
- const listed = evaluate([...disabled, 'tasks', 'list', '--json']);
558
- if (listed.exitCode !== 0) throw new Error('devenv cannot list the disabled task graph');
559
- const listing: unknown = JSON.parse(listed.stdout.toString());
560
- if (
561
- !Array.isArray(listing) ||
562
- listing.some(
563
- (entry: unknown) =>
564
- typeof entry !== 'object' || entry === null || !('name' in entry) || typeof entry.name !== 'string',
565
- )
566
- )
567
- throw new Error('devenv returned a malformed task listing');
568
- const graph = enterShellTasks(dotfile);
569
- if (graph.kind !== 'confined') throw new Error(graph.reason);
570
- const names = new Set(listing.map((entry: { name: string }) => entry.name));
571
- if (
572
- names.size !== listing.length ||
573
- names.size !== graph.names.size ||
574
- [...names].some((name) => !graph.names.has(name))
575
- )
576
- throw new Error('listed tasks differ from the compiled task graph');
577
- const planned = graphBasis(dotfile);
578
- const evaluated = evaluate([...disabled, 'direnv-export']);
579
- if (evaluated.exitCode !== 0) throw new Error(`devenv export exited ${evaluated.exitCode}`);
580
- if (planned !== graphBasis(dotfile)) throw new Error('task graph changed after preflight');
581
- const watches = watchPaths(root, safe);
582
- const after = sourceBasis(root);
583
- const version = toolchain(safe);
584
- if (before !== after || !version) throw new Error('evaluated inputs or toolchain changed');
585
- const exported = `${evaluated.stdout.toString()}\n${hook.enterShell}\nunset DEVENV_TASK_FILE DEVENV_TASKS\n`;
586
- const artifact: Artifact = {
587
- version: 1,
588
- root,
589
- paths: pathsOf(root, safe),
590
- basis: after,
591
- watches,
592
- watchBasis: watchedBasis(root, safe, watches),
593
- graphBasis: planned,
594
- toolchain: version,
595
- export: exported,
596
- };
597
- const staged = `${file}.${randomUUID()}`;
598
- writeFileSync(staged, `${JSON.stringify(artifact)}\n`, { mode: 0o600, flag: 'wx' });
599
- renameSync(staged, file);
600
- process.stdout.write(exported);
601
- return 0;
602
- } catch (error) {
603
- console.error(`inherited devenv: ${String(error)}; evaluating in place`);
604
- return live();
605
- }
606
- }
607
-
608
- if (import.meta.main) {
609
- const [root, ...args] = process.argv.slice(2);
610
- if (!root || args.length === 0) {
611
- console.error('inherited-devenv.ts: expected <project root> <devenv args…>');
612
- process.exit(2);
613
- }
614
- process.exitCode = exportShell(root, args, process.env);
615
- }
@@ -1,53 +0,0 @@
1
- # Managed by `smoo monorepo`. Sourced by devenv.smoo.nix's enterShell prologue
2
- # from the workspace root, naming the machine's shared caches root:
3
- #
4
- # . "$DEVENV_ROOT/shared-caches.sh" /private/cowshed/caches
5
- #
6
- # Where the Go and ttsc caches live. Every checkout on a cowshed host — the
7
- # host's own and every sandboxed workspace — reaches them through the one
8
- # literal path under the caches root. Keying the choice on $HOME split them:
9
- # a sandbox's HOME is private to the workspace, so each sandbox fell back to a
10
- # cold per-checkout cache while the host filled another one. Both Go caches
11
- # are content-addressed, so sharing them needs no patch — unlike Rust, Go keys
12
- # on content and flags rather than on where the files live. Without a caches
13
- # root, ttsc stays in-tree for the CI cache action while Go keeps its normal
14
- # per-user defaults. An inherited value always wins so CI can place any of
15
- # these caches itself. GOFLAGS carries -trimpath because it is Go's stable way
16
- # to keep absolute build paths out of the artifact, and unlike Rust's
17
- # trim-paths it costs no cache reuse.
18
- #
19
- # ttsc's plugin builds use the Go it bundles rather than ours, so the
20
- # repository's own Go work and ttsc's plugin builds are two toolchains by
21
- # construction. Placing both caches in the shared root is what keeps that from
22
- # costing a rebuild per workspace.
23
- #
24
- # TTSC_GO_CACHE_DIR and GOCACHE stay separate for ownership, not correctness:
25
- # both caches are content-addressed, so one directory would compile the same
26
- # bytes to the same entries. What sharing loses is an owner. ttsc reclaims a Go
27
- # build cache only when it resolved that directory itself — `ttsc clean` takes
28
- # the cache whose source is TTSC_GO_CACHE_DIR and never one whose source is a
29
- # user GOCACHE, which it treats as someone else's property. Pointing ttsc at
30
- # GOCACHE therefore produced a directory ttsc filled and no repository verb
31
- # could empty, measured at 35G. A dedicated directory gives ttsc's half back to
32
- # `ttsc clean` and leaves GOCACHE holding only Go work this repository does
33
- # itself.
34
- #
35
- # That buys ownership, not automatic GC: ttsc prunes opportunistically only
36
- # when it owns the whole cache root, which requires TTSC_CACHE_DIR unset, and a
37
- # pinned shared root is the point of this file. The trade is deliberate — one
38
- # warm cache every workspace shares, reclaimed by an explicit verb, over
39
- # per-workspace caches that self-trim. Go's own build cache trimming belongs to
40
- # the go command and still applies to both.
41
- smoo_caches_root="$1"
42
- if [ -d "$smoo_caches_root" ]; then
43
- export TTSC_CACHE_DIR="${TTSC_CACHE_DIR:-$smoo_caches_root/ttsc}"
44
- export GOCACHE="${GOCACHE:-$smoo_caches_root/go/build}"
45
- export GOMODCACHE="${GOMODCACHE:-$smoo_caches_root/go/mod}"
46
- mkdir -p "$GOCACHE" "$GOMODCACHE"
47
- else
48
- export TTSC_CACHE_DIR="${TTSC_CACHE_DIR:-$PWD/.cache/ttsc}"
49
- fi
50
- export TTSC_GO_CACHE_DIR="${TTSC_GO_CACHE_DIR:-$TTSC_CACHE_DIR/go-build}"
51
- mkdir -p "$TTSC_CACHE_DIR" "$TTSC_GO_CACHE_DIR"
52
- export GOFLAGS="${GOFLAGS:--trimpath}"
53
- unset smoo_caches_root
@@ -1,9 +0,0 @@
1
- /**
2
- * In-process plugin tests infer targets for temporary fixture workspaces. Nx's
3
- * daemon client answers file-index queries for the workspace this process
4
- * started in, never for the fixture root a query names, so a daemon-backed
5
- * glob would silently describe the wrong tree. With the daemon off, Nx builds
6
- * the index in process for the root each query names, as a CI run does.
7
- * Child Nx processes the tests spawn set NX_DAEMON themselves.
8
- */
9
- process.env.NX_DAEMON = 'false';