Skip to content

The extension cannot find the go executable in PATH when used with flatpak #263

Closed

Description

@micheartin

Go extension version: 0.14.4

> go version
go version go1.14.3 linux/amd64

> flatpak run com.vscodium.codium -v
1.46.1
cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
x64

> flatpak run com.visualstudio.code-oss -v
flatpak-vscode-oss: Setting up Node.js packages
flatpak-vscode-oss: Setting up Cargo packages
flatpak-vscode-oss: Setting up Python packages
1.46.1
cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
x64

> flatpak run com.visualstudio.code -v
1.46.1
cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
x64

> go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/o/.cache/go-build"
GOENV="/home/o/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/o/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.14"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.14/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build809671429=/tmp/go-build -gno-record-gcc-switches"

Describe the bug

Fresh installation of Go, VSCodium (flatpak) and the Go extension (on Ubuntu 20.04).
Nothing configured, no environment variable such as GOPATH.
Bug = the Go extension cannot find the go executable (PATH contains /usr/bin having the go executable).
I have reproduced this same issue with official VisualCode and Code - OSS too.

Steps to reproduce the behavior:

  1. Install Go: sudo apt install golang-go (on Ubuntu 20.04)
  2. Check go location: which go, result is /usr/bin/go
  3. Check go version: go version, result is go version go1.14.3 linux/amd64
  4. Install VSCodium: flatpak install com.vscodium.codium
  5. Run VSCodium: flatpak run com.vscodium.codium (version 1.46.6)
  6. Install extension: FIle > Preferences > Extensions > Select Go 0.14.4 "Rich Go language support for Visual Studio Code"
  7. File > Open folder... > select a folder containing Go files
  8. A notification on the bottom right corner, says:

    Failed to run "go env" to find GOPATH as the "go" binary cannot be found in either GOROOT(undefined) or PATH(/app/bin:/usr/bin:/home/o/.var/app/com.vscodium.codium/data/node_modules/bin)

Expected behavior
Go extension should see the go executable located at /usr/bin
(error message says environment variable PATH contains /usr/bin).

I have tested these three flatpak apps facing the same issue:

  • flatpak run com.vscodium.codium
  • flatpak run com.visualstudio.code-oss
  • flatpak run com.visualstudio.code

