microsoft / vscode-dev-containers

NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own!
https://aka.ms/vscode-remote
MIT License
4.71k stars 1.4k forks source link

Haskell dev-container isn't properly configured to work well with stack #1250

Open nartamonov opened 2 years ago

nartamonov commented 2 years ago

I'm trying to use Haskell dev-container with my stack-based toy project. Haskell dev-container is based on docker image haskell. As it turned out that image is not adapted to work under a user other than root. For example, they configure stack to use global system-wide GHC installation over self-managed local installation:

...
        stack config set system-ghc --global true; \
        stack config set install-ghc --global false; \
...

Unfortunately, those settings stored under /root/.stack/config.yml and since dev-container currently configured to work under user vscode, when I use stack it tries to download and install GHC locally event though I already had one:

vscode ➜ /workspaces/haskell (ops ✗) $ id
uid=1000(vscode) gid=1000(vscode) groups=1000(vscode)
vscode ➜ /workspaces/haskell (ops ✗) $ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.7
vscode ➜ /workspaces/haskell (ops ✗) $ which ghc
/opt/ghc/8.10.7/bin/ghc
vscode ➜ /workspaces/haskell (ops ✗) $ stack build
Specified file "ChangeLog.md" for extra-source-files does not exist
Preparing to install GHC (tinfo6) to an isolated location.
This will not interfere with any system-level installation.
ghc-tinfo6-8.10.7:   21.14 MiB / 207.64 MiB ( 10.18%) downloaded...^C

If I logs in as root it works as expected:

vscode ➜ /workspaces/haskell (ops ✗) $ sudo su
root ➜ /workspaces/haskell (ops ✗) $ stack build
You are not the owner of '/workspaces/haskell/.stack-work/'. Aborting to protect file permissions.
Retry with '--allow-different-user' to disable this precaution.
root ➜ /workspaces/haskell (ops ✗) $ stack build --allow-different-user
Specified file "ChangeLog.md" for extra-source-files does not exist
No information from Hackage index, updating
Selected mirror https://hackage.haskell.org/
Downloading root
Waiting to acquire cache lock on /root/.stack/pantry/hackage/hackage-security-lock
Acquired cache lock on /root/.stack/pantry/hackage/hackage-security-lock
Released cache lock on /root/.stack/pantry/hackage/hackage-security-lock
Selected mirror https://hackage.haskell.org/
Downloading timestamp
Downloading snapshot
Downloading mirrors
Cannot update index (no local copy)
Downloading index
^C

I assume there are two possible solutions to the problem:

  1. Change remoteUser to root in devcontainer.json. Dont know what consequences it will have.
  2. Parameterise the base image of the dev-container by user argument so that we could build dev-container for specific user, vscode in our case.
Chuxel commented 2 years ago

Adding in @stuartpike who owns the community definition.

stuartpike commented 2 years ago

Behaviour received at 'stack build' 'Preparing to install GHC (tinfo6) to an isolated location' is the default behaviour I've experienced. The download only takes place once for the account used when creating/building multiple projects. After the download has taken place you can build without needing to login as root.

Testing: On native clean Linux install using 'curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh' directly from haskell.

The issue raised looks not to be with the container or a native installation, but with how haskell installs. So I'd suggest contacting haskell community for assistance.