fix: pin devshell cwd to git toplevel before env.bash#3
Merged
Mayeu merged 2 commits intoMay 9, 2026
Merged
Conversation
Running `nix develop` from a subdirectory caused PRJ_ROOT to be set to that subdir (devshell hardcodes PRJ_ROOT=$PWD when IN_NIX_SHELL=1) and made nixago materialize repo config files (.editorconfig, treefmt.toml, lefthook.yml, …) in the subdir, since nixago's hooks resolve output paths against $PWD. Wrap the devshell derivation's outer shellHook with a prelude that cd's to `git rev-parse --show-toplevel` before env.bash is sourced, and an epilogue that restores the invocation cwd for the interactive shell. Falls back to $PWD with a stderr warning when not in a git repo. The prelude runs before devshell's PRJ_ROOT=$PWD line, so PRJ_ROOT picks up the real root automatically; nixago's startup hook then materializes files at the right place. The user's interactive cwd is preserved.
Document the new git-toplevel cd-prelude in mkShell so users entering a devshell from a subdirectory understand why files end up at the repo root. Also update src/local and src/tests subflake locks to point at the previous fix commit (via .github/workflows/update-subflake.sh) so the dogfooded devshell uses the new behavior.
855cf3f to
8286028
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Running
nix developfrom a subdirectory caused PRJ_ROOT to be set to thatsubdir (devshell hardcodes PRJ_ROOT=$PWD when IN_NIX_SHELL=1) and made nixago
materialize repo config files (.editorconfig, treefmt.toml, lefthook.yml, …) in
the subdir, since nixago's hooks resolve output paths against $PWD.
Wrap the devshell derivation's outer shellHook with a prelude that cd's to
git rev-parse --show-toplevelbefore env.bash is sourced, and an epiloguethat restores the invocation cwd for the interactive shell. Falls back to
$PWD with a stderr warning when not in a git repo.
The prelude runs before devshell's PRJ_ROOT=$PWD line, so PRJ_ROOT picks up
the real root automatically; nixago's startup hook then materializes files
at the right place. The user's interactive cwd is preserved.