Activity

  1. hyangah commented on Jun 27, 2020

    @hyangah
    Contributor

    The relevant code path used to look for the go binary is:

    https://github.com/golang/vscode-go/blob/latest/src/goPath.ts#L69 : check process.env['PATH']

    https://github.com/golang/vscode-go/blob/latest/src/goPath.ts#L19-L31 : for each path component in the process.env['PATH'], check if there is a usable go binary

    https://github.com/golang/vscode-go/blob/latest/src/goPath.ts#L96-L106 : code that checks if the 'go' binary exists and accessible.

    Is there any condition that would cause this code for the go executable search to fail on your system? (e.g. permission, file mode, or incorrectly splitting the path env var, ...)

    As a workaround, can you try "go.alternateTools": { "go": "/usr/bin/go" } in your case? (and if it still fails, executableFileExists will be the problematic code).

  2. micheartin commented on Jun 27, 2020

    @micheartin
    Author

    Hi @hyangah

    Thanks for the advice, but I have still the same error message.

    What I did :

    1. File > Preferences > Extensions > Go (0.14.4)
    2. Click on the Wheel symbol "Manage" > Extension Settings
    3. Go: Alternate Tools > Edit in settings.json
      {
          "window.zoomLevel": 2,
          "go.alternateTools": {
              "go": "/usr/bin/go"
          }
      }
    4. Restart

    I wonder if Flatpak has isolated the app in order to allow access to only very few paths / executables...

    > ls  -l /usr/bin/go
    lrwxrwxrwx 1 root root 21 Feb 25 23:15 /usr/bin/go -> ../lib/go-1.14/bin/go
    
    > ls  -l /usr/lib/go-1.14/bin/go
    -rwxr-xr-x 1 root root 11327352 Jun  4 01:58 /usr/lib/go-1.14/bin/go
    
    > file /usr/lib/go-1.14/bin/go
    /usr/lib/go-1.14/bin/go: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, Go BuildID=oazcoCAUKRuWOpy-PpWt/LNVdmeMHLDTCd7Cek0Am/V4k5_xftXHDTNXriqIl3/w41DZL20ICXy59NePDVJ, stripped
    

    I have also tried the following settings.json content, but no success:

    {
        "window.zoomLevel": 2,
        "go.alternateTools": {
            "go": "/usr/lib/go-1.14/bin/go"
        }
    }
    
  3. micheartin commented on Jun 27, 2020

    @micheartin
    Author

    I have just installed Flatseal https://askubuntu.com/q/1086529#1247345
    and I can see that "VSCodium", "Code - OSS" and "Visual Studio Code" have all three access to all system files (filesytem=host) but no access to user files (filesytem=home).

    I am still investigating on that direction...

  4. hyangah commented on Jun 29, 2020

    @hyangah
    Contributor

    @micheartin thanks for the update. Failure even with "go.alternateTools" setting is clearly a sign that the binary is not accessible from the extension. In addition to the go command, this extension requires to run other tools (gopls, dlv, and a few others), so the permission issue should be sorted out first.

  5. changed the title [-]The Go extension cannot find the `go` executable but PATH contains `/usr/bin` having the `go` executable[/-] [+]The extension cannot find the `go` executable in PATH when used with flatpack[/+] on Jun 29, 2020
  6. added
    WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.
    on Jun 30, 2020
  7. changed the title [-]The extension cannot find the `go` executable in PATH when used with flatpack[/-] [+]The extension cannot find the `go` executable in PATH when used with flatpak[/+] on Jul 2, 2020
  8. hyangah commented on Jul 21, 2020

    @hyangah
    Contributor

    @micheartin I don't see any immediately actionable tasks for this extension to help this specific case. I will close this issue now. If you have feature requests or suggestions for improvement, feel free to reopen or file a new issue. Thanks!

  9. micheartin commented on Jul 21, 2020

    @micheartin
    Author

    All right. I plan to perform similar tests on Fedora Workstation and also some tests using Toolbox
    (see https://docs.fedoraproject.org/en-US/fedora-silverblue/toolbox/ and https://github.com/containers/toolbox)
    If I found a solution I will post it here.
    However I am currently working on other tasks and will check this issue later...

  10. micheartin commented on Sep 5, 2020

    @micheartin
    Author

    The Flatpak documentations https://docs.flatpak.org/en/latest/sandbox-permissions.html#filesystem-access says:

    It is common for applications to require access to different parts of the host filesystem, and Flatpak provides a flexible set of options for this. Some examples include:

    • --filesystem=host - access normal files on the host, not including host os or system internals described below
    • --filesystem=home - access the user’s home directory

    [...]

    As mentioned above the host option does not actually provide complete access to the host filesystem. The main rules are:

    • These directories are blacklisted: /lib, /lib32, /lib64, /bin, /sbin, /usr, /boot, /root, /tmp, /etc, /app, /run, /proc, /sys, /dev, /var
    • [...]

    My understanding: the confined IDE has never access to go dependencies (libraries) in /lib and /lib64, even when providing options --filesystem=/lib --filesystem=/lib64 (or using Flatseal).

    Alternatives to use the Go extension (vscode-go) on a GNU/Linux distribution:

    1. Install Go environment within the /home/$USER location. See https://dev.to/satimewallin/go--mess-with-flatpakvscode-ja6
    2. Do not use Flatpak, but Snap using --classic (unboxed) installtion. Attention: your IDE will have full access to your filesystem.
      • VS Codium: replace flatpak install com.vscodium.codium by sudo snap install codium --classic
      • VS Code: replace flatpak run com.visualstudio.code by sudo snap install code --classic
  11. locked and limited conversation to collaborators on Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions