Skip to content

Fix "install: skipping file '/dev/stdin', as it was replaced while being copied" on MacOS#682

Merged
bbenne10 merged 1 commit into
nix-community:masterfrom
joshuataylor:change-install-chmod
Feb 8, 2026
Merged

Fix "install: skipping file '/dev/stdin', as it was replaced while being copied" on MacOS#682
bbenne10 merged 1 commit into
nix-community:masterfrom
joshuataylor:change-install-chmod

Conversation

@joshuataylor
Copy link
Copy Markdown
Contributor

  • MacOS 15.7.3 (24G419)
  • zsh 5.9,
  • nix (Determinate Nix 3.15.2) 2.33.1
  • direnv 2.37.1

Running:

direnv allow
direnv: loading ~/dev/foo/.envrc
direnv: using nix
install: skipping file '/dev/stdin', as it was replaced while being copied
direnv: nix-direnv: Using cached dev shell

Seems to be from commit: 01fdb24

Instead of using install, we use rm -f + cat + chmod, no longer a single command, but it works..

The rm -f handles the original issue (chmod failing when file is owned by another user) by removing the old file first so cat creates a new one owned by the current user.

Essentially , before:

# Use install -m instead of cat + chmod to atomically create the file with
# correct permissions. This works even when an existing file is owned by
# another user, as install unlinks and recreates the file.
install -m 755 /dev/stdin "${layout_dir}/bin/nix-direnv-reload" <<-EOF

After:

# Remove first to handle case where file is owned by a different user
rm -f "${layout_dir}/bin/nix-direnv-reload"
cat >"${layout_dir}/bin/nix-direnv-reload" <<-EOF

And after the heredoc closing EOF, chmod +x "${layout_dir}/bin/nix-direnv-reload".


Could be related to NixOS/nix#9330 ?


This now works as expected for me, but the weird part is that it seems to be fine on Linux, from my testing. I'm going to guess MacOS might still have the file open or something, especially if you use something like Kandji (enterprise MDM file scanning policy thing), but could also be an issue with antivirus if users use something like that (I don't, just another theory)?


Feel free to do whatever with this PR, change it, close it, go a different direction -- this fixed it for me.

…ing copied" on MacOS

Fixes:

```sh
direnv: loading ~/dev/foo/.envrc
direnv: using nix
install: skipping file '/dev/stdin', as it was replaced while being
copied
direnv: nix-direnv: Using cached dev shell
```

Seems to be from commit:
nix-community@01fdb24

Instead of using `install`, we use `rm -f` + `cat` + `chmod`, no longer
a single command, but it works..

> The rm -f handles the original issue (chmod failing when file is owned
by another user) by removing the old file first so cat creates a new one
owned by the current user.

Essentially , before:

```sh
# Use install -m instead of cat + chmod to atomically create the file
with
# correct permissions. This works even when an existing file is owned by
# another user, as install unlinks and recreates the file.
install -m 755 /dev/stdin "${layout_dir}/bin/nix-direnv-reload" <<-EOF
```

After:

```sh
# Remove first to handle case where file is owned by a different user
rm -f "${layout_dir}/bin/nix-direnv-reload"
cat >"${layout_dir}/bin/nix-direnv-reload" <<-EOF
```

And after the heredoc closing EOF, `chmod +x
"${layout_dir}/bin/nix-direnv-reload"`.

---

Could be related to NixOS/nix#9330 ?
@bbenne10
Copy link
Copy Markdown
Contributor

bbenne10 commented Feb 8, 2026

Thank you. Merging.

@bbenne10 bbenne10 added this pull request to the merge queue Feb 8, 2026
Merged via the queue into nix-community:master with commit c30a1f0 Feb 8, 2026
5 checks passed
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.

2 participants