Skip to content

Commit f8bafa6

Browse files
committed
chore(policy): enforce no-fallbacks inside Nix dev shell; update scripts and shellHook
- Enforce reproducibility policy: when `IN_NIX_SHELL` is set, do not use online or ad‑hoc fallbacks. - scripts/md-mermaid-validate.sh: remove npx fallback inside Nix shell; outside shell still supports best‑effort npx with system Chrome/Chromium if available. - Justfile conf-schema-validate: if `ajv` is missing inside Nix shell, exit 127 with guidance to add `pkgs.nodePackages."ajv-cli"` to flake.nix; only use `npx` when outside the shell. - flake.nix shellHook: wrap `docson` helper to refuse npx fallback inside Nix shell and instruct adding a proper package; allow npx only outside shell. - Keep earlier Justfile documentation block describing the policy at the top. This converts the previous docs-only change into an enforced policy across our dev tooling.
1 parent 95c6674 commit f8bafa6

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

Justfile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
#
2+
# Nix Dev Shell Policy (reproducibility)
3+
# -------------------------------------
4+
# When running inside the Nix dev shell (environment variable `IN_NIX_SHELL` is set),
5+
# Just tasks and helper scripts MUST NOT use fallbacks such as `npx`, brew installs,
6+
# network downloads, or any ad-hoc tool bootstrap. If a required command is missing
7+
# in that context, the correct fix is to add it to `flake.nix` (devShell.buildInputs)
8+
# and re-enter the shell, not to fall back. Outside of the Nix shell, tasks may use
9+
# best-effort fallbacks for convenience, but scripts should gate them like:
10+
# if [ -n "$IN_NIX_SHELL" ]; then echo "missing <tool>; fix flake.nix" >&2; exit 127; fi
11+
# This keeps `nix develop` fully reproducible and prevents hidden network variability.
12+
113
# Run the test suite
214

315
test:
@@ -22,7 +34,11 @@ conf-schema-validate:
2234
if command -v ajv >/dev/null 2>&1; then
2335
AJV=ajv
2436
else
25-
echo "ajv not found; using npx ajv-cli (requires network)" >&2
37+
if [ -n "${IN_NIX_SHELL:-}" ]; then
38+
echo "Error: 'ajv' is missing inside Nix dev shell. Add pkgs.nodePackages.\"ajv-cli\" to flake.nix devShell inputs." >&2
39+
exit 127
40+
fi
41+
echo "ajv not found; falling back to 'npx ajv-cli' outside Nix shell (requires network)" >&2
2642
AJV='npx -y ajv-cli'
2743
fi
2844
for f in specs/schemas/*.json; do

flake.nix

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,23 @@
107107

108108
shellHook = ''
109109
echo "Agent workflow development environment loaded"
110-
# Provide a convenience function to launch Docson without global install
111-
docson () { npx -y docson "$@"; }
110+
# Provide a convenience function for Docson; no fallbacks in Nix shell
111+
docson () {
112+
if command -v docson >/dev/null 2>&1; then
113+
command docson "$@"
114+
return
115+
fi
116+
if [ -n "${IN_NIX_SHELL:-}" ]; then
117+
echo "Docson is not available in this Nix dev shell. Add it to flake.nix (or choose an alternative) — no fallbacks allowed." >&2
118+
return 127
119+
fi
120+
if command -v npx >/dev/null 2>&1; then
121+
npx -y docson "$@"
122+
else
123+
echo "Docson not found and npx unavailable. Install Docson or enter nix develop with it provisioned." >&2
124+
return 127
125+
fi
126+
}
112127
echo "Tip: run: docson -d ./specs/schemas # then open http://localhost:3000"
113128
# Ensure mermaid-cli (mmdc) uses system Chrome/Chromium when present
114129
if command -v chromium >/dev/null 2>&1; then

scripts/md-mermaid-validate.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ set -euo pipefail
55
if command -v mmdc >/dev/null 2>&1; then
66
MMDC_CMD="mmdc"
77
else
8-
# Fallback to npx if available (requires network on first run)
8+
# Inside a Nix dev shell we must not fallback; require fixing flake.nix
9+
if [[ -n "${IN_NIX_SHELL:-}" ]]; then
10+
echo "mmdc (mermaid-cli) not found in Nix dev shell. Fix flake.nix devShell inputs; no fallbacks allowed." >&2
11+
exit 127
12+
fi
13+
# Outside Nix shell: allow best-effort npx fallback with system Chrome/Chromium
914
if command -v npx >/dev/null 2>&1; then
1015
MMDC_CMD="npx -y @mermaid-js/mermaid-cli"
11-
# Prefer system Chrome/Chromium if present to avoid downloads
1216
for bin in chromium chromium-browser google-chrome google-chrome-stable; do
1317
if command -v "$bin" >/dev/null 2>&1; then
1418
export PUPPETEER_EXECUTABLE_PATH="$(command -v "$bin")"
@@ -17,12 +21,8 @@ else
1721
break
1822
fi
1923
done
20-
if [[ -z "${PUPPETEER_EXECUTABLE_PATH:-}" ]]; then
21-
echo "No system Chrome/Chromium found. Without nix develop this fallback requires network to download a headless browser via npx. If that's not possible here, either install Chrome and re-run, or enter 'nix develop'." >&2
22-
exit 127
23-
fi
2424
else
25-
echo "mmdc (mermaid-cli) not found and no npx fallback. Install via Nix dev shell or Node." >&2
25+
echo "mmdc (mermaid-cli) not found. Install mermaid-cli or run inside Nix dev shell." >&2
2626
exit 127
2727
fi
2828
fi

0 commit comments

Comments
 (0)