Skip to content

fix: pin devshell cwd to git toplevel before env.bash#3

Merged
Mayeu merged 2 commits into
mainfrom
fix/entering-the-shell-should-create-dotfile-at-the-root
May 9, 2026
Merged

fix: pin devshell cwd to git toplevel before env.bash#3
Mayeu merged 2 commits into
mainfrom
fix/entering-the-shell-should-create-dotfile-at-the-root

Conversation

@Mayeu
Copy link
Copy Markdown
Owner

@Mayeu Mayeu commented May 6, 2026

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.

@Mayeu Mayeu self-assigned this May 6, 2026
Mayeu added 2 commits May 9, 2026 18:12
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.
@Mayeu Mayeu force-pushed the fix/entering-the-shell-should-create-dotfile-at-the-root branch from 855cf3f to 8286028 Compare May 9, 2026 16:12
@Mayeu Mayeu merged commit 51a2479 into main May 9, 2026
12 checks passed
@Mayeu Mayeu deleted the fix/entering-the-shell-should-create-dotfile-at-the-root branch May 9, 2026 17:30
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