-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extension Prevents .envrc
being loaded in terminal.
#561
Comments
How are you determining that the .envrc isn't loaded? |
The binary paths that are available when |
What's the output of |
When opening terminal:
Then I run
Status After:
|
I have the exact same issue. # .envrc
if ! has nix_direnv_version || ! nix_direnv_version 2.3.0; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc" "sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8="
fi
use nix When the
However, as soon as I enable the Note that everything works correctly from a custom task defined in |
Same as @s0kil my
|
It's so strange that direnv status is the same, however the programs I run cannot see certain paths unless I do, |
Another thing, when I open a regular terminal, and go to the project directory: It's visible that the direnv is being loaded:
However, when I open a VS Code Terminal in the project directory, There is no output:
|
FWIW, that the My best guess at this point is that your shell setup undoes what your .envrc does, so let's check that:
|
Yes, Here are the outputs: Before (new integrated terminal):/home/danielsokil/.fly/bin:/home/danielsokil/.wasmtime/bin:/home/danielsokil/.local/share/pnpm:/home/danielsokil/.opam/4.14.0/bin:/home/danielsokil/.nix-profile/bin:/home/danielsokil/.local/share/pnpm:/home/danielsokil/.cabal/bin:/home/danielsokil/.ghcup/bin:/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/bin:/home/danielsokil/.fly/bin:/home/danielsokil/.wasmtime/bin:/home/danielsokil/.local/share/pnpm:/home/danielsokil/.opam/4.14.0/bin:/home/danielsokil/.nix-profile/bin:/home/danielsokil/.cargo/bin:/home/danielsokil/.local/share/pnpm:/home/danielsokil/.asdf/shims:/home/danielsokil/.asdf/bin:/home/danielsokil/.cabal/bin:/home/danielsokil/.ghcup/bin:/home/danielsokil/.nix-profile/bin:/home/danielsokil/.local/bin:/home/danielsokil/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/danielsokil/snap/flutter/common/flutter/.pub-cache/bin:/home/danielsokil/Downloads/platform-tools_r33.0.1-linux/platform-tools:/home/danielsokil/Downloads/commandlinetools-linux-8092744_latest/cmdline-tools/bin:/home/danielsokil/Android/Sdk/tools:/home/danielsokil/Android/Sdk/platform-tools:/usr/local/go/bin:/home/danielsokil/go/bin:/home/danielsokil/Lab/odin-lang/Odin:/home/danielsokil/.nimble/bin:/home/danielsokil/.local/share/coursier/bin:/home/danielsokil/.local/share/JetBrains/Toolbox/scripts:/opt/mssql-tools18/bin:/home/danielsokil/snap/flutter/common/flutter/.pub-cache/bin:/home/danielsokil/Downloads/platform-tools_r33.0.1-linux/platform-tools:/home/danielsokil/Downloads/commandlinetools-linux-8092744_latest/cmdline-tools/bin:/home/danielsokil/Android/Sdk/tools:/home/danielsokil/Android/Sdk/platform-tools:/usr/local/go/bin:/home/danielsokil/go/bin:/home/danielsokil/Lab/odin-lang/Odin:/home/danielsokil/.nimble/bin:/home/danielsokil/.local/share/coursier/bin:/home/danielsokil/.local/share/JetBrains/Toolbox/scripts:/opt/mssql-tools18/bin {
"p": {
"PATH": "/home/danielsokil/.fly/bin:/home/danielsokil/.wasmtime/bin:/home/danielsokil/.local/share/pnpm:/home/danielsokil/.opam/4.14.0/bin:/home/danielsokil/.nix-profile/bin:/home/danielsokil/.cargo/bin:/home/danielsokil/.local/share/pnpm:/home/danielsokil/.asdf/shims:/home/danielsokil/.asdf/bin:/home/danielsokil/.cabal/bin:/home/danielsokil/.ghcup/bin:/home/danielsokil/.nix-profile/bin:/home/danielsokil/.local/bin:/home/danielsokil/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/danielsokil/snap/flutter/common/flutter/.pub-cache/bin:/home/danielsokil/Downloads/platform-tools_r33.0.1-linux/platform-tools:/home/danielsokil/Downloads/commandlinetools-linux-8092744_latest/cmdline-tools/bin:/home/danielsokil/Android/Sdk/tools:/home/danielsokil/Android/Sdk/platform-tools:/usr/local/go/bin:/home/danielsokil/go/bin:/home/danielsokil/Lab/odin-lang/Odin:/home/danielsokil/.nimble/bin:/home/danielsokil/.local/share/coursier/bin:/home/danielsokil/.local/share/JetBrains/Toolbox/scripts:/opt/mssql-tools18/bin",
"XDG_CONFIG_DIRS": "/etc/xdg/xdg-pop:/etc/xdg",
"XDG_DATA_DIRS": "/usr/share/pop:/usr/share/gnome:/home/danielsokil/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop"
},
"n": {
"C_INCLUDE_PATH": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/include:",
"DEVENV_DOTFILE": "/home/danielsokil/Lab/Zetta-Pow/command/.devenv",
"DEVENV_PROFILE": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile",
"DEVENV_ROOT": "/home/danielsokil/Lab/Zetta-Pow/command",
"DEVENV_STATE": "/home/danielsokil/Lab/Zetta-Pow/command/.devenv/state",
"DIRENV_ACTIVE": "/home/danielsokil/Lab/Zetta-Pow/command:",
"DIRENV_DIR": "-/home/danielsokil/Lab/Zetta-Pow/command",
"DIRENV_FILE": "/home/danielsokil/Lab/Zetta-Pow/command/.envrc",
"DIRENV_WATCHES": "eJyskU1O7DAQBu_i9bzYmTg_zhnegjWIRafdJlbaNopNZiTE3VkghIBR0AguUF3V392zeIQyi1HIOQWSFqInzmnxLP_DJG-pFPh3k04SUwgQrawobiuKgwjJFh9IjHVnlG76oRkOgs4-lyzGsj7Ry2EHXnFCYJlnWElav1LcJDCnk6xJH0GhQphc3w4T1IBkajfBBOD0UVnXW2VahCNSrY1pbNfoVvWEfTe4S2qt0deovel8jlQfAAecfyBgis4_vHf9mnd5CcewUBX9-XtxO3TXjLHH54TL1wONMfoPDlja8kzMVUmBd59z_xoAAP__p6bmgw==",
"IHP": "/nix/store/bi05sv3ms22j5v3cla85bvam8xfcrsxf-source/lib/IHP",
"IHP_LIB": "IHP/lib/IHP",
"IN_NIX_SHELL": "impure",
"LD_LIBRARY_PATH": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/lib:",
"LIBRARY_PATH": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/lib:",
"LOCALE_ARCHIVE": "/nix/store/7n67sxgrwchfjpwjady8rlmp350jzi3n-glibc-locales-2.37-8/lib/locale/locale-archive",
"PATH": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/bin:/home/danielsokil/.fly/bin:/home/danielsokil/.wasmtime/bin:/home/danielsokil/.local/share/pnpm:/home/danielsokil/.opam/4.14.0/bin:/home/danielsokil/.nix-profile/bin:/home/danielsokil/.cargo/bin:/home/danielsokil/.local/share/pnpm:/home/danielsokil/.asdf/shims:/home/danielsokil/.asdf/bin:/home/danielsokil/.cabal/bin:/home/danielsokil/.ghcup/bin:/home/danielsokil/.nix-profile/bin:/home/danielsokil/.local/bin:/home/danielsokil/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/danielsokil/snap/flutter/common/flutter/.pub-cache/bin:/home/danielsokil/Downloads/platform-tools_r33.0.1-linux/platform-tools:/home/danielsokil/Downloads/commandlinetools-linux-8092744_latest/cmdline-tools/bin:/home/danielsokil/Android/Sdk/tools:/home/danielsokil/Android/Sdk/platform-tools:/usr/local/go/bin:/home/danielsokil/go/bin:/home/danielsokil/Lab/odin-lang/Odin:/home/danielsokil/.nimble/bin:/home/danielsokil/.local/share/coursier/bin:/home/danielsokil/.local/share/JetBrains/Toolbox/scripts:/opt/mssql-tools18/bin",
"PKG_CONFIG_PATH": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/lib/pkgconfig:",
"XDG_CONFIG_DIRS": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/etc/xdg:/etc/xdg/xdg-pop:/etc/xdg",
"XDG_DATA_DIRS": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/share:/usr/share/pop:/usr/share/gnome:/home/danielsokil/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop",
"name": "devenv-shell-env"
}
} After (direnv reload):/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/bin:/home/danielsokil/.fly/bin:/home/danielsokil/.wasmtime/bin:/home/danielsokil/.local/share/pnpm:/home/danielsokil/.opam/4.14.0/bin:/home/danielsokil/.nix-profile/bin:/home/danielsokil/.cargo/bin:/home/danielsokil/.local/share/pnpm:/home/danielsokil/.asdf/shims:/home/danielsokil/.asdf/bin:/home/danielsokil/.cabal/bin:/home/danielsokil/.ghcup/bin:/home/danielsokil/.nix-profile/bin:/home/danielsokil/.local/bin:/home/danielsokil/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/danielsokil/snap/flutter/common/flutter/.pub-cache/bin:/home/danielsokil/Downloads/platform-tools_r33.0.1-linux/platform-tools:/home/danielsokil/Downloads/commandlinetools-linux-8092744_latest/cmdline-tools/bin:/home/danielsokil/Android/Sdk/tools:/home/danielsokil/Android/Sdk/platform-tools:/usr/local/go/bin:/home/danielsokil/go/bin:/home/danielsokil/Lab/odin-lang/Odin:/home/danielsokil/.nimble/bin:/home/danielsokil/.local/share/coursier/bin:/home/danielsokil/.local/share/JetBrains/Toolbox/scripts:/opt/mssql-tools18/bin {
"p": {
"PATH": "/home/danielsokil/.fly/bin:/home/danielsokil/.wasmtime/bin:/home/danielsokil/.local/share/pnpm:/home/danielsokil/.opam/4.14.0/bin:/home/danielsokil/.nix-profile/bin:/home/danielsokil/.cargo/bin:/home/danielsokil/.local/share/pnpm:/home/danielsokil/.asdf/shims:/home/danielsokil/.asdf/bin:/home/danielsokil/.cabal/bin:/home/danielsokil/.ghcup/bin:/home/danielsokil/.nix-profile/bin:/home/danielsokil/.local/bin:/home/danielsokil/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/danielsokil/snap/flutter/common/flutter/.pub-cache/bin:/home/danielsokil/Downloads/platform-tools_r33.0.1-linux/platform-tools:/home/danielsokil/Downloads/commandlinetools-linux-8092744_latest/cmdline-tools/bin:/home/danielsokil/Android/Sdk/tools:/home/danielsokil/Android/Sdk/platform-tools:/usr/local/go/bin:/home/danielsokil/go/bin:/home/danielsokil/Lab/odin-lang/Odin:/home/danielsokil/.nimble/bin:/home/danielsokil/.local/share/coursier/bin:/home/danielsokil/.local/share/JetBrains/Toolbox/scripts:/opt/mssql-tools18/bin",
"XDG_CONFIG_DIRS": "/etc/xdg/xdg-pop:/etc/xdg",
"XDG_DATA_DIRS": "/usr/share/pop:/usr/share/gnome:/home/danielsokil/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop"
},
"n": {
"C_INCLUDE_PATH": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/include:",
"DEVENV_DOTFILE": "/home/danielsokil/Lab/Zetta-Pow/command/.devenv",
"DEVENV_PROFILE": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile",
"DEVENV_ROOT": "/home/danielsokil/Lab/Zetta-Pow/command",
"DEVENV_STATE": "/home/danielsokil/Lab/Zetta-Pow/command/.devenv/state",
"DIRENV_ACTIVE": "/home/danielsokil/Lab/Zetta-Pow/command:",
"DIRENV_DIR": "-/home/danielsokil/Lab/Zetta-Pow/command",
"DIRENV_FILE": "/home/danielsokil/Lab/Zetta-Pow/command/.envrc",
"DIRENV_WATCHES": "eJyskU1O7DAQBu_i9bzYmTg_zhnegjWIRafdJlbaNopNZiTE3VkghIBR0AguUF9V992zeIQyi1HIOQWSFqInzmnxLP_DJG-pFPh3k04SUwgQrawobiuKgwjJFh9IjHVnlG56Y8xB0NnnksVY1id6OezAK04ILPMMK0nrV4qbBOZ0kjXpIyhUCJPr22GCGpBM7SaYAJw-Kut6q0yLcESqtTGN7Rrdqp6w7wZ3Sa01-hq1N53PkeoD4IDzDwRM0fmH965f8y5_wjEsVEV__l7cDt1wRfEenxMuXwcaY_QfDFja8kzMVUmBd49z_xoAAP__uobmiw==",
"IHP": "/nix/store/bi05sv3ms22j5v3cla85bvam8xfcrsxf-source/lib/IHP",
"IHP_LIB": "IHP/lib/IHP",
"IN_NIX_SHELL": "impure",
"LD_LIBRARY_PATH": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/lib:",
"LIBRARY_PATH": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/lib:",
"LOCALE_ARCHIVE": "/nix/store/7n67sxgrwchfjpwjady8rlmp350jzi3n-glibc-locales-2.37-8/lib/locale/locale-archive",
"PATH": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/bin:/home/danielsokil/.fly/bin:/home/danielsokil/.wasmtime/bin:/home/danielsokil/.local/share/pnpm:/home/danielsokil/.opam/4.14.0/bin:/home/danielsokil/.nix-profile/bin:/home/danielsokil/.cargo/bin:/home/danielsokil/.local/share/pnpm:/home/danielsokil/.asdf/shims:/home/danielsokil/.asdf/bin:/home/danielsokil/.cabal/bin:/home/danielsokil/.ghcup/bin:/home/danielsokil/.nix-profile/bin:/home/danielsokil/.local/bin:/home/danielsokil/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/danielsokil/snap/flutter/common/flutter/.pub-cache/bin:/home/danielsokil/Downloads/platform-tools_r33.0.1-linux/platform-tools:/home/danielsokil/Downloads/commandlinetools-linux-8092744_latest/cmdline-tools/bin:/home/danielsokil/Android/Sdk/tools:/home/danielsokil/Android/Sdk/platform-tools:/usr/local/go/bin:/home/danielsokil/go/bin:/home/danielsokil/Lab/odin-lang/Odin:/home/danielsokil/.nimble/bin:/home/danielsokil/.local/share/coursier/bin:/home/danielsokil/.local/share/JetBrains/Toolbox/scripts:/opt/mssql-tools18/bin",
"PKG_CONFIG_PATH": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/lib/pkgconfig:",
"XDG_CONFIG_DIRS": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/etc/xdg:/etc/xdg/xdg-pop:/etc/xdg",
"XDG_DATA_DIRS": "/nix/store/cdp99l37xzciik0ljr89wn4b4ya26pn5-devenv-profile/share:/usr/share/pop:/usr/share/gnome:/home/danielsokil/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop",
"name": "devenv-shell-env"
}
} |
Yes, When I source |
So, it seems the solution is as simple as adding
To the |
Same as @s0kil, my PATH order changes before and after |
I use I've solved this by using asdf-direnv:
In my Lastly, I've created the following
This way, I use Hope this helps. |
Facing the same issue here, where new integrated terminal doesn't have the env loaded. |
I'm facing the same issue starting a few months ago. It used to work just fine: the environment was correctly loaded in the IDE and in the integrated terminal. But since a few months ago, I constantly need to reload in the integrated terminal. I definitely can see it not working in the integrated terminal, because it doesn't pick up the correct version of the binary that is loaded inside my Looks like there was some optimization put in place so that the environment doesn't load again in the terminal and attempts to reuse the one that's already loaded by the IDE extension. But seems like it doesn't work correctly. Before that, whenever I open integrated terminal I always used to see the activation message (which I understand wouldn't appear after the optimization was put in place). I uninstalled the extension, and things started working as expected in the integrated terminal, but of course nothing is loading inside the IDE. After installing the extension again things went back being bad: the environment doesn't load in the integrated terminal until I explicitly reload. |
OK, looks like the problem is a bit more complex. Turns out that if I just export some variable in my The problem is that I'm not just exporting some static variables. I used to do Now, I'm switching from Nix to Pixi, and even though it doesn't have a built in support for Direnv, I basically do Actually, it looks like most variables do appear, except the one for PATH. |
Just checked again. Indeed, it seems like only the PATH variable is getting mangled somehow after direnv activation. But most other things evaluated in |
Testing even further. I'm now just doing I could assume that it might be VS Code doing its environment resolution thing. But I wonder why it used to work just fine (although I was seeing the direnv loading the environment each time I open the terminal, which I now don't). |
To clarify, none of my VS Code settings touch the PATH variables. |
@burdiyan did you read the earlier comments on this? What's happening is this:
Setting up the environment inside VSCode is not an optimization, it is necessary to make sure VSCode Tasks can even get the direnv environment, and it has been working like this since the first version. The easiest workaround is having your shell run I'm still thinking about what I can do from the extension side to make that workaround not necessary. |
I've read the conversation but it's quite hard to follow, and I haven't realized that the problem is what you now explain (which now makes sense). I wonder why this wasn't a problem before (a few months ago)? Something had to change I presume, either inside direnv, VS Code, or the extension? |
I added this snippet to my shell profile to mitigate the problem (in case it helps anyone else), but I hope it could be fixed on some other level so this trick isn't necessary. # This is a workaround to make direnv work with VS Code's integrated terminal
# when using the direnv extension, by making sure to reload
# the environment the first time terminal is opened.
#
# See https://github.com/direnv/direnv-vscode/issues/561#issuecomment-1837462994.
#
# The variable VSCODE_INJECTION is apparently set by VS Code itself, and this is how
# we can detect if we're running inside the VS Code terminal or not.
if [[ -n "$VSCODE_INJECTION" && -z "$VSCODE_TERMINAL_DIRENV_LOADED" && -f .envrc ]]; then
direnv reload
export VSCODE_TERMINAL_DIRENV_LOADED=1
fi I'm using this with |
using @burdiyan workaround caused the direnv extension to continually reload. This is my version that seems to work better. # This is a workaround to make direnv work with VS Code's integrated terminal
# when using the direnv extension, by making sure to reload
# the environment the first time terminal is opened.
#
# See https://github.com/direnv/direnv-vscode/issues/561#issuecomment-1837462994.
#
# The variable VSCODE_INJECTION is apparently set by VS Code itself, and this is how
# we can detect if we're running inside the VS Code terminal or not.
if [[ -n "$VSCODE_INJECTION" && -z "$VSCODE_TERMINAL_DIRENV_LOADED" && -f .envrc ]]; then
cd ..
cd -
export VSCODE_TERMINAL_DIRENV_LOADED=1
fi |
Translated @Maatteogekko's solution to # This is a workaround to make direnv work with VS Code's integrated terminal
# when using the direnv extension, by making sure to reload
# the environment the first time terminal is opened.
#
# See <https://github.com/direnv/direnv-vscode/issues/561#issuecomment-2310756248>.
#
# The variable VSCODE_INJECTION is apparently set by VS Code itself, and this is how
# we can detect if we're running inside the VS Code terminal or not.
if test -n "$VSCODE_INJECTION"
and test -z "$VSCODE_TERMINAL_DIRENV_LOADED"
and test -f .envrc
# fish only emits `fish_prompt` in interactive mode,
# so emit it explicitly to trigger direnv to reload.
cd ..
emit fish_prompt
cd -
emit fish_prompt
# I'm not sure if this is actually helpful?
# new terminals created by vscode don't inheret env variables,
# so all new terminals will still re-execute this
export VSCODE_TERMINAL_DIRENV_LOADED=1
end |
@mkhl Would it make sense to add an configuration to this extension that triggers a reload every time a terminal is opened? If you are using direnv to create a consistent dev environment for a team it can be hard to anticipate how every dev configures their shell init scripts. If a |
@purkhusid I think that it shouldn't even require configuration and that consistency is the reason to use direnv. I even have an idea how to do this, but it's fairly invasive, and it doesn't help that the tests are currently broken and other things are requiring my attention :( |
Would you please describe the solution you have in mind? I would be happy to help with the implementation. |
In my
.bashrc
I hook in direnv as:When I open a new integrated terminal window in VS Code, the env is loaded:
However, when I enable the
direnv-vscode
extension, the env is no longer loaded when opening a new terminal window.The text was updated successfully, but these errors were encountered: