Shell snapshot drops Nix `PATH` entries while preserving `__ETC_PROFILE_NIX_SOURCED=1`, causing commands to disappear in `bash -lc`
What version of Codex CLI is running?
codex-cli 0.116.0
What subscription do you have?
Plus
Which model were you using?
gpt-5.4
What platform is your computer?
Linux 6.12.74+deb13+1-amd64 x86_64 unknown
What terminal emulator and version are you using (if applicable)?
_No response_
What issue are you seeing?
In Codex 0.116.0, commands installed via Nix are available to the parent Codex process, but unavailable to tool commands executed through bash -lc.
The shell snapshot appears to serialize an inconsistent environment:
- it preserves
NIX_PROFILES - it preserves
__ETC_PROFILE_NIX_SOURCED=1 - but it rewrites
PATHto only system directories
Because of that, later shell startup does not restore Nix paths: /etc/profile.d/nix.sh runs, but its delegated script exits early because __ETC_PROFILE_NIX_SOURCED is already set.
What steps can reproduce the bug?
- Start Codex in a Nix-based shell environment where the parent process
PATHincludes Nix profile bins. - Run a tool command through Codex such as:
command -v rg
- Observe that it fails.
- Inspect the generated shell snapshot and compare its
PATHto the parent process environment.
What is the expected behavior?
Commands available in the parent Codex environment should remain available in tool shell commands.
At minimum, if the snapshot preserves __ETC_PROFILE_NIX_SOURCED=1, it should also preserve the corresponding Nix-modified PATH.
Actual
The parent process has the correct Nix PATH, but the generated shell snapshot contains a reduced PATH. As a result, commands installed in the Nix profile are not found from bash -lc.
Example symptom:
command -v rg
# exits non-zero
Additional information
Evidence
Parent sandbox process environment includes Nix paths:
PATH=/tmp/codex-arg0/...:/nix/store/...-ripgrep-15.1.0/bin:/home/<user>/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/bin:...
NIX_PROFILES=/nix/var/nix/profiles/default /home/<user>/.nix-profile
__ETC_PROFILE_NIX_SOURCED=1
SHELL=/home/<user>/.nix-profile/bin/fish
Generated shell snapshot contains:
declare -x NIX_PROFILES="/nix/var/nix/profiles/default /home/<user>/.nix-profile"
declare -x PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
declare -x SHELL="/home/<user>/.nix-profile/bin/fish"
declare -x __ETC_PROFILE_NIX_SOURCED="1"
Then bash -x -lc true shows shell init loading Nix startup, but it short-circuits immediately:
+ . /etc/profile.d/nix.sh
++ . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
+++ '[' -n 1 ']'
+++ return
So the shell snapshot has already made the environment inconsistent before command execution begins.
Likely root cause
The shell snapshot generator is reconstructing or sanitizing PATH incorrectly while preserving related Nix environment variables verbatim.
Suggested fix
One of:
- Preserve the actual inherited
PATHin the shell snapshot. - Do not preserve
__ETC_PROFILE_NIX_SOURCEDunless the snapshot also preserves the matching NixPATH. - Recompute the environment in a way that keeps Nix init state internally consistent.
Workaround
A local shell workaround is to prepend the Nix profile bin explicitly in user startup files, but this looks like a Codex environment snapshot bug rather than a user shell configuration problem.
2 Comments
Same issue with flox. Codex gets flox env vars like FLOX_ENV but doesn't have the updated PATH from
flox activateI put together a fix for this on my fork:
fix/shell-snapshot-inherited-pathe78e14cRoot cause I confirmed locally:
PATHbefore the script gets controlPATHalongside inherited activation markers like__ETC_PROFILE_NIX_SOURCED=1(and similarlyFLOX_ENV-style state), which leaves the snapshot internally inconsistentThe fix here is to preserve the actual inherited parent-process
PATH, not the login-shell-rewritten one:PATHinto an internal env var before spawning the snapshot shellPATHfrom that internal value when serializing exports forbash/zsh/sh.bash_profilerewritingPATHwhile keeping__ETC_PROFILE_NIX_SOURCED=1This should address the flox follow-up too, because the behavior is no longer Nix-specific; it preserves the parent session's command lookup path instead of trusting a fallback login shell's reconstruction of it.
Validation I ran:
just fmt.bash_profilerewritesPATHto system dirs, the generated snapshot still preserves the inherited Nix-stylePATHand keeps__ETC_PROFILE_NIX_SOURCED=1PWD, invalid names, andNEXTEST_BIN_EXE_*, and the internal helper env var does not leak into the snapshotgit diff --checkI also attempted:
cargo test -p codex-core shell_snapshot_tests::bash_snapshot_preserves_inherited_path_across_login_init -- --exactI retried that 4 times with a 60s hard timeout, but on this machine each run stayed in
codex-corecompilation and never reached the test body before timing out, so I can't honestly claim a localcargo testpass yet.Per the current contributing guidelines (
docs/contributing.mdsays external contributions are by invitation only), I'm not opening an upstream PR uninvited. If you'd like this as a PR, I can open it immediately once invited.