@smoothbricks/nx-plugin 0.4.26 → 0.4.28
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.
- package/README.md +994 -117
- package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
- package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
- package/dist/bin/smoo-nx-bound-failures.js +31 -0
- package/dist/bin/smoo-nx-cargo-hash.js +28 -3
- package/dist/bin/smoo-nx-exec.js +15 -73
- package/dist/bin/smoo-nx-failures.d.ts +3 -0
- package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
- package/dist/bin/smoo-nx-failures.js +3 -0
- package/dist/bin/smoo-nx-nextest-extract.js +3 -2
- package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
- package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
- package/dist/bin/smoo-nx-test-walks.js +34 -0
- package/dist/bounded-test-policy.d.ts +7 -1
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +101 -40
- package/dist/build-state-output-policy.d.ts +25 -0
- package/dist/build-state-output-policy.d.ts.map +1 -0
- package/dist/build-state-output-policy.js +64 -0
- package/dist/cargo-closure-input.d.ts +3 -2
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +16 -15
- package/dist/cargo-dev-profile.d.ts +37 -0
- package/dist/cargo-dev-profile.d.ts.map +1 -0
- package/dist/cargo-dev-profile.js +108 -0
- package/dist/cargo-source-hash.d.ts +43 -6
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +309 -73
- package/dist/cargo-toolchain-policy.d.ts +4 -0
- package/dist/cargo-toolchain-policy.d.ts.map +1 -1
- package/dist/cargo-toolchain-policy.js +5 -0
- package/dist/cargo-workspace.d.ts +101 -5
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +291 -10
- package/dist/cross-check-policy.d.ts +21 -3
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +24 -6
- package/dist/disk-command-policy.d.ts +7 -0
- package/dist/disk-command-policy.d.ts.map +1 -0
- package/dist/disk-command-policy.js +98 -0
- package/dist/ensure-built-receipt.d.ts +25 -0
- package/dist/ensure-built-receipt.d.ts.map +1 -0
- package/dist/ensure-built-receipt.js +261 -0
- package/dist/ensure-built-witness.d.ts +57 -0
- package/dist/ensure-built-witness.d.ts.map +1 -0
- package/dist/ensure-built-witness.js +412 -0
- package/dist/ensure-built.d.ts +207 -12
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +576 -202
- package/dist/eslint-file-set.d.ts +7 -0
- package/dist/eslint-file-set.d.ts.map +1 -0
- package/dist/eslint-file-set.js +12 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-pool.js +379 -0
- package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
- package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
- package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
- package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
- package/dist/executors/bounded-exec/disk-lease.js +91 -0
- package/dist/executors/bounded-exec/executor.d.ts +45 -2
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +447 -52
- package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
- package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
- package/dist/executors/bounded-exec/gateway-lease.js +143 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
- package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
- package/dist/executors/bounded-exec/progress.d.ts +35 -0
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
- package/dist/executors/bounded-exec/progress.js +79 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
- package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
- package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp.js +1528 -0
- package/dist/executors/bounded-exec/schema.d.ts +29 -11
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.d.ts +162 -0
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
- package/dist/executors/bounded-exec/verdict.js +318 -0
- package/dist/executors/shard-timings/executor.d.ts +14 -0
- package/dist/executors/shard-timings/executor.d.ts.map +1 -0
- package/dist/executors/shard-timings/executor.js +25 -0
- package/dist/executors/shard-timings/schema.d.ts +4 -0
- package/dist/executors/shard-timings/schema.d.ts.map +1 -0
- package/dist/executors/shard-timings/schema.js +1 -0
- package/dist/failure-summary.d.ts +5 -0
- package/dist/failure-summary.d.ts.map +1 -0
- package/dist/failure-summary.js +118 -0
- package/dist/generators/create-package/generator.d.ts.map +1 -1
- package/dist/generators/create-package/generator.js +6 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +370 -138
- package/dist/managed-files/ci-workflow.d.ts +13 -0
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +44 -13
- package/dist/managed-files/files.d.ts +7 -1
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +62 -8
- package/dist/managed-files/json-edit.d.ts +21 -0
- package/dist/managed-files/json-edit.d.ts.map +1 -0
- package/dist/managed-files/json-edit.js +295 -0
- package/dist/managed-files/managed-format.d.ts +33 -1
- package/dist/managed-files/managed-format.d.ts.map +1 -1
- package/dist/managed-files/managed-format.js +82 -2
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
- package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/managed-files/publish-workflow.js +231 -48
- package/dist/managed-files/tree.d.ts +5 -0
- package/dist/managed-files/tree.d.ts.map +1 -1
- package/dist/managed-files/tree.js +5 -3
- package/dist/manifest-hash.d.ts.map +1 -1
- package/dist/manifest-hash.js +2 -5
- package/dist/nextest-code-bound.d.ts +62 -0
- package/dist/nextest-code-bound.d.ts.map +1 -0
- package/dist/nextest-code-bound.js +154 -0
- package/dist/nextest-extraction.d.ts +24 -8
- package/dist/nextest-extraction.d.ts.map +1 -1
- package/dist/nextest-extraction.js +42 -7
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +3 -5
- package/dist/release-config-policy.d.ts.map +1 -1
- package/dist/release-config-policy.js +3 -5
- package/dist/runtime-input.d.ts +14 -0
- package/dist/runtime-input.d.ts.map +1 -0
- package/dist/runtime-input.js +15 -0
- package/dist/rust-tokens.d.ts +11 -0
- package/dist/rust-tokens.d.ts.map +1 -0
- package/dist/rust-tokens.js +81 -0
- package/dist/task-results.d.ts +6 -0
- package/dist/task-results.d.ts.map +1 -0
- package/dist/task-results.js +61 -0
- package/dist/test-program.d.ts +54 -0
- package/dist/test-program.d.ts.map +1 -0
- package/dist/test-program.js +292 -0
- package/dist/test-timings.d.ts +71 -0
- package/dist/test-timings.d.ts.map +1 -0
- package/dist/test-timings.js +393 -0
- package/dist/test-walk-policy.d.ts +103 -0
- package/dist/test-walk-policy.d.ts.map +1 -0
- package/dist/test-walk-policy.js +657 -0
- package/dist/testing.d.ts +177 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +824 -0
- package/dist/type-guards.d.ts +3 -0
- package/dist/type-guards.d.ts.map +1 -0
- package/dist/type-guards.js +4 -0
- package/dist/typecheck-test-policy.d.ts +8 -5
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +113 -100
- package/dist/workspace-config-policy.d.ts +8 -0
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +175 -63
- package/dist/workspace-index.d.ts +12 -0
- package/dist/workspace-index.d.ts.map +1 -0
- package/dist/workspace-index.js +17 -0
- package/dist/workspace-manifest.d.ts +37 -0
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/executors.json +5 -0
- package/loader.js +13 -11
- package/managed/raw/envrc +33 -67
- package/managed/raw/git-format-staged.yml +30 -35
- package/managed/raw/patches/nx@23.2.1.patch +3484 -0
- package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
- package/managed/raw/tooling/direnv/developer-links.ts +569 -11
- package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -93
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
- package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
- package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
- package/managed/raw/tooling/direnv/repo-path +14 -2
- package/managed/raw/tooling/direnv/setup-environment.ts +1146 -159
- package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
- package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
- package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
- package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
- package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
- package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
- package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
- package/managed/templates/github/actions/cache-nx/action.yml +1 -1
- package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
- package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
- package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
- package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
- package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
- package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
- package/managed/templates/github/workflows/managed-files.yml +1 -2
- package/nextest.toml +8 -41
- package/package.json +74 -12
- package/runtime-input.sh +81 -0
- package/src/__tests__/counted-cargo.ts +33 -14
- package/src/__tests__/fixture-nx-env.ts +111 -46
- package/src/__tests__/progress-clock.ts +43 -0
- package/src/__tests__/runtime-input.ts +23 -0
- package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
- package/src/bin/smoo-nx-bound-failures.ts +33 -0
- package/src/bin/smoo-nx-cargo-hash.ts +28 -3
- package/src/bin/smoo-nx-exec.ts +16 -74
- package/src/bin/smoo-nx-failures.ts +4 -0
- package/src/bin/smoo-nx-nextest-extract.ts +3 -2
- package/src/bin/smoo-nx-test-walks.ts +42 -0
- package/src/bounded-test-policy.test.ts +268 -21
- package/src/bounded-test-policy.ts +114 -42
- package/src/build-state-output-policy.test.ts +115 -0
- package/src/build-state-output-policy.ts +90 -0
- package/src/bun-bootstrap.test.ts +57 -3
- package/src/bun-file-packages.test.ts +47 -0
- package/src/cargo-closure-input.test.ts +138 -66
- package/src/cargo-closure-input.ts +17 -15
- package/src/cargo-dev-profile.ts +137 -0
- package/src/cargo-resolve-cache.test.ts +70 -1
- package/src/cargo-source-hash.test.ts +193 -97
- package/src/cargo-source-hash.ts +345 -68
- package/src/cargo-toolchain-policy.ts +6 -0
- package/src/cargo-workspace.test.ts +320 -0
- package/src/cargo-workspace.ts +336 -10
- package/src/cross-check-policy.test.ts +59 -1
- package/src/cross-check-policy.ts +25 -6
- package/src/disk-command-policy.test.ts +61 -0
- package/src/disk-command-policy.ts +107 -0
- package/src/ensure-built-receipt.test.ts +184 -0
- package/src/ensure-built-receipt.ts +263 -0
- package/src/ensure-built-witness.test.ts +344 -0
- package/src/ensure-built-witness.ts +252 -0
- package/src/ensure-built.test.ts +1036 -578
- package/src/ensure-built.ts +820 -224
- package/src/eslint-file-set.ts +9 -0
- package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
- package/src/executors/bounded-exec/cpu-pool.ts +417 -0
- package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
- package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
- package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
- package/src/executors/bounded-exec/disk-lease.ts +139 -0
- package/src/executors/bounded-exec/executor-host.test.ts +778 -0
- package/src/executors/bounded-exec/executor.test.ts +1116 -63
- package/src/executors/bounded-exec/executor.ts +565 -67
- package/src/executors/bounded-exec/gateway-lease.ts +176 -0
- package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
- package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
- package/src/executors/bounded-exec/progress.test.ts +79 -0
- package/src/executors/bounded-exec/progress.ts +118 -0
- package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
- package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
- package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
- package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
- package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
- package/src/executors/bounded-exec/ram-temp.ts +1918 -0
- package/src/executors/bounded-exec/schema.json +11 -5
- package/src/executors/bounded-exec/schema.ts +27 -11
- package/src/executors/bounded-exec/verdict.test.ts +440 -0
- package/src/executors/bounded-exec/verdict.ts +433 -0
- package/src/executors/shard-timings/executor.ts +36 -0
- package/src/executors/shard-timings/schema.json +21 -0
- package/src/executors/shard-timings/schema.ts +4 -0
- package/src/failure-summary.ts +119 -0
- package/src/generators/bounded-test-targets/generator.test.ts +4 -4
- package/src/generators/bun-test-tracing/generator.test.ts +2 -2
- package/src/generators/create-package/generator.test.ts +6 -0
- package/src/generators/create-package/generator.ts +6 -2
- package/src/host-controller-wiring.test.ts +31 -0
- package/src/index.test.ts +909 -295
- package/src/index.ts +441 -143
- package/src/linked-snapshots.nx.test.ts +172 -0
- package/src/managed-files/ci-workflow.ts +54 -13
- package/src/managed-files/files.ts +65 -9
- package/src/managed-files/forgejo-artifact.test.ts +395 -0
- package/src/managed-files/generator.test.ts +60 -1
- package/src/managed-files/json-edit.test.ts +216 -0
- package/src/managed-files/json-edit.ts +290 -0
- package/src/managed-files/managed-format-json.test.ts +308 -0
- package/src/managed-files/managed-format.ts +90 -2
- package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
- package/src/managed-files/publish-workflow.ts +285 -67
- package/src/managed-files/repo-path.test.ts +129 -0
- package/src/managed-files/trace-db-artifact.test.ts +7 -0
- package/src/managed-files/tree.ts +11 -3
- package/src/manifest-hash.ts +2 -6
- package/src/nextest-code-bound.test.ts +155 -0
- package/src/nextest-code-bound.ts +195 -0
- package/src/nextest-extraction.test.ts +37 -5
- package/src/nextest-extraction.ts +51 -9
- package/src/nextest-partitions.test.ts +427 -82
- package/src/nx-cache-bound.test.ts +5 -10
- package/src/nx-cache-restore-mtime.test.ts +170 -0
- package/src/nx-daemon-claim.test.ts +277 -0
- package/src/nx-daemon-idle-cpu.test.ts +81 -0
- package/src/nx-daemon-idle-policy.test.ts +51 -0
- package/src/nx-daemon-ignore-files.test.ts +210 -0
- package/src/nx-daemon-root-normalization.test.ts +105 -0
- package/src/nx-daemon-validity.test.ts +925 -0
- package/src/nx-dot-input-policy.test.ts +353 -0
- package/src/nx-failure-life-cycles.test.ts +207 -0
- package/src/nx-files-archive-racy.test.ts +97 -0
- package/src/nx-foreign-workspace-env.test.ts +329 -0
- package/src/nx-incomplete-run-summary.test.ts +70 -0
- package/src/nx-plugin-load-errors.test.ts +120 -0
- package/src/nx-project-resolution-cache.test.ts +176 -0
- package/src/nx-raw-inputs.test.ts +166 -0
- package/src/nx-resident-graph-workers.test.ts +7 -16
- package/src/nx-run-information.test.ts +118 -0
- package/src/nx-skipped-task-exit.test.ts +180 -0
- package/src/nx-state-location.test.ts +63 -0
- package/src/nx-store-resolution.test.ts +26 -25
- package/src/nx-task-graph-cycles.test.ts +148 -0
- package/src/nx-task-output-lease.test.ts +414 -0
- package/src/nx-use-local.test.ts +103 -0
- package/src/package-target-policy.ts +3 -6
- package/src/release-config-policy.ts +3 -6
- package/src/runtime-input.test.ts +215 -0
- package/src/runtime-input.ts +17 -0
- package/src/rust-tokens.ts +78 -0
- package/src/serial-group-wiring.test.ts +326 -0
- package/src/task-history-namespace.test.ts +87 -89
- package/src/task-results.test.ts +226 -0
- package/src/task-results.ts +75 -0
- package/src/test-program.test.ts +303 -0
- package/src/test-program.ts +341 -0
- package/src/test-timings.test.ts +240 -0
- package/src/test-timings.ts +311 -0
- package/src/test-walk-policy.test.ts +585 -0
- package/src/test-walk-policy.ts +731 -0
- package/src/testing.test.ts +509 -0
- package/src/testing.ts +922 -0
- package/src/type-guards.ts +4 -0
- package/src/typecheck-test-policy.test.ts +496 -11
- package/src/typecheck-test-policy.ts +137 -103
- package/src/workspace-config-policy.test.ts +212 -13
- package/src/workspace-config-policy.ts +101 -73
- package/src/workspace-index.ts +18 -0
- package/src/workspace-manifest.ts +41 -0
- package/test-timings.json +85 -30
- package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -665
- package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
|
@@ -1,665 +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
|
-
// Every path a cowshed workspace child is handed that an export can embed. Each
|
|
26
|
-
// is the sandbox's own (its private HOME, TMPDIR, XDG roots, direnv config), so
|
|
27
|
-
// a clone relocates the origin's value to its own.
|
|
28
|
-
const ENV_PATHS = [
|
|
29
|
-
'HOME',
|
|
30
|
-
'TMPDIR',
|
|
31
|
-
'XDG_RUNTIME_DIR',
|
|
32
|
-
'XDG_CONFIG_HOME',
|
|
33
|
-
'XDG_CACHE_HOME',
|
|
34
|
-
'XDG_DATA_HOME',
|
|
35
|
-
'XDG_STATE_HOME',
|
|
36
|
-
'DIRENV_CONFIG',
|
|
37
|
-
] as const;
|
|
38
|
-
// The evaluator sees exactly what a cowshed workspace child is handed and the
|
|
39
|
-
// evaluation needs, so an origin evaluated from a host shell and a clone agree:
|
|
40
|
-
// the bootstrap PATH, the private roots, and the live routing the evaluator
|
|
41
|
-
// fetches the lock's inputs with — the proxy endpoint (a cowshed workspace's
|
|
42
|
-
// userinfo is its own gateway token), its exclusions, the CA files, and the one
|
|
43
|
-
// NIX_CONFIG setting that is pure transport (`ssl-cert-file`, which outranks
|
|
44
|
-
// nix.conf). Nix's client cache is `$XDG_CACHE_HOME/nix`, which cowshed shares
|
|
45
|
-
// across workspaces. No login identity, locale, terminal, Xcode selection,
|
|
46
|
-
// other caller credential, gateway token, NIX_CONFIG line (`access-tokens`,
|
|
47
|
-
// `impure-env`, …) or ambient impure override reaches it: a tool the shell
|
|
48
|
-
// needs is the devenv's to declare. Routing belongs to the evaluating checkout
|
|
49
|
-
// only: an export that embeds any proxy value or its userinfo is never
|
|
50
|
-
// published. A live shell still runs with its exact caller env.
|
|
51
|
-
const EVALUATOR_ENV = [
|
|
52
|
-
'PATH',
|
|
53
|
-
'HOME',
|
|
54
|
-
'TMPDIR',
|
|
55
|
-
'XDG_RUNTIME_DIR',
|
|
56
|
-
'XDG_CONFIG_HOME',
|
|
57
|
-
'XDG_CACHE_HOME',
|
|
58
|
-
'XDG_DATA_HOME',
|
|
59
|
-
'XDG_STATE_HOME',
|
|
60
|
-
'DIRENV_CONFIG',
|
|
61
|
-
'NIX_SSL_CERT_FILE',
|
|
62
|
-
'SSL_CERT_FILE',
|
|
63
|
-
'NODE_EXTRA_CA_CERTS',
|
|
64
|
-
'GIT_SSL_CAINFO',
|
|
65
|
-
'NO_PROXY',
|
|
66
|
-
'no_proxy',
|
|
67
|
-
] as const;
|
|
68
|
-
/** cowshed's proxy endpoint; a value may carry credentials as URL userinfo. */
|
|
69
|
-
const PROXY_ENV = ['HTTP_PROXY', 'HTTPS_PROXY', 'http_proxy', 'https_proxy'] as const;
|
|
70
|
-
|
|
71
|
-
type Watch = { readonly scope: 'root' | 'home' | 'runtime' | 'tmp' | 'store'; readonly relative: string };
|
|
72
|
-
type Entry = {
|
|
73
|
-
readonly relative: string;
|
|
74
|
-
readonly kind: 'file' | 'link';
|
|
75
|
-
readonly executable?: boolean;
|
|
76
|
-
readonly target?: string;
|
|
77
|
-
};
|
|
78
|
-
interface Artifact {
|
|
79
|
-
readonly version: 1;
|
|
80
|
-
readonly root: string;
|
|
81
|
-
readonly paths: Readonly<Record<string, string>>;
|
|
82
|
-
readonly basis: string;
|
|
83
|
-
readonly graphBasis: string;
|
|
84
|
-
readonly watches: readonly Watch[];
|
|
85
|
-
readonly watchBasis: string;
|
|
86
|
-
readonly toolchain: string;
|
|
87
|
-
readonly export: string;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** NIX_CONFIG reduced to its last `ssl-cert-file`, read as nix reads it: `#` starts a comment. */
|
|
91
|
-
function nixTransportConfig(config: string | undefined): string | undefined {
|
|
92
|
-
let caFile: string | undefined;
|
|
93
|
-
for (const line of config?.split('\n') ?? []) {
|
|
94
|
-
const setting = /^\s*ssl-cert-file\s*=\s*(.*?)\s*$/.exec(line.split('#', 1)[0] ?? '');
|
|
95
|
-
if (setting) caFile = setting[1];
|
|
96
|
-
}
|
|
97
|
-
return caFile === undefined ? undefined : `ssl-cert-file = ${caFile}`;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function privateEnvironment(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
|
|
101
|
-
const selected: NodeJS.ProcessEnv = {};
|
|
102
|
-
for (const name of [...EVALUATOR_ENV, ...PROXY_ENV]) {
|
|
103
|
-
const value = env[name];
|
|
104
|
-
if (value !== undefined) selected[name] = value;
|
|
105
|
-
}
|
|
106
|
-
const transport = nixTransportConfig(env.NIX_CONFIG);
|
|
107
|
-
if (transport !== undefined) selected.NIX_CONFIG = transport;
|
|
108
|
-
return selected;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function percentDecoded(text: string): string {
|
|
112
|
-
try {
|
|
113
|
-
return decodeURIComponent(text);
|
|
114
|
-
} catch {
|
|
115
|
-
return text;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Whether `text` holds a proxy value of `env`, or the credential in its userinfo. A
|
|
121
|
-
* userinfo with a password is matched whole or by the password, never by the
|
|
122
|
-
* username alone: cowshed's username is the fixed label `cowshed`.
|
|
123
|
-
*/
|
|
124
|
-
export function embedsRouting(text: string, env: NodeJS.ProcessEnv): boolean {
|
|
125
|
-
const secrets: string[] = [];
|
|
126
|
-
for (const name of PROXY_ENV) {
|
|
127
|
-
const value = env[name];
|
|
128
|
-
if (!value) continue;
|
|
129
|
-
secrets.push(value);
|
|
130
|
-
const url = URL.parse(value);
|
|
131
|
-
if (url?.password) {
|
|
132
|
-
secrets.push(`${url.username}:${url.password}`, url.password, percentDecoded(url.password));
|
|
133
|
-
} else if (url?.username) {
|
|
134
|
-
secrets.push(url.username, percentDecoded(url.username));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return secrets.some((secret) => text.includes(secret));
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function toolchain(env: NodeJS.ProcessEnv): string | undefined {
|
|
141
|
-
const versions: string[] = [];
|
|
142
|
-
for (const command of [
|
|
143
|
-
['devenv', 'version'],
|
|
144
|
-
['nix', '--version'],
|
|
145
|
-
]) {
|
|
146
|
-
const result = Bun.spawnSync(command, { env, stdout: 'pipe', stderr: 'pipe' });
|
|
147
|
-
if (result.exitCode !== 0) return undefined;
|
|
148
|
-
versions.push(result.stdout.toString().trim());
|
|
149
|
-
}
|
|
150
|
-
return `${process.platform}/${process.arch}\n${versions.join('\n')}`;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/** devenv's runtime directory is keyed by the dotfile, not by DEVENV_RUNTIME. */
|
|
154
|
-
export function devenvRuntimeDir(xdg: string | undefined, dotfile: string): string {
|
|
155
|
-
const hash = new Bun.CryptoHasher('sha256').update(dotfile).digest('hex');
|
|
156
|
-
return path.join(xdg || '/tmp', `devenv-${hash.slice(0, 7)}`);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function pathsOf(root: string, env: NodeJS.ProcessEnv): Record<string, string> {
|
|
160
|
-
const paths: Record<string, string> = {};
|
|
161
|
-
for (const name of ENV_PATHS) {
|
|
162
|
-
const value = env[name];
|
|
163
|
-
if (value) paths[name] = value;
|
|
164
|
-
}
|
|
165
|
-
paths.DEVENV_RUNTIME = devenvRuntimeDir(env.XDG_RUNTIME_DIR, path.join(root, DEVENV_DIR, '.devenv'));
|
|
166
|
-
return paths;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export interface Relocation {
|
|
170
|
-
readonly from: string;
|
|
171
|
-
readonly to: string;
|
|
172
|
-
}
|
|
173
|
-
export function relocations(
|
|
174
|
-
origin: string,
|
|
175
|
-
originPaths: Readonly<Record<string, string>>,
|
|
176
|
-
root: string,
|
|
177
|
-
env: NodeJS.ProcessEnv,
|
|
178
|
-
): Relocation[] {
|
|
179
|
-
const current = pathsOf(root, env);
|
|
180
|
-
const moves: Relocation[] = [];
|
|
181
|
-
for (const [name, from] of Object.entries(originPaths)) {
|
|
182
|
-
const to = current[name];
|
|
183
|
-
if (to && from !== to) moves.push({ from, to });
|
|
184
|
-
}
|
|
185
|
-
moves.push({ from: origin, to: root });
|
|
186
|
-
moves.sort((left, right) => right.from.length - left.from.length);
|
|
187
|
-
return moves;
|
|
188
|
-
}
|
|
189
|
-
export function relocate(text: string, moves: readonly Relocation[]): string {
|
|
190
|
-
// Match only the original export: a replacement can itself start with HOME,
|
|
191
|
-
// especially when a host's checkout lives below HOME.
|
|
192
|
-
let cursor = 0;
|
|
193
|
-
let result = '';
|
|
194
|
-
while (cursor < text.length) {
|
|
195
|
-
let next = text.length;
|
|
196
|
-
let selected: Relocation | undefined;
|
|
197
|
-
for (const move of moves) {
|
|
198
|
-
if (!move.from) continue;
|
|
199
|
-
const found = text.indexOf(move.from, cursor);
|
|
200
|
-
if (found !== -1 && (found < next || (found === next && move.from.length > (selected?.from.length ?? 0)))) {
|
|
201
|
-
next = found;
|
|
202
|
-
selected = move;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
if (!selected) break;
|
|
206
|
-
result += text.slice(cursor, next) + selected.to;
|
|
207
|
-
cursor = next + selected.from.length;
|
|
208
|
-
}
|
|
209
|
-
return result + text.slice(cursor);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/** Local path inputs have Nix's layout; unknown YAML imports are not guessed. */
|
|
213
|
-
function pathInputs(root: string): string[] {
|
|
214
|
-
const dir = path.join(root, DEVENV_DIR);
|
|
215
|
-
const yaml = path.join(dir, 'devenv.yaml');
|
|
216
|
-
const document: unknown = Bun.YAML.parse(readFileSync(yaml, 'utf8'));
|
|
217
|
-
if (typeof document !== 'object' || document === null || Array.isArray(document))
|
|
218
|
-
throw new Error(`${yaml} is not a mapping`);
|
|
219
|
-
if ('imports' in document && Array.isArray(document.imports) && document.imports.length > 0) {
|
|
220
|
-
throw new Error(`${yaml} imports modules outside the captured inputs`);
|
|
221
|
-
}
|
|
222
|
-
const inputs = 'inputs' in document ? document.inputs : undefined;
|
|
223
|
-
const directories = new Set<string>();
|
|
224
|
-
for (const [name, input] of Object.entries(typeof inputs === 'object' && inputs !== null ? inputs : {})) {
|
|
225
|
-
const url: unknown = typeof input === 'object' && input !== null && 'url' in input ? input.url : undefined;
|
|
226
|
-
if (typeof url !== 'string' || !url.startsWith('path:')) continue;
|
|
227
|
-
const resolved = realpathSync(path.resolve(dir, url.slice(5)));
|
|
228
|
-
if (!resolved.startsWith(`${root}/`) || !statSync(resolved).isDirectory()) {
|
|
229
|
-
throw new Error(`path input ${name} is not a directory inside ${root}`);
|
|
230
|
-
}
|
|
231
|
-
const relative = path.relative(root, resolved);
|
|
232
|
-
if (relative !== DEVENV_DIR && !relative.startsWith(`${DEVENV_DIR}/`)) directories.add(relative);
|
|
233
|
-
}
|
|
234
|
-
return [...directories].sort();
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
function entriesUnder(
|
|
238
|
-
root: string,
|
|
239
|
-
relative: string,
|
|
240
|
-
followLinks: boolean,
|
|
241
|
-
entries: Entry[],
|
|
242
|
-
ancestors: ReadonlySet<string>,
|
|
243
|
-
): void {
|
|
244
|
-
const absolute = path.join(root, relative);
|
|
245
|
-
const stat = lstatSync(absolute);
|
|
246
|
-
if (stat.isSymbolicLink() && !followLinks) {
|
|
247
|
-
entries.push({ relative, kind: 'link', target: readlinkSync(absolute) });
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
const real = realpathSync(absolute);
|
|
251
|
-
if (!real.startsWith(`${root}/`)) throw new Error(`${absolute} resolves outside ${root}`);
|
|
252
|
-
if (ancestors.has(real)) throw new Error(`${absolute} links back into itself`);
|
|
253
|
-
const target = statSync(absolute);
|
|
254
|
-
if (target.isDirectory()) {
|
|
255
|
-
const inside = new Set(ancestors).add(real);
|
|
256
|
-
for (const name of readdirSync(absolute).sort()) {
|
|
257
|
-
if (relative === DEVENV_DIR && (name === '.devenv' || name === '.direnv')) continue;
|
|
258
|
-
entriesUnder(root, path.join(relative, name), followLinks, entries, inside);
|
|
259
|
-
}
|
|
260
|
-
} else if (target.isFile()) {
|
|
261
|
-
entries.push({ relative, kind: 'file', executable: (target.mode & 0o100) !== 0 });
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function sourceBasis(root: string): string {
|
|
266
|
-
const entries: Entry[] = [];
|
|
267
|
-
entriesUnder(root, DEVENV_DIR, true, entries, new Set());
|
|
268
|
-
for (const relative of pathInputs(root)) entriesUnder(root, relative, false, entries, new Set());
|
|
269
|
-
entries.sort((left, right) => left.relative.localeCompare(right.relative));
|
|
270
|
-
const hash = new Bun.CryptoHasher('sha256');
|
|
271
|
-
for (const entry of entries) {
|
|
272
|
-
if (entry.kind === 'link') {
|
|
273
|
-
hash.update(`link\0${entry.relative}\0${entry.target}\0`);
|
|
274
|
-
} else {
|
|
275
|
-
const bytes = readFileSync(path.join(root, entry.relative));
|
|
276
|
-
hash.update(`file\0${entry.relative}\0${entry.executable ? 'x' : '-'}\0${bytes.byteLength}\0`);
|
|
277
|
-
hash.update(bytes);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
return hash.digest('hex');
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
function watchPaths(root: string, env: NodeJS.ProcessEnv): Watch[] {
|
|
284
|
-
const inputPaths = readFileSync(path.join(root, DEVENV_DIR, '.devenv', 'input-paths.txt'), 'utf8');
|
|
285
|
-
const home = env.HOME;
|
|
286
|
-
const runtime = devenvRuntimeDir(env.XDG_RUNTIME_DIR, path.join(root, DEVENV_DIR, '.devenv'));
|
|
287
|
-
const tmp = env.TMPDIR || '/tmp';
|
|
288
|
-
const bases: readonly [Watch['scope'], string | undefined][] = [
|
|
289
|
-
['runtime', runtime],
|
|
290
|
-
['home', home],
|
|
291
|
-
['root', root],
|
|
292
|
-
['tmp', tmp],
|
|
293
|
-
['store', '/nix/store'],
|
|
294
|
-
];
|
|
295
|
-
const watches = new Map<string, Watch>();
|
|
296
|
-
for (const input of inputPaths.split('\n').filter(Boolean)) {
|
|
297
|
-
if (!path.isAbsolute(input)) throw new Error(`devenv input is not absolute: ${input}`);
|
|
298
|
-
const match = [...bases]
|
|
299
|
-
.sort((a, b) => (b[1]?.length ?? 0) - (a[1]?.length ?? 0))
|
|
300
|
-
.find(([, base]) => base && (input === base || input.startsWith(`${base}/`)));
|
|
301
|
-
if (!match || !match[1]) throw new Error(`devenv input is outside isolated roots: ${input}`);
|
|
302
|
-
const relative = path.relative(match[1], input);
|
|
303
|
-
const watch: Watch = { scope: match[0], relative };
|
|
304
|
-
watches.set(`${watch.scope}:${watch.relative}`, watch);
|
|
305
|
-
}
|
|
306
|
-
return [...watches.values()].sort((a, b) => `${a.scope}:${a.relative}`.localeCompare(`${b.scope}:${b.relative}`));
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
function watchedBasis(root: string, env: NodeJS.ProcessEnv, watches: readonly Watch[]): string {
|
|
310
|
-
const bases: Record<Watch['scope'], string> = {
|
|
311
|
-
root,
|
|
312
|
-
home: env.HOME ?? '',
|
|
313
|
-
runtime: devenvRuntimeDir(env.XDG_RUNTIME_DIR, path.join(root, DEVENV_DIR, '.devenv')),
|
|
314
|
-
tmp: env.TMPDIR || '/tmp',
|
|
315
|
-
store: '/nix/store',
|
|
316
|
-
};
|
|
317
|
-
const hash = new Bun.CryptoHasher('sha256');
|
|
318
|
-
for (const watch of watches) {
|
|
319
|
-
const base = bases[watch.scope];
|
|
320
|
-
if (!base) throw new Error(`missing ${watch.scope} for a watched devenv input`);
|
|
321
|
-
const absolute = path.resolve(base, watch.relative);
|
|
322
|
-
if (absolute !== base && !absolute.startsWith(`${base}/`)) throw new Error(`watch escapes ${watch.scope}`);
|
|
323
|
-
hash.update(`${watch.scope}:${watch.relative}\0`);
|
|
324
|
-
const stat = lstatSync(absolute, { throwIfNoEntry: false });
|
|
325
|
-
if (!stat) {
|
|
326
|
-
hash.update('absent\0');
|
|
327
|
-
} else if (watch.scope === 'store') {
|
|
328
|
-
hash.update('store-present\0'); // Nix store paths are immutable; their names identify their contents.
|
|
329
|
-
} else if (stat.isSymbolicLink()) {
|
|
330
|
-
const target = readlinkSync(absolute);
|
|
331
|
-
hash.update(`link\0${target}\0`);
|
|
332
|
-
const resolved = realpathSync(absolute);
|
|
333
|
-
if (!resolved.startsWith(`${root}/`) && !resolved.startsWith('/nix/store/')) {
|
|
334
|
-
throw new Error(`watched link resolves outside isolated roots: ${absolute}`);
|
|
335
|
-
}
|
|
336
|
-
hash.update(readFileSync(resolved));
|
|
337
|
-
} else if (stat.isFile()) {
|
|
338
|
-
hash.update(`file\0${stat.mode & 0o111}\0${stat.size}\0`);
|
|
339
|
-
hash.update(readFileSync(absolute));
|
|
340
|
-
} else {
|
|
341
|
-
throw new Error(`watched input is neither a file nor a missing path: ${absolute}`);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
return hash.digest('hex');
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
function graphBasis(dotfile: string): string {
|
|
348
|
-
const gc = path.join(dotfile, 'gc');
|
|
349
|
-
if (!lstatSync(dotfile).isDirectory() || !lstatSync(gc).isDirectory())
|
|
350
|
-
throw new Error('devenv state or GC root is not a private directory');
|
|
351
|
-
const graph = path.join(gc, 'task-config-devenv-config-task-config');
|
|
352
|
-
const link = lstatSync(graph);
|
|
353
|
-
if (
|
|
354
|
-
!link.isSymbolicLink() ||
|
|
355
|
-
!readlinkSync(graph).startsWith('/nix/store/') ||
|
|
356
|
-
!realpathSync(graph).startsWith('/nix/store/')
|
|
357
|
-
)
|
|
358
|
-
throw new Error(`task graph is not a Nix store link: ${graph}`);
|
|
359
|
-
return new Bun.CryptoHasher('sha256').update(readFileSync(graph)).digest('hex');
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
function readArtifact(file: string): Artifact | undefined {
|
|
363
|
-
if (!lstatSync(file, { throwIfNoEntry: false })?.isFile()) return undefined;
|
|
364
|
-
const value: unknown = JSON.parse(readFileSync(file, 'utf8'));
|
|
365
|
-
if (
|
|
366
|
-
typeof value !== 'object' ||
|
|
367
|
-
value === null ||
|
|
368
|
-
!('version' in value) ||
|
|
369
|
-
value.version !== 1 ||
|
|
370
|
-
!('root' in value) ||
|
|
371
|
-
typeof value.root !== 'string' ||
|
|
372
|
-
!('paths' in value) ||
|
|
373
|
-
typeof value.paths !== 'object' ||
|
|
374
|
-
value.paths === null ||
|
|
375
|
-
Array.isArray(value.paths) ||
|
|
376
|
-
!('basis' in value) ||
|
|
377
|
-
!('graphBasis' in value) ||
|
|
378
|
-
typeof value.graphBasis !== 'string' ||
|
|
379
|
-
typeof value.basis !== 'string' ||
|
|
380
|
-
!('watches' in value) ||
|
|
381
|
-
!Array.isArray(value.watches) ||
|
|
382
|
-
!('watchBasis' in value) ||
|
|
383
|
-
typeof value.watchBasis !== 'string' ||
|
|
384
|
-
!('toolchain' in value) ||
|
|
385
|
-
typeof value.toolchain !== 'string' ||
|
|
386
|
-
!('export' in value) ||
|
|
387
|
-
typeof value.export !== 'string'
|
|
388
|
-
)
|
|
389
|
-
return undefined;
|
|
390
|
-
const paths: Record<string, string> = {};
|
|
391
|
-
for (const [name, entry] of Object.entries(value.paths)) {
|
|
392
|
-
if (typeof entry !== 'string') return undefined;
|
|
393
|
-
paths[name] = entry;
|
|
394
|
-
}
|
|
395
|
-
const watches: Watch[] = [];
|
|
396
|
-
for (const entry of value.watches) {
|
|
397
|
-
const watch: unknown = entry;
|
|
398
|
-
if (
|
|
399
|
-
typeof watch !== 'object' ||
|
|
400
|
-
watch === null ||
|
|
401
|
-
!('scope' in watch) ||
|
|
402
|
-
(watch.scope !== 'root' &&
|
|
403
|
-
watch.scope !== 'home' &&
|
|
404
|
-
watch.scope !== 'runtime' &&
|
|
405
|
-
watch.scope !== 'tmp' &&
|
|
406
|
-
watch.scope !== 'store') ||
|
|
407
|
-
!('relative' in watch) ||
|
|
408
|
-
typeof watch.relative !== 'string'
|
|
409
|
-
)
|
|
410
|
-
return undefined;
|
|
411
|
-
watches.push({ scope: watch.scope, relative: watch.relative });
|
|
412
|
-
}
|
|
413
|
-
return {
|
|
414
|
-
version: 1,
|
|
415
|
-
root: value.root,
|
|
416
|
-
paths,
|
|
417
|
-
basis: value.basis,
|
|
418
|
-
graphBasis: value.graphBasis,
|
|
419
|
-
watches,
|
|
420
|
-
watchBasis: value.watchBasis,
|
|
421
|
-
toolchain: value.toolchain,
|
|
422
|
-
export: value.export,
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
/** Check inherited data from this checkout only. A sibling cannot write this file or its GC roots. */
|
|
427
|
-
function inherited(root: string, env: NodeJS.ProcessEnv, file: string): string | undefined {
|
|
428
|
-
if (!lstatSync(path.dirname(file), { throwIfNoEntry: false })?.isDirectory()) return undefined;
|
|
429
|
-
const artifact = readArtifact(file);
|
|
430
|
-
if (!artifact) return undefined;
|
|
431
|
-
if (
|
|
432
|
-
artifact.basis !== sourceBasis(root) ||
|
|
433
|
-
artifact.toolchain !== toolchain(privateEnvironment(env)) ||
|
|
434
|
-
artifact.watchBasis !== watchedBasis(root, env, artifact.watches) ||
|
|
435
|
-
artifact.graphBasis !== graphBasis(path.join(root, DEVENV_DIR, '.devenv'))
|
|
436
|
-
)
|
|
437
|
-
return undefined;
|
|
438
|
-
const graph = enterShellTasks(path.join(root, DEVENV_DIR, '.devenv'));
|
|
439
|
-
if (graph.kind !== 'confined') return undefined;
|
|
440
|
-
const dotfile = path.join(root, DEVENV_DIR, '.devenv');
|
|
441
|
-
const shell = path.join(dotfile, 'gc', 'shell');
|
|
442
|
-
if (!lstatSync(shell, { throwIfNoEntry: false })?.isSymbolicLink()) return undefined;
|
|
443
|
-
const target = readlinkSync(shell);
|
|
444
|
-
if (!target.startsWith('/nix/store/') || !realpathSync(shell).startsWith('/nix/store/')) return undefined;
|
|
445
|
-
const moves = relocations(artifact.root, artifact.paths, root, env);
|
|
446
|
-
const registered = Bun.spawnSync(['nix-store', '--realise', target, '--add-root', shell], {
|
|
447
|
-
env: privateEnvironment(env),
|
|
448
|
-
stdout: 'ignore',
|
|
449
|
-
stderr: 'inherit',
|
|
450
|
-
});
|
|
451
|
-
if (registered.exitCode !== 0) return undefined;
|
|
452
|
-
const inputPaths = path.join(dotfile, 'input-paths.txt');
|
|
453
|
-
if (existsSync(inputPaths)) {
|
|
454
|
-
const staged = `${inputPaths}.${randomUUID()}`;
|
|
455
|
-
writeFileSync(staged, relocate(readFileSync(inputPaths, 'utf8'), moves), { flag: 'wx' });
|
|
456
|
-
renameSync(staged, inputPaths);
|
|
457
|
-
}
|
|
458
|
-
return `${relocate(artifact.export, moves)}\nunset DEVENV_TASK_FILE DEVENV_TASKS\n`;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
interface Task {
|
|
462
|
-
readonly name: string;
|
|
463
|
-
readonly command: string | null;
|
|
464
|
-
readonly before: readonly string[];
|
|
465
|
-
readonly after: readonly string[];
|
|
466
|
-
}
|
|
467
|
-
function strings(value: unknown): value is string[] {
|
|
468
|
-
return Array.isArray(value) && value.every((item): item is string => typeof item === 'string');
|
|
469
|
-
}
|
|
470
|
-
/** Classify the real graph emitted by devenv, not script text or source names. */
|
|
471
|
-
function enterShellTasks(
|
|
472
|
-
dotfile: string,
|
|
473
|
-
): { kind: 'confined'; names: ReadonlySet<string> } | { kind: 'writes'; reason: string } {
|
|
474
|
-
const graph = path.join(dotfile, 'gc', 'task-config-devenv-config-task-config');
|
|
475
|
-
let rows: unknown;
|
|
476
|
-
try {
|
|
477
|
-
rows = JSON.parse(readFileSync(graph, 'utf8'));
|
|
478
|
-
} catch (error) {
|
|
479
|
-
return { kind: 'writes', reason: `task graph ${graph}: ${String(error)}` };
|
|
480
|
-
}
|
|
481
|
-
if (!Array.isArray(rows)) return { kind: 'writes', reason: `${graph} is not a list of tasks` };
|
|
482
|
-
const tasks = new Map<string, Task>();
|
|
483
|
-
for (const row of rows) {
|
|
484
|
-
const raw: unknown = row;
|
|
485
|
-
if (
|
|
486
|
-
typeof raw !== 'object' ||
|
|
487
|
-
raw === null ||
|
|
488
|
-
!('name' in raw) ||
|
|
489
|
-
typeof raw.name !== 'string' ||
|
|
490
|
-
!('command' in raw) ||
|
|
491
|
-
(raw.command !== null && typeof raw.command !== 'string') ||
|
|
492
|
-
!('before' in raw) ||
|
|
493
|
-
!strings(raw.before) ||
|
|
494
|
-
!('after' in raw) ||
|
|
495
|
-
!strings(raw.after) ||
|
|
496
|
-
tasks.has(raw.name)
|
|
497
|
-
)
|
|
498
|
-
return { kind: 'writes', reason: `${graph} has a malformed or duplicate task` };
|
|
499
|
-
tasks.set(raw.name, { name: raw.name, command: raw.command, before: raw.before, after: raw.after });
|
|
500
|
-
}
|
|
501
|
-
if (!tasks.has('devenv:enterShell')) return { kind: 'writes', reason: `${graph} has no devenv:enterShell` };
|
|
502
|
-
const pending = ['devenv:enterShell'];
|
|
503
|
-
const closure = new Set<string>();
|
|
504
|
-
for (let name = pending.pop(); name !== undefined; name = pending.pop()) {
|
|
505
|
-
if (closure.has(name)) continue;
|
|
506
|
-
const task = tasks.get(name);
|
|
507
|
-
if (!task) return { kind: 'writes', reason: `${graph} depends on missing task ${name}` };
|
|
508
|
-
closure.add(name);
|
|
509
|
-
pending.push(...task.after);
|
|
510
|
-
for (const candidate of tasks.values()) if (candidate.before.includes(name)) pending.push(candidate.name);
|
|
511
|
-
}
|
|
512
|
-
const writing = [...closure].filter((name) => {
|
|
513
|
-
const task = tasks.get(name);
|
|
514
|
-
return (
|
|
515
|
-
task?.command !== null &&
|
|
516
|
-
task?.command !== undefined &&
|
|
517
|
-
name !== 'devenv:enterShell' &&
|
|
518
|
-
name !== 'devenv:files:cleanup'
|
|
519
|
-
);
|
|
520
|
-
});
|
|
521
|
-
return writing.length === 0
|
|
522
|
-
? { kind: 'confined', names: new Set(tasks.keys()) }
|
|
523
|
-
: { kind: 'writes', reason: `enterShell runs ${writing.sort().join(', ')}, which write into its evaluation root` };
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
/** Expose only a credential-free evaluated shell to future private COW clones. */
|
|
527
|
-
export function exportShell(rootPath: string, args: readonly string[], env: NodeJS.ProcessEnv): number {
|
|
528
|
-
const root = realpathSync(rootPath);
|
|
529
|
-
const cwd = path.join(root, DEVENV_DIR);
|
|
530
|
-
if (args.at(-1) !== 'direnv-export') {
|
|
531
|
-
const live = Bun.spawnSync(['devenv', ...args], {
|
|
532
|
-
cwd,
|
|
533
|
-
env,
|
|
534
|
-
stdin: 'inherit',
|
|
535
|
-
stdout: 'inherit',
|
|
536
|
-
stderr: 'inherit',
|
|
537
|
-
});
|
|
538
|
-
return live.exitCode;
|
|
539
|
-
}
|
|
540
|
-
const local = ['.env', 'devenv.local.nix', 'devenv.local.yaml', 'devenv.local.yml'];
|
|
541
|
-
const privateInputs =
|
|
542
|
-
local.some((name) => existsSync(path.join(cwd, name))) ||
|
|
543
|
-
(env.HOME && existsSync(path.join(env.HOME, '.config', 'nixpkgs')));
|
|
544
|
-
const file = path.join(cwd, '.devenv', ARTIFACT);
|
|
545
|
-
if (!privateInputs) {
|
|
546
|
-
try {
|
|
547
|
-
const cached = inherited(root, env, file);
|
|
548
|
-
if (cached !== undefined) {
|
|
549
|
-
process.stdout.write(cached);
|
|
550
|
-
console.error("inherited devenv: reused this checkout's evaluated shell");
|
|
551
|
-
return 0;
|
|
552
|
-
}
|
|
553
|
-
} catch (error) {
|
|
554
|
-
console.error(`inherited devenv: private artifact cannot be used (${String(error)}); evaluating in place`);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
const safe = privateEnvironment(env);
|
|
558
|
-
const dotfile = path.join(cwd, '.devenv');
|
|
559
|
-
const live = (): number => {
|
|
560
|
-
const evaluated = Bun.spawnSync(['devenv', ...args], {
|
|
561
|
-
cwd,
|
|
562
|
-
env,
|
|
563
|
-
stdin: 'inherit',
|
|
564
|
-
stdout: 'pipe',
|
|
565
|
-
stderr: 'inherit',
|
|
566
|
-
});
|
|
567
|
-
if (evaluated.exitCode === 0) process.stdout.write(evaluated.stdout);
|
|
568
|
-
return evaluated.exitCode;
|
|
569
|
-
};
|
|
570
|
-
if (privateInputs) {
|
|
571
|
-
console.error('inherited devenv: checkout-local or home configuration; evaluating in place');
|
|
572
|
-
return live();
|
|
573
|
-
}
|
|
574
|
-
try {
|
|
575
|
-
const before = sourceBasis(root);
|
|
576
|
-
// Shared fetcher bytes are useful; a sibling-writable Nix eval cache must not supply shell code.
|
|
577
|
-
const options = [...args.slice(0, -1), '--nix-option', 'eval-cache', 'false'];
|
|
578
|
-
const disabled = [...options, '--option', 'enterShell:string', ''];
|
|
579
|
-
const evaluate = (argv: readonly string[]) =>
|
|
580
|
-
Bun.spawnSync(['devenv', ...argv], {
|
|
581
|
-
cwd,
|
|
582
|
-
env: safe,
|
|
583
|
-
stdin: 'inherit',
|
|
584
|
-
stdout: 'pipe',
|
|
585
|
-
stderr: 'inherit',
|
|
586
|
-
});
|
|
587
|
-
const original = evaluate([...options, 'eval', 'enterShell']);
|
|
588
|
-
const without = evaluate([...disabled, 'eval', 'enterShell']);
|
|
589
|
-
if (original.exitCode !== 0 || without.exitCode !== 0)
|
|
590
|
-
throw new Error('devenv cannot evaluate the merged hook without executing it');
|
|
591
|
-
const hook: unknown = JSON.parse(original.stdout.toString());
|
|
592
|
-
const empty: unknown = JSON.parse(without.stdout.toString());
|
|
593
|
-
if (
|
|
594
|
-
typeof hook !== 'object' ||
|
|
595
|
-
hook === null ||
|
|
596
|
-
!('enterShell' in hook) ||
|
|
597
|
-
typeof hook.enterShell !== 'string' ||
|
|
598
|
-
typeof empty !== 'object' ||
|
|
599
|
-
empty === null ||
|
|
600
|
-
!('enterShell' in empty) ||
|
|
601
|
-
empty.enterShell !== ''
|
|
602
|
-
)
|
|
603
|
-
throw new Error('devenv did not prove the complete merged hook was disabled');
|
|
604
|
-
const listed = evaluate([...disabled, 'tasks', 'list', '--json']);
|
|
605
|
-
if (listed.exitCode !== 0) throw new Error('devenv cannot list the disabled task graph');
|
|
606
|
-
const listing: unknown = JSON.parse(listed.stdout.toString());
|
|
607
|
-
if (
|
|
608
|
-
!Array.isArray(listing) ||
|
|
609
|
-
listing.some(
|
|
610
|
-
(entry: unknown) =>
|
|
611
|
-
typeof entry !== 'object' || entry === null || !('name' in entry) || typeof entry.name !== 'string',
|
|
612
|
-
)
|
|
613
|
-
)
|
|
614
|
-
throw new Error('devenv returned a malformed task listing');
|
|
615
|
-
const graph = enterShellTasks(dotfile);
|
|
616
|
-
if (graph.kind !== 'confined') throw new Error(graph.reason);
|
|
617
|
-
const names = new Set(listing.map((entry: { name: string }) => entry.name));
|
|
618
|
-
if (
|
|
619
|
-
names.size !== listing.length ||
|
|
620
|
-
names.size !== graph.names.size ||
|
|
621
|
-
[...names].some((name) => !graph.names.has(name))
|
|
622
|
-
)
|
|
623
|
-
throw new Error('listed tasks differ from the compiled task graph');
|
|
624
|
-
const planned = graphBasis(dotfile);
|
|
625
|
-
const evaluated = evaluate([...disabled, 'direnv-export']);
|
|
626
|
-
if (evaluated.exitCode !== 0) throw new Error(`devenv export exited ${evaluated.exitCode}`);
|
|
627
|
-
if (planned !== graphBasis(dotfile)) throw new Error('task graph changed after preflight');
|
|
628
|
-
const watches = watchPaths(root, safe);
|
|
629
|
-
const after = sourceBasis(root);
|
|
630
|
-
const version = toolchain(safe);
|
|
631
|
-
if (before !== after || !version) throw new Error('evaluated inputs or toolchain changed');
|
|
632
|
-
const exported = `${evaluated.stdout.toString()}\n${hook.enterShell}\nunset DEVENV_TASK_FILE DEVENV_TASKS\n`;
|
|
633
|
-
const artifact: Artifact = {
|
|
634
|
-
version: 1,
|
|
635
|
-
root,
|
|
636
|
-
paths: pathsOf(root, safe),
|
|
637
|
-
basis: after,
|
|
638
|
-
watches,
|
|
639
|
-
watchBasis: watchedBasis(root, safe, watches),
|
|
640
|
-
graphBasis: planned,
|
|
641
|
-
toolchain: version,
|
|
642
|
-
export: exported,
|
|
643
|
-
};
|
|
644
|
-
const serialized = `${JSON.stringify(artifact)}\n`;
|
|
645
|
-
if (embedsRouting(exported, safe) || embedsRouting(serialized, safe))
|
|
646
|
-
throw new Error("the evaluated shell embeds this checkout's proxy routing, which no clone may inherit");
|
|
647
|
-
const staged = `${file}.${randomUUID()}`;
|
|
648
|
-
writeFileSync(staged, serialized, { mode: 0o600, flag: 'wx' });
|
|
649
|
-
renameSync(staged, file);
|
|
650
|
-
process.stdout.write(exported);
|
|
651
|
-
return 0;
|
|
652
|
-
} catch (error) {
|
|
653
|
-
console.error(`inherited devenv: ${String(error)}; evaluating in place`);
|
|
654
|
-
return live();
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
if (import.meta.main) {
|
|
659
|
-
const [root, ...args] = process.argv.slice(2);
|
|
660
|
-
if (!root || args.length === 0) {
|
|
661
|
-
console.error('inherited-devenv.ts: expected <project root> <devenv args…>');
|
|
662
|
-
process.exit(2);
|
|
663
|
-
}
|
|
664
|
-
process.exitCode = exportShell(root, args, process.env);
|
|
665
|
-
}
|