cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
3.56k stars 259 forks source link

TMPDIR is set to null #255

Closed shyim closed 1 year ago

shyim commented 1 year ago

Describe the bug

When you switch your process implementation a different one, MySQL and PHP are broken.

The issue is that TMPDIR is set to string null. This seems not to happen with the default implementation, as it sources variables from a file.

domenkozar commented 1 year ago

cc @thenonameguy

thenonameguy commented 1 year ago

Please define which implementation works and which doesn't.

The process-compose example works for me with Postgres.

shyim commented 1 year ago

Can you try process-compose with MySQL?

process.implementation = "process-compose";
services.mysql.enable = true;
shyim commented 1 year ago

Okay now I can't reproduce it anymore. wtff

shyim commented 1 year ago

Sooo I guess I can reproduce it now. I simplified it a lot to make it easier

# foo.sh
export NIX_BUILD_TOP="$(mktemp -d -t nix-shell.XXXXXX)"
export TMP="$NIX_BUILD_TOP"
export TMPDIR="$NIX_BUILD_TOP"
export TEMP="$NIX_BUILD_TOP"
export TEMPDIR="$NIX_BUILD_TOP"

# Remove all the unnecessary noise that is set by the build env
unset NIX_BUILD_TOP NIX_BUILD_CORES NIX_STORE
unset TEMP TEMPDIR TMP TMPDIR
# .envrc
eval "$(cat foo)"
❯ direnv allow
direnv: loading ~/Code/test/.envrc
direnv: export +A -TMPDIR

It adjusts the TMPDIR to null.

I have already a TMPDIR before I join the folder. Maybe thats the real difference?

❯ echo $TMPDIR
/var/folders/h4/wz89kr5928d_1c8zsmlry3s40000gn/T/
shyim commented 1 year ago

Yep without the global TMPDIR variable i cannot reproduce it anymore.

shyim in ~/Code
❯ set -e TMPDIR

shyim in ~/Code
❯ cd test/
direnv: loading ~/Code/test/.envrc

I guess direnv compares the environment variables to find out the difference?

shyim commented 1 year ago

Maybe also relates to this in Nix? https://github.com/NixOS/nix/blob/8c52f8ea9db6aba495bff7c9b7511a5a5420efab/src/libmain/shared.cc#L234

domenkozar commented 1 year ago

Could you create a gist to reproduce? I'm not able to follow your snippets :)

shyim commented 1 year ago

better? :) https://gist.github.com/shyim/570e7eabb39bae690714f9167fa6fa1e

TLDR: When the terminal already have a TMPDIR set, it gets overridden to null .

domenkozar commented 1 year ago

What is the global value of TMPDIR you have?

domenkozar commented 1 year ago

Looks like another problem that can be avoided by implementing #240

shyim commented 1 year ago

/var/folders/qg/s5jp5ffx2p1fxv0hy2l_p3hm0000gn/ seems like

shyim commented 1 year ago

We could remove unsetting TMPDIR only on Darwin until #240. What do you think about it?

domenkozar commented 1 year ago

I can prepare a PR for removing https://github.com/NixOS/nix/blob/8c52f8ea9db6aba495bff7c9b7511a5a5420efab/src/libmain/shared.cc#L234 and let's see

shyim commented 1 year ago

If I understand the code when TMPDIR is /var/folders or /tmp it unsets it.

Changed it for my shell and makes no difference:

shyim in ~/Code
❯ echo $TMPDIR
/Users/shyim/Downloads/

shyim in ~/Code
❯ cd platform/
direnv: loading ~/Code/platform/.envrc
direnv: export +APP_SECRET +APP_URL +CYPRESS_baseUrl +CYPRESS_dbHost +CYPRESS_dbName +CYPRESS_dbPassword +CYPRESS_dbUser +C_INCLUDE_PATH +DATABASE_URL +DEVENV_DOTFILE +DEVENV_PROFILE +DEVENV_ROOT +DEVENV_STATE +INSTALL_URL +IN_NIX_SHELL +LD_LIBRARY_PATH +LIBRARY_PATH +MAILER_URL +MYSQL_HOME +MYSQL_UNIX_PORT +NIXPKGS_ALLOW_UNFREE +PHPFPMDIR +PKG_CONFIG_PATH +REDISDATA +name ~PATH ~TMPDIR ~XDG_CONFIG_DIRS ~XDG_DATA_DIRS

shyim in platform on  next-24090/new-updater [!⇕] via  v18.12.1 via 🐘 v8.1.13 via ❄️  impure (devenv-shell)
❯ echo $TMPDIR
null