jetify-com / devbox

Instant, easy, and predictable development environments
https://www.jetify.com/devbox/
Apache License 2.0
8.8k stars 205 forks source link

Corepack symlinks are relative and not absolute (they break if you move the devbox to a different directory depth) #2304

Open foucist opened 1 month ago

foucist commented 1 month ago

What happened?

after moving devbox with corepack enabled to a different directory the following error appears after running devbox shell:

Internal Error: EEXIST: file already exists, symlink '../../../../../../../../nix/store/6njmhaghg7x19cra79g8ljvxcxr77sfq-nodejs-14.21.3/lib/node_modules/corepack/dist/pnpm.js' -> '/Users/foucist/nested/test-devbox/.devbox/virtenv/nodejs/corepack-bin/pnpm'
Error: EEXIST: file already exists, symlink '../../../../../../../../nix/store/6njmhaghg7x19cra79g8ljvxcxr77sfq-nodejs-14.21.3/lib/node_modules/corepack/dist/pnpm.js' -> '/Users/foucist/nested/test-devbox/.devbox/virtenv/nodejs/corepack-bin/pnpm'

It should affect any corepack-bin pnpm / pnpx / yarn / yarnpkg regardless of the version of nodejs/etc due to the relative linking to reach /nix folder.

Steps to reproduce

  1. mkdir test-devbox
  2. cat > devbox.json
    {
    "$schema":  "https://raw.githubusercontent.com/jetify-com/devbox/0.13.0/.schema/devbox.schema.json",
    "packages": ["nodejs@14"],
    "env": {
    "DEVBOX_COREPACK_ENABLED": "true"
    },
    "shell": {
    "init_hook": [
      "echo 'Welcome to devbox!' > /dev/null"
    ],
    "scripts": {
      "test": [
        "echo \"Error: no test specified\" && exit 1"
      ]
    }
    }
    }
  3. devbox shell
  4. exit
  5. cd ..
  6. mkdir nested
  7. mv test-devbox nested
  8. cd nested/test-devbox
  9. devbox shell

Command

shell

devbox.json

{
  "$schema":  "https://raw.githubusercontent.com/jetify-com/devbox/0.13.0/.schema/devbox.schema.json",
  "packages": ["nodejs@14"],
  "env": {
    "DEVBOX_COREPACK_ENABLED": "true"
  },
  "shell": {
    "init_hook": [
      "echo 'Welcome to devbox!' > /dev/null"
    ],
    "scripts": {
      "test": [
        "echo \"Error: no test specified\" && exit 1"
      ]
    }
  }
}

Devbox version

0.13.0

Nix version

2.24.7

What system does this bug occur on?

macOS (Intel)

Debug logs

No response

foucist commented 1 month ago

Fixing this bug might fix #1984

Looks like it's a corepack issue. The command corepack enable --install-directory .devbox/virtenv/nodejs/corepack-bin installs relative symlinks.