fix: chmod permission error when nix-direnv-reload owned by different user#647
Merged
Merged
Conversation
…user Use `install -m 755` instead of separate cat + chmod to atomically create the file with correct permissions. This works even when an existing file is owned by another user (e.g., root), as install unlinks and recreates the file. Assisted-By: claude-opus-4-5-20251101 via Claude Code
Contributor
|
Has this fix been tested on Darwin? I worry about its options not matching a nixos or Linux provided binaries. |
Contributor
Author
Good point. I ran some tests and found this to be a darwin-compatible version: # Good (tested on Linux + macOS)
install -m 755 /dev/stdin "$target" <<'EOF'
...
EOFAnother option would be to just remove the file (did that for devenv) - but I wasn't sure if that would maybe reset other kinds of permissions. (But the file is created by "us" anyways, right? so we could just remove and recreate?) |
tennox
added a commit
to tennox/devenv
that referenced
this pull request
Dec 12, 2025
The previous pipe-based approach (printf | install /dev/stdin) doesn't work reliably on macOS. Use temp file + install instead, which: - Preserves exact contents of DEVENV_TASK_ENV (no shell expansion) - Fixes file-owned-by-another-user problem (install recreates) - Works on both Linux and macOS See: nix-community/nix-direnv#647 (comment) Assisted-By: claude-opus-4-5-20251101 via Claude Code
tennox
added a commit
to tennox/devenv
that referenced
this pull request
Dec 12, 2025
The pipe-based `echo | install /dev/stdin` approach doesn't work reliably on macOS (piping to /dev/stdin fails on Darwin). Simply removing the file first achieves the same result: rm succeeds on files owned by other users (only needs directory write permission), then echo + chmod work on the newly created file we own. See: nix-community/nix-direnv#647 (comment) Assisted-By: claude-opus-4-5-20251101 via Claude Code
1 task
Contributor
|
Let's just do this the same way as you implemented it for devenv, please. Just |
Mic92
reviewed
Dec 30, 2025
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.
Summary
Fix
chmod: Operation not permittederror whennix-direnv-reloadfile is owned by adifferent user (e.g., a colleague entered direnv first).
Problem
chmodcannot change permissions on a file owned by another user.Solution
Use
install -m 755 /dev/stdininstead of separatecat+chmod. Theinstallcommandunlinks and recreates the file rather than modifying it in place, which works even when the
existing file is owned by another user.
Test
Add this to
.envrc: