Skip to content

Conversation

icholy
Copy link

@icholy icholy commented Oct 4, 2025

Running commands with su discards the Env being set on the exec.Cmd. This results in no PATH being available so all commands must be fully qualified. The vscode devcontainers use docker's -u flag which doesn't have the same issue.

I ran into this incompatibility while trying to start a .devcontainer.json file generated by https://devenv.sh/

devenv init
vim devenv.nix # add devcontainer.enable = true
devenv shell # Ctrl-D to exit
devpod up . --debug

Generated .devcontainer.json:

{
  "customizations": {
    "vscode": {
      "extensions": [
        "mkhl.direnv"
      ]
    }
  },
  "image": "ghcr.io/cachix/devenv/devcontainer:latest",
  "overrideCommand": false,
  "updateContentCommand": "devenv test"
}

Error:

12:39:20 warn bash: line 1: devenv: command not found
12:39:20 debug Failed running postCreateCommand lifecycle script [su vscode -c devenv test]: exit status 127

Note:

The su command has a -p flag to preserve the environment. However, this flag omits the PATH, HOME, SHELL, and USER environment variables. So we'd need to use the export command for these either way.

@icholy icholy marked this pull request as ready for review October 4, 2025 16:40
@icholy icholy changed the title fix: use login shell to execute lifecycle hooks fix: use su with explicit exports for lifecycle hooks Oct 8, 2025
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.

1 participant