devcontainers / devcontainers/spec

`${env:...}` in `customizations:vscode:settings` are interpolated from local env instead of remote env

Open
#485 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
No language data
Stars
5.7k
Forks
496
PR merge metrics
No merged PRs in 30d

Description

I’m setting up a `devcontainers.json` that works with our container images containing a cross-compiling SDK. In the Dockerfile, we already define an `ENV SDK_NATIVE_SYSROOT=/path/to/sdk` pointing to the path where the SDK is installed. We set the `cmake.cmakePath` to make the `ms-vscode.cmake-tools` extension use the CMake executable from our SDK. According to [its documentation](https://github.com/microsoft/vscode-cmake-tools/blob/7f2f5abb73df585eac3d7da6f1ab55cafd107d06/docs/cmake-settings.md?plain=1#L18), `cmake.cmakePath` supports expanding `${env:...}` variables. Thus, I tried to use the following in my `.devcontainer/devcontainer.json`:

```json
{
"image": "[redacted]",
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools-extension-pack"
],
"settings": {
"cmake.cmakePath": "${env:SDK_NATIVE_SYSROOT}/usr/bin/cmake"
}
}
}
}
```

However, when running the above configuration, I get an error that the CMake executable cannot be found at `/usr/bin/cmake`. Thus, the `${env:SDK_NATIVE_SYSROOT}` seems to expand to an empty string. Interestingly, the same setting works when placed in `.vscode/settings.json` instead.

After further investigation, I think the issue is that `${env:...}` in the `customizations:vscode:settings` is evaluated/expanded on the local host before being passed to the remote. Thus, `${env:SDK_NATIVE_SYSROOT}` results in an empty string since it's only defined in the container, not on my local host. From my understanding, this is unintended behaviour as the `customizations:vscode:settings` are primarily to override settings specific to the devcontainer, and environment variables should be taken from the `remoteEnv` instead of `localEnv`.

Is there a way to escape `${env:...}` or anything else that allows the use of `SDK_NATIVE_SYSROOT` from the container?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.