Skip to content

Commit 7ac67bf

Browse files
committed
Simplify fix: use rm before echo + chmod
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 parent 5fb104b commit 7ac67bf

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/modules/tasks.nix

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,12 @@ in
210210
description = "Runs when entering the shell";
211211
exec = ''
212212
mkdir -p "$DEVENV_DOTFILE" || { echo "Failed to create $DEVENV_DOTFILE"; exit 1; }
213-
214-
# Write to temp file first, then use install to atomically replace.
215-
# This works even when the target is owned by another user (e.g., root),
216-
# as install unlinks and recreates the file.
217-
_tmp="$DEVENV_DOTFILE/load-exports.$$"
218-
printf '%s\n' "$DEVENV_TASK_ENV" >"$_tmp"
219-
install -m 755 "$_tmp" "$DEVENV_DOTFILE/load-exports"
220-
rm -f "$_tmp"
213+
# Remove first to handle case where file is owned by another user (e.g., root).
214+
# chmod would fail on such files, but rm + recreate works as long as we have
215+
# write permission on the directory.
216+
rm -f "$DEVENV_DOTFILE/load-exports" 2>/dev/null || true
217+
echo "$DEVENV_TASK_ENV" > "$DEVENV_DOTFILE/load-exports"
218+
chmod +x "$DEVENV_DOTFILE/load-exports"
221219
'';
222220
};
223221
"devenv:enterTest" = {

0 commit comments

Comments
 (0)