Skip to content

Commit 5fb104b

Browse files
committed
Use temp file + install pattern for Darwin compatibility
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
1 parent e2d633a commit 5fb104b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/modules/tasks.nix

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,14 @@ in
210210
description = "Runs when entering the shell";
211211
exec = ''
212212
mkdir -p "$DEVENV_DOTFILE" || { echo "Failed to create $DEVENV_DOTFILE"; exit 1; }
213-
echo "$DEVENV_TASK_ENV" | install -m 755 /dev/stdin "$DEVENV_DOTFILE/load-exports"
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"
214221
'';
215222
};
216223
"devenv:enterTest" = {

0 commit comments

Comments
 (0)