Skip to content

fix(ci): forward flake shellHook env in direnv preamble - #1183

Merged
c-vigo merged 3 commits into
devfrom
bugfix/1180-forward-shellhook-env
Jul 17, 2026
Merged

c-vigo merged 3 commits into
devfrom
bugfix/1180-forward-shellhook-env

Conversation

@c-vigo

@c-vigo c-vigo commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

What

Fixes #1180. In direnv mode the setup-devkit-toolchain preamble exported the
dev-shell store bin dirs to GITHUB_PATH but dropped everything a project's
flake shellHook exports, so env defaults present in every local
nix develop/direnv session silently vanished on CI — a local-vs-CI divergence
that surfaced as unrelated tool errors (vig-os/org-config#40: a shellHook-seeded
OTTERDOG_TOKEN placeholder worked locally, failed on CI).

The preamble now forwards the flake shellHook environment to CI by default,
sanitized
(the approved design).

Approach — env-diff + denylist

  • Capture: snapshot the ambient runner env (env -0) and the dev-shell env
    (nix develop --command env -0, so the shellHook has already run), both
    null-delimited so newlines/special chars survive.
  • Diff: forward only the vars the dev-shell adds or changes. The ambient
    diff is the security boundary — host secrets already in the runner env are
    unchanged inside the shell, so they are never re-emitted into GITHUB_ENV.
  • Denylist: never forward shell session state (PATH — already handled via
    GITHUB_PATH — HOME, USER, LOGNAME, SHELL, TERM, PWD, OLDPWD,
    SHLVL, IFS, TMPDIR/TMP/TEMP/TEMPDIR) or Nix/stdenv build machinery
    (NIX_*, out, outputs, src, stdenv, system, builder, name,
    pname, version, shell, shellHook, buildInputs, nativeBuildInputs,
    propagated*BuildInputs, deps*, *Phase, phases, dont*,
    configureFlags/cmakeFlags/mesonFlags/makeFlags, patches, strictDeps,
    SOURCE_DATE_EPOCH, HOST_PATH, outputHash*, …).
  • Write: each forwarded var uses a random GITHUB_ENV heredoc delimiter, so
    multi-line and special-character values cannot break GITHUB_ENV parsing.

Why env-diff, not nix print-dev-env

nix print-dev-env dumps the full stdenv build machinery (phases, buildInputs,
stdenv, out, …), none of which belongs in a CI environment — separating a
project's genuine shellHook exports from that noise still needs a diff and a
denylist. The env-diff (outside vs inside the dev shell) isolates exactly the
dev-shell's contribution, and the denylist removes the build machinery that the
shell layers on top. Cleaner and more robust than parsing print-dev-env.

Contained to the direnv step (if: inputs.mode == 'direnv'); container and bare
modes are untouched.

Tests / evidence

New tests/test_setup_toolchain_env.py executes the step's real run:
script against a stubbed nix that emits a simulated dev-shell env (same
executed-bash pattern as test_ci_runner.py):

  • scalar shellHook exports (OTTERDOG_TOKEN, PROJECT_GREETING) reach
    GITHUB_ENV;
  • a multi-line value survives intact via the heredoc;
  • 15 denylisted names (build machinery + session state) are never forwarded;
  • a var unchanged from the ambient env is not re-forwarded (host-secret
    boundary).

18 passed; full prek run --all-files green; manual shellcheck of the step's
run script clean (only pre-existing SC2016 info notes on the existing
single-quoted nix develop captures).

Scope

Minimal diff: the direnv step, a new test, changelog (+ synced .devcontainer
mirror), and a MIGRATION.md subsection. The LD_LIBRARY_PATH/native-wheel issue
(#1181) is deliberately untouched; justfile.base untouched.

Refs: #1180, vig-os/org-config#40

c-vigo added 3 commits July 17, 2026 14:23
Add executed-bash coverage for the setup-devkit-toolchain direnv step: a
stubbed nix emits a simulated dev-shell environment, and the test asserts
shellHook exports reach GITHUB_ENV (scalar + multi-line heredoc) while shell
session state and Nix/stdenv build machinery stay denied and unchanged ambient
vars are never re-forwarded. Fails today because the step forwards PATH only.

Refs: #1180
The direnv-mode setup-devkit-toolchain step exported the dev-shell store bin
dirs to GITHUB_PATH but dropped everything the flake shellHook exports, so env
defaults present in every local nix develop/direnv session silently vanished on
CI (vig-os/org-config#40). Diff the ambient environment against the dev-shell
environment (the shellHook has run inside nix develop) and forward the vars the
dev-shell adds or changes to GITHUB_ENV, minus a denylist of shell session
state and Nix/stdenv build machinery. Null-delimited env dumps plus a random
GITHUB_ENV heredoc delimiter keep multi-line values intact; the ambient diff
keeps host secrets out of GITHUB_ENV.

Refs: #1180
Add the Unreleased changelog entry (synced to the .devcontainer mirror) and a
MIGRATION.md subsection describing the default shellHook env forwarding, the
ambient diff that keeps host secrets out of GITHUB_ENV, the session/build
machinery denylist, and why the diff-plus-denylist approach beats forwarding
nix print-dev-env wholesale.

Refs: #1180
@c-vigo
c-vigo merged commit 972e74b into dev Jul 17, 2026
13 checks passed
@c-vigo
c-vigo deleted the bugfix/1180-forward-shellhook-env branch July 17, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant